Ejemplo n.º 1
0
        // generate SQL code for dyadic set operations
        DataTableSql DyadicSet(DataTableSql other, DataHeading newheading, JoinOps joinop)
        {
            var sql      = _gen.SelectSet(GetFrom(), other.GetFrom(), newheading, joinop);
            var newtable = DataTableSql.CreateFromSql(newheading, sql);

            return(newtable);
        }
Ejemplo n.º 2
0
        //--- updates

        // Execute an update using a JOIN op
        // Only INSERT and DELETE actually supported
        public override DataTable UpdateJoin(DataTable other, JoinOps joinops)
        {
            switch (joinops)
            {
            case JoinOps.UNION:
                if (other is DataTableSql)
                {
                    InsertValuesQuery(other as DataTableSql);
                }
                else
                {
                    InsertValuesSingly(other);
                }
                return(this);

            case JoinOps.MINUS:
                if (other is DataTableSql)
                {
                    DeleteValuesQuery(other as DataTableSql);
                }
                else
                {
                    DeleteValuesSingly(other);
                }
                return(this);
            }
            throw ProgramError.Fatal("Sql data", "join operation not supported: {0}", joinops);
        }
Ejemplo n.º 3
0
        public string SelectOneWhere(string query1, string query2, JoinOps joinop, bool equal)
        {
            var dict = new Dictionary <string, SubstituteDelegate> {
                { "whereexist", (x) => WhereExist(query1, query2, joinop, true, equal) },
            };

            return(_templater.Process("SelectOneWhere", dict));
        }
Ejemplo n.º 4
0
        // Compare tables: joinop is INTERSECT, MINUS or NUL (for equals)
        bool SetCompare(DataTableSql other, JoinOps joinop, bool both)
        {
            Logger.Assert(Heading.Equals(other.Heading));
            var sql = _gen.SelectOneWhere(GetQuery(), other.GetQuery(), joinop, both);
            var ret = GetBoolValue(sql);

            Release();
            other.Release();
            return(ret);
        }
Ejemplo n.º 5
0
        // Generalised Set via naive cross product
        // Handles all cases, projecting onto common heading, not necessarily optimal
        DataTableLocal GeneralisedSet(DataTableLocal other, DataHeading newheading, JoinOps joinops)
        {
            Logger.WriteLine(4, "GenSet L={0} R={1} new={2} j={3}", this.Heading, other.Heading, newheading, joinops);

            var ldict = new Dictionary <DataRow, int>();
            var rdict = new Dictionary <DataRow, int>();

            switch (joinops)
            {
            case JoinOps.MINUS:
            case JoinOps.INTERSECT:
                BuildIndex(other, newheading, rdict);
                break;

            case JoinOps.SYMDIFF:
                BuildIndex(this, newheading, ldict);
                BuildIndex(other, newheading, rdict);
                break;
            }

            var newtable = DataTableLocal.Create(newheading);

            if (joinops == JoinOps.UNION || rdict.Count > 0)
            {
                var lmovndx = newheading.MakeIndex(Heading);
                foreach (var row in this.GetRows()) //TODO:Enumerable
                {
                    var newrow = row.Project(newheading, lmovndx);
                    var ok     = (joinops == JoinOps.MINUS || joinops == JoinOps.SYMDIFF) ? !rdict.ContainsKey(newrow)
            : (joinops == JoinOps.INTERSECT) ? rdict.ContainsKey(newrow)
            : true;
                    if (ok)
                    {
                        newtable.AddRow(newrow);
                    }
                }
            }
            if (joinops == JoinOps.UNION || ldict.Count > 0)
            {
                var rmovndx = newheading.MakeIndex(other.Heading);
                foreach (var row in other.GetRows()) //TODO:Enumerable
                {
                    var newrow = row.Project(newheading, rmovndx);
                    var ok     = (joinops == JoinOps.SYMDIFF) ? !ldict.ContainsKey(newrow)
            : true;
                    if (ok)
                    {
                        newtable.AddRow(newrow);
                    }
                }
            }
            Logger.WriteLine(4, "[GenSet={0}]", newtable);
            return(newtable);
        }
Ejemplo n.º 6
0
        string WhereExist(string query1, string query2, JoinOps joinop, bool not, bool twice)
        {
            var dict = new Dictionary <string, SubstituteDelegate> {
                { "not", (x) => not ? "NOT" : "" },
                { "query1", (x) => query1 },
                { "query2", (x) => query2 },
                { "setop", (x) => _templater.JoinOp(joinop) },
            };

            return(_templater.Process(twice ? "WhereExistAnd" : "WhereExist", dict));
        }
Ejemplo n.º 7
0
        // Generate Sql to insert query results into this table
        public string InsertJoin(string name, DataHeading heading, string query, JoinOps joinop)
        {
            // ignore joinop for now
            var dict = new Dictionary <string, SubstituteDelegate> {
                { "namelist", (x) => NameList(heading) },
                { "table", (x) => name },
                { "query", (x) => query },
            };

            return(_templater.Process("InsertJoin", dict));
        }
Ejemplo n.º 8
0
    // Create an endpoint in slot [i]
    static void CreateEndpt(int i)
    {
        JoinOps jops = new JoinOps();

        jops.group_name = groupName;
        Member m = new Member(conn);

        m.Join(jops);
        memb_a[i] = m;

        Console.WriteLine("Join");
    }
Ejemplo n.º 9
0
 Symbol AddDyadic(string name, int numargs, int precedence, JoinOps joinop, string method)
 {
     return(Add(name, new Symbol {
         Kind = SymKinds.FUNC,
         CallKind = CallKinds.JFUNC,
         NumArgs = numargs,
         Precedence = precedence,
         JoinOp = joinop,
         DataType = DataTypes.Unknown,
         CallInfo = CallInfo.Get(method),
         Foldable = (joinop.HasFlag(JoinOps.LEFT) == joinop.HasFlag(JoinOps.RIGHT)) ? FoldableFlags.ANY : FoldableFlags.NUL,
     }));
 }
Ejemplo n.º 10
0
    public static void Main(string[] args)
    {
        conn = new Connection();
        conn.Connect();

        JoinOps jops = new JoinOps();

        jops.group_name = "CS_Mtalk";

        // Create the endpoint
        memb = new Member(conn);

        memb.Join(jops);
        MainLoop();
    }
Ejemplo n.º 11
0
        public override DataTable DyadicAntijoin(DataTable otherarg, JoinOps joinops, DataHeading newheading)
        {
            var          other   = Convert(otherarg);
            var          joinhdg = Heading.Intersect(other.Heading);
            DataTableSql newtable;

            if (joinops.HasFlag(JoinOps.REV))
            {
                newtable = (other).DyadicAntijoin(this, joinhdg, newheading);
            }
            else
            {
                newtable = DyadicAntijoin(other, joinhdg, newheading);
            }
            other.Release();
            Logger.WriteLine(4, "[DAJ '{0}']", newtable);
            return(newtable);
        }
Ejemplo n.º 12
0
        // Implement Antijoin by dispatch to preferred algorithm
        public override DataTable DyadicAntijoin(DataTable otherarg, JoinOps joinops, DataHeading newheading)
        {
            var other = Convert(otherarg);

            // pick off the custom implementations
            switch (joinops)
            {
            case JoinOps.ANTIJOIN:
                return(Antijoin(other));

            case JoinOps.RANTIJOIN:
                return(other.Antijoin(this));
            }
            // use generalised fallback
            var joinhdg = Heading.Intersect(other.Heading);

            return((joinops.HasFlag(JoinOps.REV))
        ? other.GeneralisedAntijoin(this, newheading, joinhdg)
        : GeneralisedAntijoin(other, newheading, joinhdg));
        }
Ejemplo n.º 13
0
    /** A simple test case. Invoke with a number of group names.
     * Each member will cast the group name every second.
     */
    public static void Main(string[] args)
    {
        ParseCmdLine(args);
        conn = new Connection();
        conn.Connect();

        JoinOps jops = new JoinOps();

        jops.group_name = "CS_Perf";

        // Create the endpoint
        memb = new Member(conn);

        if (prog == "rpc")
        {
            RpcMainLoop(jops);
        }
        else
        {
            ThrouMainLoop(jops);
        }
    }
Ejemplo n.º 14
0
        public override DataTable DyadicSet(DataTable otherarg, JoinOps joinop, DataHeading newheading)
        {
            var          other = Convert(otherarg);
            DataTableSql newtable;

            if (joinop == JoinOps.RMINUS)
            {
                newtable = other.DyadicSet(this, newheading, JoinOps.MINUS);
            }
            else if (joinop == JoinOps.SYMDIFF)
            {
                var r1 = DyadicSet(other, newheading, JoinOps.MINUS);
                var r2 = other.DyadicSet(this, newheading, JoinOps.MINUS);
                newtable = r1.DyadicSet(r2, newheading, JoinOps.UNION);
            }
            else
            {
                newtable = DyadicSet(other, newheading, joinop);
            }
            other.Release();
            Logger.WriteLine(4, "[DS '{0}']", newtable);
            return(newtable);
        }
Ejemplo n.º 15
0
        // Implement Set operations by dispatch to preferred algorithm
        public override DataTable DyadicSet(DataTable otherarg, JoinOps joinops, DataHeading newheading)
        {
            var other = Convert(otherarg);

            if (Heading.Equals(other.Heading) && Heading.Equals(newheading))
            {
                // pick off the custom implementations
                switch (joinops)
                {
                case JoinOps.UNION:
                    return(Union(other));

                case JoinOps.MINUS:
                    return(Minus(other));

                case JoinOps.RMINUS:
                    return(other.Minus(this));
                }
            }
            // use generalised fallback
            return((joinops == JoinOps.RMINUS)
        ? other.GeneralisedSet(this, newheading, JoinOps.MINUS)
        : GeneralisedSet(other, newheading, joinops));
        }
Ejemplo n.º 16
0
 public abstract DataTable UpdateJoin(DataTable other, JoinOps joinops);
Ejemplo n.º 17
0
        public string SelectSet(string tableorquery1, string tableorquery2, DataHeading newheading, JoinOps joinop)
        {
            var dict = new Dictionary <string, SubstituteDelegate> {
                { "select1", (x) => tableorquery1 },
                { "select2", (x) => tableorquery2 },
                { "namelist", (x) => NameList(newheading) },
                { "setop", (x) => _templater.JoinOp(joinop) },
            };

            return(_templater.Process("SelectSetName", dict));
        }
Ejemplo n.º 18
0
    /**************************************************************/

    /* Throuput test case
     */

    static void ThrouMainLoop(JoinOps jops)
    {
        memb.Join(jops);

        while (true)
        {
            // handle all incoming messages
            while (conn.Poll())
            {
                Message msg = conn.Recv();

                switch (msg.mtype)
                {
                case UpType.VIEW:
                    v = msg.view;
                    Console.Write("  view=[");
                    foreach (string endpt in v.view)
                    {
                        System.Console.Write(":" + endpt);
                    }
                    Console.WriteLine("]");
                    blocked = false;

                    if (nmembers == v.nmembers)
                    {
                        start      = true;
                        start_time = DateTime.Now.Ticks;
                        bulk_data  = new byte[size];
                        Console.WriteLine("Got initial membership");
                    }

                    if (nmembers > v.nmembers &&
                        start)
                    {
                        Console.WriteLine("Members have started to leave, exiting.");
                        System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
                        currentProcess.Kill();
                    }
                    break;

                case UpType.EXIT:
                    Console.WriteLine("RPC exit");
                    break;

                case UpType.CAST:
                    num_recvd_msgs++;
                    total += size;
                    if (num_recvd_msgs % 10 == 0)
                    {
                        Console.WriteLine("#recv_cast: " + num_recvd_msgs);
                    }

                    if (start &&
                        num_recvd_msgs == total_num_msgs &&
                        1 == v.rank)
                    {
                        start = false;
                        long now  = DateTime.Now.Ticks;
                        long diff = (now - start_time) / (10 * 1000 * 1000);
                        Console.WriteLine("finished Throuput test");
                        Console.WriteLine("total=" + total);
                        Console.WriteLine("time=" + diff + "sec");
                        Console.WriteLine("throughput=" + (int)total / (1024 * diff) + "Kbyte/sec");

                        memb.Leave();
                        Thread.Sleep(1000);
                        System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
                        currentProcess.Kill();
                    }
                    break;

                case UpType.SEND:
                    break;

                case UpType.BLOCK:
                    blocked = true;
                    memb.BlockOk();
                    break;
                }
            }

            // multicast the message periodically.
            if (start &&
                !blocked &&
                v.nmembers == nmembers &&
                0 == v.rank &&
                !done)
            {
                Console.WriteLine("Mulitcasting messages\n");
                for (int i = 0; i < total_num_msgs; i++)
                {
                    memb.Cast(bulk_data);
                }
                done = true;
            }
        }
    }
Ejemplo n.º 19
0
 public static MergeOps ToTupleOp(JoinOps joinop)
 {
     return((MergeOps)((int)(joinop & JoinOps.SETOPS) >> 3));
 }
Ejemplo n.º 20
0
    /**************************************************************/

    /* RPC test case
     */
    static void RpcMainLoop(JoinOps jops)
    {
        memb.Join(jops);

        while (true)
        {
            Message msg = conn.Recv();

            switch (msg.mtype)
            {
            case UpType.VIEW:
                v = msg.view;
                Console.Write("  view=[");
                foreach (string endpt in v.view)
                {
                    System.Console.Write(":" + endpt);
                }
                Console.WriteLine("]");
                blocked = false;

                if (2 == v.nmembers)
                {
                    start      = true;
                    start_time = DateTime.Now.Ticks;
                    bulk_data  = new byte[size];
                    Console.WriteLine("Got initial membership");
                }

                if (start &&
                    0 == v.rank)
                {
                    Console.WriteLine("Sending first message");
                    memb.Send1(1, bulk_data);
                }
                break;

            case UpType.EXIT:
                Console.WriteLine("RPC exit");
                break;

            case UpType.CAST:
                break;

            case UpType.SEND:
                num_recvd_msgs++;
                if (num_recvd_msgs % 1000 == 0)
                {
                    Console.WriteLine("#recv_send: " + num_recvd_msgs);
                }

                if (start &&
                    !blocked &&
                    v.nmembers == 2)
                {
                    if (v.rank == 0)
                    {
                        memb.Send1(1, bulk_data);
                    }
                    if (v.rank == 1)
                    {
                        memb.Send1(0, bulk_data);
                    }
                }

                if (start &&
                    num_recvd_msgs >= total_num_msgs)
                {
                    start = false;
                    long now  = DateTime.Now.Ticks;
                    long diff = (now - start_time) / (10 * 1000 * 1000);
                    Console.WriteLine("finished RPC test");
                    Console.WriteLine("total=" + num_recvd_msgs);
                    Console.WriteLine("time=" + diff + "sec");
                    Console.WriteLine("round-trip latency=" + (double)((diff * 1000 * 1000) / num_recvd_msgs) + "(mircosecond)");
                    //	conn.Leave(memb);

                    Thread.Sleep(1000);
                    System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
                    currentProcess.Kill();
                }
                break;

            case UpType.BLOCK:
                blocked = true;
                memb.BlockOk();
                break;
            }
        }
    }
Ejemplo n.º 21
0
 public abstract DataTable DyadicSet(DataTable other, JoinOps joinops, DataHeading newheading);
Ejemplo n.º 22
0
 public virtual string JoinOp(JoinOps joinop)
 {
     Logger.Assert(_joinoptosql.ContainsKey(joinop), joinop);
     return(_joinoptosql[joinop]);
 }
Ejemplo n.º 23
0
 public static MergeOps ToMergeOp(JoinOps joinop)
 {
     return((MergeOps)(joinop & JoinOps.MERGEOPS));
 }
Ejemplo n.º 24
0
        ///=================================================================
        /// Updates -- return original table modified
        ///

        // Update Join
        // Handles Insert and others, but requires common heading
        public override DataTable UpdateJoin(DataTable otherarg, JoinOps joinops)
        {
            Logger.WriteLine(4, "UpJoin {0} j={1}", Heading, joinops);
            var other = Convert(otherarg);

            var left   = joinops.HasFlag(JoinOps.SETL);
            var common = joinops.HasFlag(JoinOps.SETC);
            var right  = joinops.HasFlag(JoinOps.SETR);

            // pass 1 - new rows
            var reladd = DataTableLocal.Create(Heading);

            if (right && left && common)
            {
                reladd = other;
            }
            else if (right)
            {
                foreach (var row in other.GetRows())
                {
                    if (!Contains(row))
                    {
                        reladd.AddRow(row);
                    }
                }
            }

            // pass 2 - deletions
            if (left && common)
            {
            }
            else if (left)
            {
                foreach (var row in GetRows())
                {
                    if (other.Contains(row))
                    {
                        DeleteRow(row);
                    }
                }
            }
            else if (common)
            {
                foreach (var row in GetRows())
                {
                    if (!other.Contains(row))
                    {
                        DeleteRow(row);
                    }
                }
            }
            else
            {
                ClearRows();
            }

            // pass 3 - additions
            foreach (var row in reladd.GetRows())
            {
                AddRow(row);
            }

            // TODO: update persistence store

            Logger.WriteLine(4, "[UpJoin={0}]", this);
            return(this);
        }