예제 #1
0
 internal static Node Copy(Command cmd, Node n, out VarMap varMap)
 {
     var oc = new OpCopier(cmd);
     var newNode = oc.CopyNode(n);
     varMap = oc.m_varMap;
     return newNode;
 }
예제 #2
0
 /// <summary>
 ///     Compute the hash value for this node
 /// </summary>
 internal override void ComputeHashValue(Command cmd, Node n)
 {
     base.ComputeHashValue(cmd, n);
     m_hashValue = (m_hashValue << 4) ^ GetHashValue(Definitions);
     m_hashValue = (m_hashValue << 4) ^ GetHashValue(Keys.KeyVars);
     return;
 }
 /// <summary>
 ///     Private constructor
 /// </summary>
 /// <param name="command"> </param>
 /// <param name="groupAggregateVarInfoManager"> </param>
 private GroupAggregateVarComputationTranslator(
     Command command,
     GroupAggregateVarInfoManager groupAggregateVarInfoManager)
 {
     _command = command;
     _groupAggregateVarInfoManager = groupAggregateVarInfoManager;
 }
예제 #4
0
        internal Table(Command command, TableMD tableMetadata, int tableId)
        {
            m_tableMetadata = tableMetadata;
            m_columns = Command.CreateVarList();
            m_keys = command.CreateVarVec();
            m_nonnullableColumns = command.CreateVarVec();
            m_tableId = tableId;

            var columnVarMap = new Dictionary<string, ColumnVar>();
            foreach (var c in tableMetadata.Columns)
            {
                var v = command.CreateColumnVar(this, c);
                columnVarMap[c.Name] = v;
                if (!c.IsNullable)
                {
                    m_nonnullableColumns.Set(v);
                }
            }

            foreach (var c in tableMetadata.Keys)
            {
                var v = columnVarMap[c.Name];
                m_keys.Set(v);
            }

            m_referencedColumns = command.CreateVarVec(m_columns);
        }
        // <summary>
        // Produces a list of all GroupAggregateVarInfos, each of which represents a single group aggregate
        // and it candidate function aggregates. It also produces a delegate that given a child node returns the parent node
        // </summary>
        internal static IEnumerable<GroupAggregateVarInfo> Process(Command itree, out TryGetValue tryGetParent)
        {
            var groupRefComputingVisitor = new GroupAggregateRefComputingVisitor(itree);
            groupRefComputingVisitor.VisitNode(itree.Root);
            tryGetParent = groupRefComputingVisitor._childToParent.TryGetValue;

            return groupRefComputingVisitor._groupAggregateVarInfoManager.GroupAggregateVarInfos;
        }
 /// <summary>
 /// Equivalent to OpCopier.Copy, only in addition it keeps track of the defining subtrees
 /// of collection vars defined in the subtree rooted at the copy of the input node n.
 /// </summary>
 /// <param name="cmd"></param>
 /// <param name="n"></param>
 /// <param name="varMap"></param>
 /// <param name="newCollectionVarDefinitions"></param>
 /// <returns></returns>
 internal static Node Copy(Command cmd, Node n, out VarMap varMap, out Dictionary<Var, Node> newCollectionVarDefinitions)
 {
     var oc = new OpCopierTrackingCollectionVars(cmd);
     var newNode = oc.CopyNode(n);
     varMap = oc.m_varMap;
     newCollectionVarDefinitions = oc.m_newCollectionVarDefinitions;
     return newNode;
 }
예제 #7
0
        public static bool Process(Command command)
        {
            var processor = new NullSemantics(command);

            command.Root = processor.VisitNode(command.Root);

            return processor._modified;
        }
        /// <summary>
        ///     The driver.
        ///     Walks the tree, and "pushes" down information about required properties
        ///     to every node and Var in the tree.
        /// </summary>
        /// <param name="itree"> The query tree </param>
        /// <param name="varPropertyRefs"> List of desired properties from each Var </param>
        /// <param name="nodePropertyRefs"> List of desired properties from each node </param>
        internal static void Process(
            Command itree, out Dictionary<Var, PropertyRefList> varPropertyRefs, out Dictionary<Node, PropertyRefList> nodePropertyRefs)
        {
            var pph = new PropertyPushdownHelper();
            pph.Process(itree.Root);

            varPropertyRefs = pph.m_varPropertyRefMap;
            nodePropertyRefs = pph.m_nodePropertyRefMap;
        }
예제 #9
0
 internal ExtendedNodeInfo(Command cmd)
     : base(cmd)
 {
     m_localDefinitions = cmd.CreateVarVec();
     m_definitions = cmd.CreateVarVec();
     m_nonNullableDefinitions = cmd.CreateVarVec();
     m_nonNullableVisibleDefinitions = cmd.CreateVarVec();
     m_keys = new KeyVec(cmd);
     m_minRows = RowCount.Zero;
     m_maxRows = RowCount.Unbounded;
 }
예제 #10
0
 // <summary>
 // Make a copy of the current node. Also return an ordered list of the new
 // Vars corresponding to the vars in "varList"
 // </summary>
 // <param name="cmd"> current command </param>
 // <param name="node"> the node to clone </param>
 // <param name="varList"> list of Vars </param>
 // <param name="newVarList"> list of "new" Vars </param>
 // <returns> the cloned node </returns>
 internal static Node Copy(Command cmd, Node node, VarList varList, out VarList newVarList)
 {
     VarMap varMap;
     var newNode = Copy(cmd, node, out varMap);
     newVarList = Command.CreateVarList();
     foreach (var v in varList)
     {
         var newVar = varMap[v];
         newVarList.Add(newVar);
     }
     return newNode;
 }
예제 #11
0
        /// <summary>
        ///     Computes the hash value for this node. The hash value is simply the
        ///     local hash value for this node info added with the hash values of the child
        ///     nodes
        /// </summary>
        /// <param name="cmd"> current command </param>
        /// <param name="n"> current node </param>
        internal virtual void ComputeHashValue(Command cmd, Node n)
        {
            m_hashValue = 0;
            foreach (var chi in n.Children)
            {
                var chiNodeInfo = cmd.GetNodeInfo(chi);
                m_hashValue ^= chiNodeInfo.HashValue;
            }

            m_hashValue = (m_hashValue << 4) ^ ((int)n.Op.OpType); // include the optype somehow
            // Now compute my local hash value
            m_hashValue = (m_hashValue << 4) ^ GetHashValue(m_externalReferences);
        }
예제 #12
0
 internal static void Process(Command command)
 {
     Node topMostSort;
     if (command.Root.Child0 != null
         && command.Root.Child0.Op.OpType == OpType.Sort)
     {
         topMostSort = command.Root.Child0;
     }
     else
     {
         topMostSort = null;
     }
     var sortRemover = new SortRemover(command, topMostSort);
     command.Root = sortRemover.VisitNode(command.Root);
 }
        internal static ProviderCommandInfo Create(
            Command command,
            Node node)
        {
            var projectOp = node.Op as PhysicalProjectOp;
            PlanCompiler.Assert(projectOp != null, "Expected root Op to be a physical Project");

            // build up the CQT
            var ctree = CTreeGenerator.Generate(command, node);
            var cqtree = ctree as DbQueryCommandTree;
            PlanCompiler.Assert(cqtree != null, "null query command tree");

            // Get the rowtype for the result cqt
            var collType = TypeHelpers.GetEdmType<md.CollectionType>(cqtree.Query.ResultType);
            PlanCompiler.Assert(md.TypeSemantics.IsRowType(collType.TypeUsage), "command rowtype is not a record");

            // Build up a mapping from Vars to the corresponding output property/column
            var outputVarMap = BuildOutputVarMap(projectOp, collType.TypeUsage);

            return new ProviderCommandInfo(ctree);
        }
예제 #14
0
        /// <summary>
        ///     Split up a predicate into 2 parts - the pushdown and the non-pushdown predicate.
        ///     If the filter node has no external references *and* the "columns" parameter is null,
        ///     then the entire predicate can be pushed down
        ///     We then compute the set of valid column references - if the "columns" parameter
        ///     is non-null, this set is used. Otherwise, we get the definitions of the
        ///     input relop node of the filterOp, and use that.
        ///     We use this list of valid column references to identify which parts of the filter
        ///     predicate can be pushed down - only those parts of the predicate that do not
        ///     reference anything beyond these columns are considered for pushdown. The rest are
        ///     stuffed into the nonPushdownPredicate output parameter
        /// </summary>
        /// <param name="command"> Command object </param>
        /// <param name="filterNode"> the FilterOp subtree </param>
        /// <param name="columns"> (Optional) List of columns to consider for "pushdown" </param>
        /// <param name="nonPushdownPredicateNode"> (output) Part of the predicate that cannot be pushed down </param>
        /// <returns> part of the predicate that can be pushed down </returns>
        private static Node GetPushdownPredicate(Command command, Node filterNode, VarVec columns, out Node nonPushdownPredicateNode)
        {
            var pushdownPredicateNode = filterNode.Child1;
            nonPushdownPredicateNode = null;
            var filterNodeInfo = command.GetExtendedNodeInfo(filterNode);
            if (columns == null
                && filterNodeInfo.ExternalReferences.IsEmpty)
            {
                return pushdownPredicateNode;
            }

            if (columns == null)
            {
                var inputNodeInfo = command.GetExtendedNodeInfo(filterNode.Child0);
                columns = inputNodeInfo.Definitions;
            }

            var predicate = new Predicate(command, pushdownPredicateNode);
            Predicate nonPushdownPredicate;
            predicate = predicate.GetSingleTablePredicates(columns, out nonPushdownPredicate);
            pushdownPredicateNode = predicate.BuildAndTree();
            nonPushdownPredicateNode = nonPushdownPredicate.BuildAndTree();
            return pushdownPredicateNode;
        }
 private OpCopierTrackingCollectionVars(Command cmd)
     : base(cmd)
 {
 }
예제 #16
0
        private void Initialize()
        {
            // Only support queries for now
            var cqtree = m_ctree as cqt.DbQueryCommandTree;
            Assert(cqtree != null, "Unexpected command tree kind. Only query command tree is supported.");

            // Generate the ITree
            m_command = ITreeGenerator.Generate(cqtree);
            Assert(m_command != null, "Unable to generate internal tree from Command Tree");
        }
예제 #17
0
 // <summary>
 // Process Driver
 // </summary>
 // <param name="referencedTypes"> structured types referenced in the query </param>
 // <param name="referencedEntitySets"> entitysets referenced in the query </param>
 // <param name="freeFloatingEntityConstructorTypes"> entity types that have "free-floating" entity constructors </param>
 // <param name="discriminatorMaps"> information on optimized discriminator patterns for entity sets </param>
 // <param name="relPropertyHelper"> helper for rel properties </param>
 // <param name="typesNeedingNullSentinel"> which types need a null sentinel </param>
 internal static void Process(
     Command itree,
     HashSet<md.TypeUsage> referencedTypes,
     HashSet<md.EntitySet> referencedEntitySets,
     HashSet<md.EntityType> freeFloatingEntityConstructorTypes,
     Dictionary<md.EntitySetBase, DiscriminatorMapInfo> discriminatorMaps,
     RelPropertyHelper relPropertyHelper,
     HashSet<string> typesNeedingNullSentinel,
     out StructuredTypeInfo structuredTypeInfo)
 {
     structuredTypeInfo = new StructuredTypeInfo(typesNeedingNullSentinel);
     structuredTypeInfo.Process(
         itree, referencedTypes, referencedEntitySets, freeFloatingEntityConstructorTypes, discriminatorMaps, relPropertyHelper);
 }
 // <summary>
 // Private constructor
 // </summary>
 private GroupAggregateRefComputingVisitor(Command itree)
 {
     _command = itree;
 }
예제 #19
0
        private void Process(
            Command itree,
            HashSet<md.TypeUsage> referencedTypes,
            HashSet<md.EntitySet> referencedEntitySets,
            HashSet<md.EntityType> freeFloatingEntityConstructorTypes,
            Dictionary<md.EntitySetBase, DiscriminatorMapInfo> discriminatorMaps,
            RelPropertyHelper relPropertyHelper)
        {
            PlanCompiler.Assert(null != itree, "null itree?");

            m_stringType = itree.StringType;
            m_intType = itree.IntegerType;
            m_relPropertyHelper = relPropertyHelper;

            ProcessEntitySets(referencedEntitySets, freeFloatingEntityConstructorTypes);
            ProcessDiscriminatorMaps(discriminatorMaps);
            ProcessTypes(referencedTypes);
        }
예제 #20
0
 /// <summary>
 ///     Constructs a new VarRefManager given a command.
 /// </summary>
 internal VarRefManager(Command command)
 {
     m_nodeToParentMap = new Dictionary<Node, Node>();
     m_nodeToSiblingNumber = new Dictionary<Node, int>();
     m_command = command;
 }
예제 #21
0
 private VarRefReplacer(Dictionary<Var, Node> varReplacementTable, Command command)
 {
     m_varReplacementTable = varReplacementTable;
     m_command = command;
 }
 protected BasicValidator(Command command)
 {
     m_command = command;
 }
예제 #23
0
 internal KeyVec(Command itree)
 {
     m_keys = itree.CreateVarVec();
     m_noKeys = true;
 }
예제 #24
0
 // <summary>
 // Create an empty predicate
 // </summary>
 internal Predicate(Command command)
 {
     m_command = command;
     m_parts = new List<Node>();
 }
예제 #25
0
 /// <summary>
 ///     Public entry point. Returns true if at least one of the given vars occurs more than
 ///     once in the subree rooted at the given root.
 /// </summary>
 /// <param name="varVec"> </param>
 /// <param name="root"> </param>
 /// <param name="command"> </param>
 /// <returns> </returns>
 internal static bool AnyVarUsedMoreThanOnce(VarVec varVec, Node root, Command command)
 {
     var usageFinder = new VarRefUsageFinder(varVec, command);
     usageFinder.VisitNode(root);
     return usageFinder.m_anyUsedMoreThenOnce;
 }
예제 #26
0
 protected BasicValidator(Command command)
 {
     m_command = command;
 }
예제 #27
0
 private SortRemover(Command command, Node topMostSort)
 {
     m_command = command;
     m_topMostSort = topMostSort;
 }
예제 #28
0
 private AggregatePushdown(Command command)
 {
     m_command = command;
 }
예제 #29
0
 /// <summary>
 ///     "Public" entry point. In the subtree rooted at the given root,
 ///     replace each occurance of the given vars with their definitions,
 ///     where each key-value pair in the dictionary is a var-definition pair.
 /// </summary>
 /// <param name="varReplacementTable"> </param>
 /// <param name="root"> </param>
 /// <param name="command"> </param>
 /// <returns> </returns>
 internal static Node Replace(Dictionary<Var, Node> varReplacementTable, Node root, Command command)
 {
     var replacer = new VarRefReplacer(varReplacementTable, command);
     return replacer.VisitNode(root);
 }
예제 #30
0
 internal Predicate(Command command, Node andTree)
     : this(command)
 {
     PlanCompiler.Assert(andTree != null, "null node passed to Predicate() constructor");
     InitFromAndTree(andTree);
 }
예제 #31
0
 private VarRefUsageFinder(VarVec varVec, Command command)
 {
     m_varVec = varVec;
     m_usedVars = command.CreateVarVec();
 }
예제 #32
0
 protected static void AssertEqualTypes(TypeUsage type1, TypeUsage type2)
 {
     Assert(
         Command.EqualTypes(type1, type2),
         "Type mismatch: " + type1.Identity + ", " + type2.Identity);
 }