Esempio n. 1
0
        public static void Apply(
            ExprNode target,
            ExprNode start,
            ExprNode end,
            bool includeStart,
            bool includeEnd,
            bool isNot,
            QueryGraphForge queryGraph)
        {
            var rangeOp = QueryGraphRangeEnumExtensions.GetRangeOp(includeStart, includeEnd, isNot);

            if (target is ExprIdentNode &&
                start is ExprIdentNode &&
                end is ExprIdentNode) {
                var identNodeValue = (ExprIdentNode) target;
                var identNodeStart = (ExprIdentNode) start;
                var identNodeEnd = (ExprIdentNode) end;

                var keyStreamStart = identNodeStart.StreamId;
                var keyStreamEnd = identNodeEnd.StreamId;
                var valueStream = identNodeValue.StreamId;
                queryGraph.AddRangeStrict(
                    keyStreamStart,
                    identNodeStart,
                    keyStreamEnd,
                    identNodeEnd,
                    valueStream,
                    identNodeValue,
                    rangeOp);
                return;
            }

            // handle constant-compare or transformation case
            if (target is ExprIdentNode) {
                var identNode = (ExprIdentNode) target;
                var indexedStream = identNode.StreamId;

                var eligibilityStart = EligibilityUtil.VerifyInputStream(start, indexedStream);
                if (!eligibilityStart.Eligibility.IsEligible()) {
                    return;
                }

                var eligibilityEnd = EligibilityUtil.VerifyInputStream(end, indexedStream);
                if (!eligibilityEnd.Eligibility.IsEligible()) {
                    return;
                }

                queryGraph.AddRangeExpr(
                    indexedStream,
                    identNode,
                    start,
                    eligibilityStart.StreamNum,
                    end,
                    eligibilityEnd.StreamNum,
                    rangeOp);
            }
        }
Esempio n. 2
0
        private static void AnalyzeInNodeSingleIndex(
            ExprInNode inNode,
            QueryGraphForge queryGraph)
        {
            if (!(inNode.ChildNodes[0] is ExprIdentNode)) {
                return;
            }

            var testIdent = (ExprIdentNode) inNode.ChildNodes[0];
            var testIdentClass = testIdent.Forge.EvaluationType.GetBoxedType();
            var indexedStream = testIdent.StreamId;

            var setExpressions = GetInNodeSetExpressions(inNode);
            if (setExpressions.Length == 0) {
                return;
            }

            var perStreamExprs = new LinkedHashMap<int?, IList<ExprNode>>();

            foreach (var exprNodeSet in setExpressions) {
                if (exprNodeSet.Forge.EvaluationType.GetBoxedType() != testIdentClass) {
                    continue;
                }

                if (exprNodeSet is ExprIdentNode) {
                    var setIdent = (ExprIdentNode) exprNodeSet;
                    AddToList(setIdent.StreamId, setIdent, perStreamExprs);
                }
                else {
                    var eligibility = EligibilityUtil.VerifyInputStream(exprNodeSet, indexedStream);
                    if (!eligibility.Eligibility.IsEligible()) {
                        continue;
                    }

                    AddToList(eligibility.StreamNum, exprNodeSet, perStreamExprs);
                }
            }

            foreach (var entry in perStreamExprs) {
                var exprNodes = ExprNodeUtilityQuery.ToArray(entry.Value);
                if (entry.Key == null) {
                    queryGraph.AddInSetSingleIndexUnkeyed(testIdent.StreamId, testIdent, exprNodes);
                    continue;
                }

                if (entry.Key != indexedStream) {
                    queryGraph.AddInSetSingleIndex(testIdent.StreamId, testIdent, entry.Key.Value, exprNodes);
                }
            }
        }
Esempio n. 3
0
        private static void AnalyzeRelationalOpNode(
            ExprRelationalOpNode relNode,
            QueryGraphForge queryGraph)
        {
            if (relNode.ChildNodes[0] is ExprIdentNode &&
                relNode.ChildNodes[1] is ExprIdentNode) {
                var identNodeLeft = (ExprIdentNode) relNode.ChildNodes[0];
                var identNodeRight = (ExprIdentNode) relNode.ChildNodes[1];

                if (identNodeLeft.StreamId != identNodeRight.StreamId) {
                    queryGraph.AddRelationalOpStrict(
                        identNodeLeft.StreamId,
                        identNodeLeft,
                        identNodeRight.StreamId,
                        identNodeRight,
                        relNode.RelationalOpEnum);
                }

                return;
            }

            var indexedStream = -1;
            ExprIdentNode indexedPropExpr = null;
            ExprNode exprNodeNoIdent = null;
            var relop = relNode.RelationalOpEnum;

            if (relNode.ChildNodes[0] is ExprIdentNode) {
                indexedPropExpr = (ExprIdentNode) relNode.ChildNodes[0];
                indexedStream = indexedPropExpr.StreamId;
                exprNodeNoIdent = relNode.ChildNodes[1];
            }
            else if (relNode.ChildNodes[1] is ExprIdentNode) {
                indexedPropExpr = (ExprIdentNode) relNode.ChildNodes[1];
                indexedStream = indexedPropExpr.StreamId;
                exprNodeNoIdent = relNode.ChildNodes[0];
                relop = relop.Reversed();
            }

            if (indexedStream == -1) {
                return; // require property of right/left side of equals
            }

            var eligibility = EligibilityUtil.VerifyInputStream(exprNodeNoIdent, indexedStream);
            if (!eligibility.Eligibility.IsEligible()) {
                return;
            }

            queryGraph.AddRelationalOp(indexedStream, indexedPropExpr, eligibility.StreamNum, exprNodeNoIdent, relop);
        }
Esempio n. 4
0
        private static void AnalyzeInNodeMultiIndex(
            ExprInNode inNode,
            QueryGraphForge queryGraph)
        {
            var setExpressions = GetInNodeSetExpressions(inNode);
            if (setExpressions.Length == 0) {
                return;
            }

            var perStreamExprs = new LinkedHashMap<int?, IList<ExprNode>>();
            foreach (var exprNodeSet in setExpressions) {
                if (!(exprNodeSet is ExprIdentNode)) {
                    continue;
                }

                var setIdent = (ExprIdentNode) exprNodeSet;
                AddToList(setIdent.StreamId, setIdent, perStreamExprs);
            }

            if (perStreamExprs.IsEmpty()) {
                return;
            }

            var testExpr = inNode.ChildNodes[0];
            var testExprType = testExpr.Forge.EvaluationType.GetBoxedType();
            if (perStreamExprs.Count > 1) {
                return;
            }

            var entry = perStreamExprs.First();
            var exprNodes = ExprNodeUtilityQuery.ToArray(entry.Value);
            foreach (var node in exprNodes) {
                var exprType = node.Forge.EvaluationType;
                if (exprType.GetBoxedType() != testExprType) {
                    return;
                }
            }

            int? testStreamNum;
            var setStream = entry.Key.Value;
            if (!(testExpr is ExprIdentNode)) {
                var eligibility = EligibilityUtil.VerifyInputStream(testExpr, setStream);
                if (!eligibility.Eligibility.IsEligible()) {
                    return;
                }

                if (eligibility.Eligibility == Eligibility.REQUIRE_ONE && setStream == eligibility.StreamNum) {
                    return;
                }

                testStreamNum = eligibility.StreamNum;
            }
            else {
                testStreamNum = ((ExprIdentNode) testExpr).StreamId;
            }

            if (testStreamNum == null) {
                queryGraph.AddInSetMultiIndexUnkeyed(testExpr, setStream, exprNodes);
            }
            else {
                if (testStreamNum.Equals(entry.Key)) {
                    return;
                }

                queryGraph.AddInSetMultiIndex(testStreamNum.Value, testExpr, setStream, exprNodes);
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     Analye EQUALS (=) node.
        /// </summary>
        /// <param name="equalsNode">node to analyze</param>
        /// <param name="queryGraph">store relationships between stream properties</param>
        /// <param name="isOuterJoin">indicator for outer join</param>
        protected internal static void AnalyzeEqualsNode(
            ExprEqualsNode equalsNode,
            QueryGraphForge queryGraph,
            bool isOuterJoin)
        {
            if (equalsNode.ChildNodes[0] is ExprIdentNode &&
                equalsNode.ChildNodes[1] is ExprIdentNode) {
                var identNodeLeft = (ExprIdentNode) equalsNode.ChildNodes[0];
                var identNodeRight = (ExprIdentNode) equalsNode.ChildNodes[1];

                if (identNodeLeft.StreamId != identNodeRight.StreamId) {
                    queryGraph.AddStrictEquals(
                        identNodeLeft.StreamId,
                        identNodeLeft.ResolvedPropertyName,
                        identNodeLeft,
                        identNodeRight.StreamId,
                        identNodeRight.ResolvedPropertyName,
                        identNodeRight);
                }

                return;
            }

            if (isOuterJoin) {
                // outerjoins don't use constants or one-way expression-derived information to evaluate join
                return;
            }

            // handle constant-compare or transformation case
            var indexedStream = -1;
            ExprIdentNode indexedPropExpr = null;
            ExprNode exprNodeNoIdent = null;

            if (equalsNode.ChildNodes[0] is ExprIdentNode) {
                indexedPropExpr = (ExprIdentNode) equalsNode.ChildNodes[0];
                indexedStream = indexedPropExpr.StreamId;
                exprNodeNoIdent = equalsNode.ChildNodes[1];
            }
            else if (equalsNode.ChildNodes[1] is ExprIdentNode) {
                indexedPropExpr = (ExprIdentNode) equalsNode.ChildNodes[1];
                indexedStream = indexedPropExpr.StreamId;
                exprNodeNoIdent = equalsNode.ChildNodes[0];
            }

            if (indexedStream == -1) {
                return; // require property of right/left side of equals
            }

            var eligibility = EligibilityUtil.VerifyInputStream(exprNodeNoIdent, indexedStream);
            if (!eligibility.Eligibility.IsEligible()) {
                return;
            }

            if (eligibility.Eligibility == Eligibility.REQUIRE_NONE) {
                queryGraph.AddUnkeyedExpression(indexedStream, indexedPropExpr, exprNodeNoIdent);
            }
            else {
                queryGraph.AddKeyedExpression(
                    indexedStream,
                    indexedPropExpr,
                    eligibility.StreamNum.Value,
                    exprNodeNoIdent);
            }
        }