Exemple #1
0
        private static bool ProcessSetOpOverEmptySet(
            RuleProcessingContext context,
            System.Data.Entity.Core.Query.InternalTrees.Node setOpNode,
            out System.Data.Entity.Core.Query.InternalTrees.Node newNode)
        {
            bool flag1 = context.Command.GetExtendedNodeInfo(setOpNode.Child0).MaxRows == RowCount.Zero;
            bool flag2 = context.Command.GetExtendedNodeInfo(setOpNode.Child1).MaxRows == RowCount.Zero;

            if (!flag1 && !flag2)
            {
                newNode = setOpNode;
                return(false);
            }
            SetOp op    = (SetOp)setOpNode.Op;
            int   index = !flag2 && op.OpType == OpType.UnionAll || !flag1 && op.OpType == OpType.Intersect ? 1 : 0;

            newNode = setOpNode.Children[index];
            TransformationRulesContext transformationRulesContext = (TransformationRulesContext)context;

            foreach (KeyValuePair <Var, Var> keyValuePair in (Dictionary <Var, Var>)op.VarMap[index])
            {
                transformationRulesContext.AddVarMapping(keyValuePair.Key, keyValuePair.Value);
            }
            return(true);
        }
Exemple #2
0
 protected override void VisitSetOp(SetOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     foreach (Dictionary <Var, Var> var in op.VarMap)
     {
         foreach (KeyValuePair <Var, Var> keyValuePair in var)
         {
             if (TypeUtils.IsStructuredType(keyValuePair.Key.Type))
             {
                 PropertyRefList propertyRefList = this.GetPropertyRefList(keyValuePair.Key);
                 PropertyRefList propertyRefs;
                 if (op.OpType == OpType.Intersect || op.OpType == OpType.Except)
                 {
                     propertyRefs = PropertyRefList.All;
                     this.AddPropertyRefs(keyValuePair.Key, propertyRefs);
                 }
                 else
                 {
                     propertyRefs = propertyRefList.Clone();
                 }
                 this.AddPropertyRefs(keyValuePair.Value, propertyRefs);
             }
         }
     }
     this.VisitChildren(n);
 }
 /// <summary>
 /// SetOp handling
 /// UnionAllOp handling
 /// IntersectOp handling
 /// ExceptOp handling
 ///
 /// Visitor for a SetOp. Pushes desired properties to the corresponding
 /// Vars of the input
 /// </summary>
 /// <param name="op">the setop</param>
 /// <param name="n"></param>
 protected override void VisitSetOp(SetOp op, Node n)
 {
     foreach (VarMap varMap in op.VarMap)
     {
         foreach (KeyValuePair <Var, Var> kv in varMap)
         {
             if (TypeUtils.IsStructuredType(kv.Key.Type))
             {
                 // Get the set of expected properties for the unionVar, and
                 // push it down to the inputvars
                 // For Intersect and ExceptOps, we need all properties
                 // from the input
                 // We call GetPropertyRefList() always to initialize
                 // the map, even though we may not use it
                 //
                 PropertyRefList myProps = GetPropertyRefList(kv.Key);
                 if (op.OpType == OpType.Intersect || op.OpType == OpType.Except)
                 {
                     myProps = PropertyRefList.All;
                     // We "want" all properties even on the output of the setop
                     AddPropertyRefs(kv.Key, myProps);
                 }
                 else
                 {
                     myProps = myProps.Clone();
                 }
                 AddPropertyRefs(kv.Value, myProps);
             }
         }
     }
     VisitChildren(n);
 }
Exemple #4
0
        /// <summary>
        /// Returns intersection of two sets.
        /// </summary>
        /// <remarks>Intersection contains elements present in both sets.</remarks>
        public static Set Intersection(Set a, Set b)
        {
            a.CheckComparer(b);
            Set result = new Set(a.Comparer);

            SetOp.Inersection(a, b, a.Comparer, new Inserter(result));
            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Returns symmetric difference of two sets.
        /// </summary>
        /// <remarks>
        /// Symmetric difference contains elements present in one of the sets, but not in both
        /// </remarks>
        public static Set SymmetricDifference(Set a, Set b)
        {
            a.CheckComparer(b);
            Set result = new Set(a.Comparer);

            SetOp.SymmetricDifference(a, b, a.Comparer, new Inserter(result));
            return(result);
        }
 // <summary>
 // Does the list of outputs of the given SetOp contain a var
 // from the given VarVec defined by the SetOp's child with the given index
 // </summary>
 private static bool HasVarReferences(SetOp op, VarVec vars, int index)
 {
     foreach (var var in op.VarMap[index].Values)
     {
         if (vars.IsSet(var))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #7
0
 public SetOpNode(RelNode left, SetOp setop, RelNode right)
 {
     _setop    = setop;
     _left     = left;
     _right    = right;
     Heading   = left.Heading;
     _othermap = Heading.CreateMap(right.Heading);
     if (_othermap.Length != Heading.Degree ||
         _othermap.Any(x => x < 0))
     {
         throw Error.Fatal(setop.ToString(), "headings do not match");
     }
 }
Exemple #8
0
            // <summary>
            // The var that needs to be remapped may be produced by a set op,
            // in which case the varmaps need to be updated too.
            // </summary>
            protected override void VisitSetOp(SetOp op, Node n)
            {
                base.VisitSetOp(op, n);

                if (op.Outputs.IsSet(m_oldVar))
                {
                    Var newVar = m_command.CreateSetOpVar(m_oldVar.Type);
                    op.Outputs.Clear(m_oldVar);
                    op.Outputs.Set(newVar);
                    RemapVarMapKey(op.VarMap[0], newVar);
                    RemapVarMapKey(op.VarMap[1], newVar);
                    AddMapping(m_oldVar, newVar);
                }
            }
            protected override void VisitSetOp(SetOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
            {
                base.VisitSetOp(op, n);
                if (!op.Outputs.IsSet(this.m_oldVar))
                {
                    return;
                }
                Var setOpVar = (Var)this.m_command.CreateSetOpVar(this.m_oldVar.Type);

                op.Outputs.Clear(this.m_oldVar);
                op.Outputs.Set(setOpVar);
                this.RemapVarMapKey(op.VarMap[0], setOpVar);
                this.RemapVarMapKey(op.VarMap[1], setOpVar);
                this.AddMapping(this.m_oldVar, setOpVar);
            }
Exemple #10
0
 protected override System.Data.Entity.Core.Query.InternalTrees.Node VisitSetOp(
     SetOp op,
     System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     if (OpType.Intersect == op.OpType || OpType.Except == op.OpType)
     {
         this.AddReference((IEnumerable <Var>)op.Outputs);
     }
     this.PruneVarSet(op.Outputs);
     foreach (VarMap var in op.VarMap)
     {
         this.PruneVarMap(var);
     }
     this.VisitChildren(n);
     return(n);
 }
Exemple #11
0
        public static List <HashSet <char> > GetGroups(SetOp op)
        {
            var inputfile = new List <string>(System.IO.File.ReadAllLines(@"./day06/input.txt"));

            inputfile.Add("");

            List <HashSet <char> > groups = new List <HashSet <char> >();

            HashSet <char> group = null;

            foreach (var line in inputfile)
            {
                if (string.IsNullOrEmpty(line))
                {
                    if (group.Count > 0)
                    {
                        groups.Add(group);
                    }
                    group = null;
                    continue;
                }

                if (group == null)
                {
                    group = new HashSet <char>(line);
                }
                else
                {
                    switch (op)
                    {
                    case SetOp.Union:
                        group.UnionWith(new HashSet <char>(line));
                        break;

                    case SetOp.Intersect:
                        group.IntersectWith(new HashSet <char>(line));
                        break;
                    }
                }
            }

            return(groups);
        }
        public void Should_Build_DtUpdateReq_Correctly()
        {
            var updateSetCommandBuilder = new UpdateSet.Builder(DefaultAdds, DefaultRemoves);

            var q1 = new Quorum(1);
            var q2 = new Quorum(2);
            var q3 = new Quorum(3);

            updateSetCommandBuilder
            .WithBucketType(BucketType)
            .WithBucket(Bucket)
            .WithKey(Key)
            .WithW(q3)
            .WithPW(q1)
            .WithDW(q2)
            .WithReturnBody(true)
            .WithIncludeContext(false)
            .WithContext(Context)
            .WithTimeout(TimeSpan.FromSeconds(20));

            UpdateSet updateSetCommand = updateSetCommandBuilder.Build();

            DtUpdateReq protobuf = (DtUpdateReq)updateSetCommand.ConstructPbRequest();

            Assert.AreEqual(Encoding.UTF8.GetBytes(BucketType), protobuf.type);
            Assert.AreEqual(Encoding.UTF8.GetBytes(Bucket), protobuf.bucket);
            Assert.AreEqual(Encoding.UTF8.GetBytes(Key), protobuf.key);
            Assert.AreEqual(q3, protobuf.w);
            Assert.AreEqual(q1, protobuf.pw);
            Assert.AreEqual(q2, protobuf.dw);
            Assert.IsTrue(protobuf.return_body);
            Assert.IsFalse(protobuf.include_context);
            Assert.AreEqual(20000, protobuf.timeout);

            SetOp setOpMsg = protobuf.op.set_op;

            Assert.AreEqual(DefaultAdds, setOpMsg.adds);
            Assert.AreEqual(DefaultRemoves, setOpMsg.removes);
        }
        /// <summary>
        /// SetOps
        ///
        /// Common handling for all SetOps. We first identify the "output" vars
        /// that are referenced, and mark the corresponding "input" vars as referenced
        /// We then remove all unreferenced output Vars from the "Outputs" varset
        /// as well as from the Varmaps.
        /// Finally, we visit the children
        /// </summary>
        /// <param name="op"></param>
        /// <param name="n">current node</param>
        /// <returns></returns>
        protected override Node VisitSetOp(SetOp op, Node n)
        {
            // Prune the outputs varset, except for Intersect and Except, which require
            // all their outputs to compare, so don't bother pruning them.
            if (OpType.Intersect == op.OpType || OpType.Except == op.OpType)
            {
                AddReference(op.Outputs);
            }

            PruneVarSet(op.Outputs);

            // Prune the varmaps. Identify which of the setOp vars have been
            // referenced, and eliminate those entries that don't show up. Additionally
            // mark all the other Vars as referenced
            foreach (VarMap varMap in op.VarMap)
            {
                PruneVarMap(varMap);
            }

            // Now visit the children
            VisitChildren(n);
            return(n);
        }
        private static MapOp Populate(MapOperation mapOperation)
        {
            var mapOp = new MapOp();

            if (mapOperation.HasRemoves)
            {
                foreach (var removeCounter in mapOperation.RemoveCounters)
                {
                    RiakString counterName = removeCounter.Key;
                    var        field       = new MapField
                    {
                        name = counterName,
                        type = MapField.MapFieldType.COUNTER
                    };

                    mapOp.removes.Add(field);
                }

                foreach (var removeSet in mapOperation.RemoveSets)
                {
                    RiakString setName = removeSet.Key;
                    var        field   = new MapField
                    {
                        name = setName,
                        type = MapField.MapFieldType.SET
                    };

                    mapOp.removes.Add(field);
                }

                foreach (var removeRegister in mapOperation.RemoveRegisters)
                {
                    RiakString registerName = removeRegister.Key;
                    var        field        = new MapField
                    {
                        name = registerName,
                        type = MapField.MapFieldType.REGISTER
                    };

                    mapOp.removes.Add(field);
                }

                foreach (var removeFlag in mapOperation.RemoveFlags)
                {
                    RiakString flagName = removeFlag.Key;
                    var        field    = new MapField
                    {
                        name = flagName,
                        type = MapField.MapFieldType.FLAG
                    };

                    mapOp.removes.Add(field);
                }

                foreach (var removeMap in mapOperation.RemoveMaps)
                {
                    RiakString mapName = removeMap.Key;
                    var        field   = new MapField
                    {
                        name = mapName,
                        type = MapField.MapFieldType.MAP
                    };

                    mapOp.removes.Add(field);
                }
            }

            foreach (var incrementCounter in mapOperation.IncrementCounters)
            {
                RiakString counterName = incrementCounter.Key;
                long       increment   = incrementCounter.Value;

                var field = new MapField
                {
                    name = counterName,
                    type = MapField.MapFieldType.COUNTER
                };

                var counterOp = new CounterOp
                {
                    increment = increment
                };

                var update = new MapUpdate
                {
                    field      = field,
                    counter_op = counterOp
                };

                mapOp.updates.Add(update);
            }

            foreach (var addToSet in mapOperation.AddToSets)
            {
                RiakString         setName = addToSet.Key;
                IList <RiakString> setAdds = addToSet.Value;

                var field = new MapField
                {
                    name = setName,
                    type = MapField.MapFieldType.SET
                };

                var setOp = new SetOp();
                setOp.adds.AddRange(setAdds.Select(v => (byte[])v));

                var update = new MapUpdate
                {
                    field  = field,
                    set_op = setOp
                };

                mapOp.updates.Add(update);
            }

            foreach (var removeFromSet in mapOperation.RemoveFromSets)
            {
                RiakString         setName    = removeFromSet.Key;
                IList <RiakString> setRemoves = removeFromSet.Value;

                var field = new MapField
                {
                    name = setName,
                    type = MapField.MapFieldType.SET
                };

                var setOp = new SetOp();
                setOp.removes.AddRange(setRemoves.Select(v => (byte[])v));

                var update = new MapUpdate
                {
                    field  = field,
                    set_op = setOp
                };

                mapOp.updates.Add(update);
            }

            foreach (var registerToSet in mapOperation.RegistersToSet)
            {
                RiakString registerName  = registerToSet.Key;
                RiakString registerValue = registerToSet.Value;

                var field = new MapField
                {
                    name = registerName,
                    type = MapField.MapFieldType.REGISTER
                };

                var update = new MapUpdate
                {
                    field       = field,
                    register_op = registerValue
                };

                mapOp.updates.Add(update);
            }

            foreach (var flagToSet in mapOperation.FlagsToSet)
            {
                RiakString flagName  = flagToSet.Key;
                bool       flagValue = flagToSet.Value;

                var field = new MapField
                {
                    name = flagName,
                    type = MapField.MapFieldType.FLAG
                };

                var update = new MapUpdate
                {
                    field   = field,
                    flag_op = flagValue ? MapUpdate.FlagOp.ENABLE : MapUpdate.FlagOp.DISABLE
                };

                mapOp.updates.Add(update);
            }

            foreach (var map in mapOperation.Maps)
            {
                RiakString   mapName           = map.Key;
                MapOperation innerMapOperation = map.Value;

                var field = new MapField
                {
                    name = mapName,
                    type = MapField.MapFieldType.MAP
                };

                MapOp innerMapOp = Populate(innerMapOperation);

                var update = new MapUpdate
                {
                    field  = field,
                    map_op = innerMapOp
                };

                mapOp.updates.Add(update);
            }

            return(mapOp);
        }
Exemple #15
0
 protected override void VisitSetOp(SetOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     this.VisitRelOpDefault((RelOp)op, n);
     this.Map(op.VarMap[0]);
     this.Map(op.VarMap[1]);
 }
Exemple #16
0
 // <summary>
 // The number of outputs is same as for any of the inputs
 // </summary>
 protected override int VisitSetOp(SetOp op, Node n)
 {
     return(op.Outputs.Count);
 }
Exemple #17
0
 protected override void VisitSetOp(SetOp op, Node n)
 {
     VisitRelOpDefault(op, n);
     Map(op.VarMap[0]);
     Map(op.VarMap[1]);
 }
 protected override int VisitSetOp(SetOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     return(op.Outputs.Count);
 }