public static ExprAndNode Make2SubNodeAnd() { ExprAndNode topNode = new ExprAndNodeImpl(); ExprEqualsNode e1 = new ExprEqualsNodeImpl(false, false); ExprEqualsNode e2 = new ExprEqualsNodeImpl(false, false); topNode.AddChildNode(e1); topNode.AddChildNode(e2); ExprIdentNode i1_1 = new ExprIdentNodeImpl("IntPrimitive", "s0"); ExprIdentNode i1_2 = new ExprIdentNodeImpl("IntBoxed", "s1"); e1.AddChildNode(i1_1); e1.AddChildNode(i1_2); ExprIdentNode i2_1 = new ExprIdentNodeImpl("TheString", "s1"); ExprIdentNode i2_2 = new ExprIdentNodeImpl("TheString", "s0"); e2.AddChildNode(i2_1); e2.AddChildNode(i2_2); Validate3Stream(topNode); return(topNode); }
private ExprNode GetFilterExpressionInclOnClause(ExprNode optionalFilterNode, OuterJoinDesc[] outerJoinDescList) { if (optionalFilterNode == null) // no need to add as query planning is fully based on on-clause { return(null); } if (outerJoinDescList.Length == 0) // not an outer-join syntax { return(optionalFilterNode); } if (!OuterJoinDesc.ConsistsOfAllInnerJoins(outerJoinDescList)) // all-inner joins { return(optionalFilterNode); } ExprAndNode andNode = new ExprAndNodeImpl(); andNode.AddChildNode(optionalFilterNode); foreach (var outerJoinDesc in outerJoinDescList) { andNode.AddChildNode(outerJoinDesc.MakeExprNode(null)); } try { andNode.Validate(null); } catch (ExprValidationException ex) { throw new EPRuntimeException("Unexpected exception validating expression: " + ex.Message, ex); } return(andNode); }
public ExprNode MakeExprNode( StatementRawInfo statementRawInfo, StatementCompileTimeServices compileTimeServices) { ExprNode representativeNode = new ExprEqualsNodeImpl(false, false); representativeNode.AddChildNode(OptLeftNode); representativeNode.AddChildNode(OptRightNode); if (AdditionalLeftNodes == null) { TopValidate(representativeNode, statementRawInfo, compileTimeServices); return representativeNode; } ExprAndNode andNode = new ExprAndNodeImpl(); TopValidate(representativeNode, statementRawInfo, compileTimeServices); andNode.AddChildNode(representativeNode); representativeNode = andNode; for (var i = 0; i < AdditionalLeftNodes.Length; i++) { ExprEqualsNode eqNode = new ExprEqualsNodeImpl(false, false); eqNode.AddChildNode(AdditionalLeftNodes[i]); eqNode.AddChildNode(AdditionalRightNodes[i]); TopValidate(eqNode, statementRawInfo, compileTimeServices); andNode.AddChildNode(eqNode); } TopValidate(andNode, statementRawInfo, compileTimeServices); return representativeNode; }
/// <summary>Make an expression node that represents the outer join criteria as specified in the on-clause. </summary> /// <param name="exprEvaluatorContext">context for expression evalauation</param> /// <returns>expression node for outer join criteria</returns> public ExprNode MakeExprNode(ExprEvaluatorContext exprEvaluatorContext) { ExprNode representativeNode = new ExprEqualsNodeImpl(false, false); representativeNode.AddChildNode(OptLeftNode); representativeNode.AddChildNode(OptRightNode); if (AdditionalLeftNodes == null) { TopValidate(representativeNode, exprEvaluatorContext); return(representativeNode); } ExprAndNode andNode = new ExprAndNodeImpl(); TopValidate(representativeNode, exprEvaluatorContext); andNode.AddChildNode(representativeNode); representativeNode = andNode; for (int i = 0; i < AdditionalLeftNodes.Length; i++) { ExprEqualsNode eqNode = new ExprEqualsNodeImpl(false, false); eqNode.AddChildNode(AdditionalLeftNodes[i]); eqNode.AddChildNode(AdditionalRightNodes[i]); TopValidate(eqNode, exprEvaluatorContext); andNode.AddChildNode(eqNode); } TopValidate(andNode, exprEvaluatorContext); return(representativeNode); }
public static ExprNode ConnectExpressionsByLogicalAndWhenNeeded(ExprNode left, ExprNode right) { if (left == null && right == null) { return null; } if (left != null && right == null) { return left; } if (left == null) { return right; } ExprAndNode andNode = new ExprAndNodeImpl(); andNode.AddChildNode(left); andNode.AddChildNode(right); return andNode; }
public static ExprNode Make3SubNodeAnd() { ExprNode topNode = new ExprAndNodeImpl(); var equalNodes = new ExprEqualsNode[3]; for (var i = 0; i < equalNodes.Length; i++) { equalNodes[i] = new ExprEqualsNodeImpl(false, false); topNode.AddChildNode(equalNodes[i]); } ExprIdentNode i1_1 = new ExprIdentNodeImpl("IntPrimitive", "s0"); ExprIdentNode i1_2 = new ExprIdentNodeImpl("IntBoxed", "s1"); equalNodes[0].AddChildNode(i1_1); equalNodes[0].AddChildNode(i1_2); ExprIdentNode i2_1 = new ExprIdentNodeImpl("TheString", "s1"); ExprIdentNode i2_2 = new ExprIdentNodeImpl("TheString", "s0"); equalNodes[1].AddChildNode(i2_1); equalNodes[1].AddChildNode(i2_2); ExprIdentNode i3_1 = new ExprIdentNodeImpl("BoolBoxed", "s0"); ExprIdentNode i3_2 = new ExprIdentNodeImpl("BoolPrimitive", "s1"); equalNodes[2].AddChildNode(i3_1); equalNodes[2].AddChildNode(i3_2); Validate3Stream(topNode); return(topNode); }
public static ExprAndNode ConnectExpressionsByLogicalAnd(ICollection<ExprNode> nodes) { if (nodes.Count < 2) { throw new ArgumentException("Invalid empty or 1-element list of nodes"); } ExprAndNode andNode = new ExprAndNodeImpl(); foreach (ExprNode node in nodes) { andNode.AddChildNode(node); } return andNode; }
private static void RewriteNamedWindowSubselect( IList<ExprDotNode> chainedExpressionsDot, IList<ExprSubselectNode> subselects, NamedWindowCompileTimeResolver service) { foreach (var dotNode in chainedExpressionsDot) { if (dotNode.ChainSpec.IsEmpty()) { continue; } var proposedWindow = dotNode.ChainSpec[0].GetRootNameOrEmptyString(); var namedWindowDetail = service.Resolve(proposedWindow); if (namedWindowDetail == null) { continue; } // build spec for subselect var raw = new StatementSpecRaw(SelectClauseStreamSelectorEnum.ISTREAM_ONLY); var filter = new FilterSpecRaw(proposedWindow, Collections.GetEmptyList<ExprNode>(), null); raw.StreamSpecs.Add( new FilterStreamSpecRaw( filter, ViewSpec.EMPTY_VIEWSPEC_ARRAY, proposedWindow, StreamSpecOptions.DEFAULT)); var modified = new List<Chainable>(dotNode.ChainSpec); var firstChain = modified.DeleteAt(0); var firstChainParams = firstChain.GetParametersOrEmpty(); if (!firstChainParams.IsEmpty()) { if (firstChainParams.Count == 1) { raw.WhereClause = firstChainParams[0]; } else { ExprAndNode andNode = new ExprAndNodeImpl(); foreach (ExprNode node in firstChainParams) { andNode.AddChildNode(node); } raw.WhereClause = andNode; } } // activate subselect ExprSubselectNode subselect = new ExprSubselectRowNode(raw); subselects.Add(subselect); dotNode.ChildNodes = new ExprNode[] {subselect}; dotNode.ChainSpec = modified; } }
private static ExprNode Unwind(ExprNode node) { var isOr = node is ExprOrNode; var isAnd = node is ExprAndNode; if (!isOr && !isAnd) { return node; } var needsUnwind = false; foreach (var child in node.ChildNodes) { if (child is ExprOrNode && isOr || child is ExprAndNode && isAnd) { needsUnwind = true; break; } } if (!needsUnwind) { return node; } if (isOr) { var unwoundX = new ExprOrNode(); foreach (var child in node.ChildNodes) { if (child is ExprOrNode) { foreach (var orChild in child.ChildNodes) { var unwoundChild = Unwind(orChild); if (unwoundChild is ExprOrNode) { unwoundX.AddChildNodes(Arrays.AsList(unwoundChild.ChildNodes)); } else { unwoundX.AddChildNode(unwoundChild); } } } else { unwoundX.AddChildNode(Unwind(child)); } } return unwoundX; } ExprAndNode unwound = new ExprAndNodeImpl(); foreach (var child in node.ChildNodes) { if (child is ExprAndNode) { foreach (var andChild in child.ChildNodes) { var unwoundChild = Unwind(andChild); if (unwoundChild is ExprAndNode) { unwound.AddChildNodes(Arrays.AsList(unwoundChild.ChildNodes)); } else { unwound.AddChildNode(unwoundChild); } } } else { unwound.AddChildNode(Unwind(child)); } } return unwound; }
private static JoinSetComposerPrototype MakeComposerHistorical2Stream(OuterJoinDesc[] outerJoinDescList, ExprNode optionalFilterNode, EventType[] streamTypes, HistoricalViewableDesc historicalViewableDesc, bool queryPlanLogging, ExprEvaluatorContext exprEvaluatorContext, StatementContext statementContext, string[] streamNames, bool allowIndexInit) { var polledViewNum = 0; var streamViewNum = 1; if (historicalViewableDesc.Historical[1]) { streamViewNum = 0; polledViewNum = 1; } // if all-historical join, check dependency var isAllHistoricalNoSubordinate = false; if ((historicalViewableDesc.Historical[0]) && historicalViewableDesc.Historical[1]) { var graph = new DependencyGraph(2, false); graph.AddDependency(0, historicalViewableDesc.DependenciesPerHistorical[0]); graph.AddDependency(1, historicalViewableDesc.DependenciesPerHistorical[1]); if (graph.FirstCircularDependency != null) { throw new ExprValidationException("Circular dependency detected between historical streams"); } // if both streams are independent if (graph.RootNodes.Count == 2) { isAllHistoricalNoSubordinate = true; // No parameters used by either historical } else { if ((graph.GetDependenciesForStream(0).Count == 0)) { streamViewNum = 0; polledViewNum = 1; } else { streamViewNum = 1; polledViewNum = 0; } } } // Build an outer join expression node var isOuterJoin = false; var isInnerJoinOnly = false; ExprNode outerJoinEqualsNode = null; if (outerJoinDescList.Length > 0) { var outerJoinDesc = outerJoinDescList[0]; isInnerJoinOnly = outerJoinDesc.OuterJoinType == OuterJoinType.INNER; if (outerJoinDesc.OuterJoinType.Equals(OuterJoinType.FULL)) { isOuterJoin = true; } else if ((outerJoinDesc.OuterJoinType.Equals(OuterJoinType.LEFT)) && (streamViewNum == 0)) { isOuterJoin = true; } else if ((outerJoinDesc.OuterJoinType.Equals(OuterJoinType.RIGHT)) && (streamViewNum == 1)) { isOuterJoin = true; } outerJoinEqualsNode = outerJoinDesc.MakeExprNode(exprEvaluatorContext); } // Determine filter for indexing purposes ExprNode filterForIndexing = null; if ((outerJoinEqualsNode != null) && (optionalFilterNode != null) && isInnerJoinOnly) // both filter and outer join, add { filterForIndexing = new ExprAndNodeImpl(); filterForIndexing.AddChildNode(optionalFilterNode); filterForIndexing.AddChildNode(outerJoinEqualsNode); } else if ((outerJoinEqualsNode == null) && (optionalFilterNode != null)) { filterForIndexing = optionalFilterNode; } else if (outerJoinEqualsNode != null) { filterForIndexing = outerJoinEqualsNode; } var indexStrategies = DetermineIndexing(filterForIndexing, streamTypes[polledViewNum], streamTypes[streamViewNum], polledViewNum, streamViewNum, statementContext, streamNames); var hook = QueryPlanIndexHookUtil.GetHook(statementContext.Annotations); if (queryPlanLogging && (QueryPlanLog.IsInfoEnabled || hook != null)) { QueryPlanLog.Info("historical lookup strategy: " + indexStrategies.First.ToQueryPlan()); QueryPlanLog.Info("historical index strategy: " + indexStrategies.Second.ToQueryPlan()); if (hook != null) { hook.Historical(new QueryPlanIndexDescHistorical(indexStrategies.First.GetType().Name, indexStrategies.Second.GetType().Name)); } } return(new JoinSetComposerPrototypeHistorical2StreamImpl( optionalFilterNode, streamTypes, exprEvaluatorContext, polledViewNum, streamViewNum, isOuterJoin, outerJoinEqualsNode, indexStrategies, isAllHistoricalNoSubordinate, outerJoinDescList, allowIndexInit)); }
private static JoinSetComposerPrototypeHistorical2StreamDesc MakeComposerHistorical2Stream( OuterJoinDesc[] outerJoinDescs, ExprNode whereClause, EventType[] streamTypes, string[] streamNames, HistoricalViewableDesc historicalViewableDesc, bool queryPlanLogging, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { var polledViewNum = 0; var streamViewNum = 1; if (historicalViewableDesc.Historical[1]) { streamViewNum = 0; polledViewNum = 1; } // if all-historical join, check dependency var isAllHistoricalNoSubordinate = false; if (historicalViewableDesc.Historical[0] && historicalViewableDesc.Historical[1]) { var graph = new DependencyGraph(2, false); graph.AddDependency(0, historicalViewableDesc.DependenciesPerHistorical[0]); graph.AddDependency(1, historicalViewableDesc.DependenciesPerHistorical[1]); if (graph.FirstCircularDependency != null) { throw new ExprValidationException("Circular dependency detected between historical streams"); } // if both streams are independent if (graph.RootNodes.Count == 2) { isAllHistoricalNoSubordinate = true; // No parameters used by either historical } else { if (graph.GetDependenciesForStream(0).Count == 0) { streamViewNum = 0; polledViewNum = 1; } else { streamViewNum = 1; polledViewNum = 0; } } } // Build an outer join expression node var isOuterJoin = false; ExprNode outerJoinEqualsNode = null; var isInnerJoinOnly = false; var outerJoinPerStream = new bool[2]; if (outerJoinDescs != null && outerJoinDescs.Length > 0) { var outerJoinDesc = outerJoinDescs[0]; isInnerJoinOnly = outerJoinDesc.OuterJoinType.Equals(OuterJoinType.INNER); if (isAllHistoricalNoSubordinate) { if (outerJoinDesc.OuterJoinType.Equals(OuterJoinType.FULL)) { isOuterJoin = true; outerJoinPerStream[0] = true; outerJoinPerStream[1] = true; } else if (outerJoinDesc.OuterJoinType.Equals(OuterJoinType.LEFT)) { isOuterJoin = true; outerJoinPerStream[0] = true; } else if (outerJoinDesc.OuterJoinType.Equals(OuterJoinType.RIGHT)) { isOuterJoin = true; outerJoinPerStream[1] = true; } } else { if (outerJoinDesc.OuterJoinType.Equals(OuterJoinType.FULL)) { isOuterJoin = true; outerJoinPerStream[0] = true; outerJoinPerStream[1] = true; } else if (outerJoinDesc.OuterJoinType.Equals(OuterJoinType.LEFT) && streamViewNum == 0) { isOuterJoin = true; outerJoinPerStream[0] = true; } else if (outerJoinDesc.OuterJoinType.Equals(OuterJoinType.RIGHT) && streamViewNum == 1) { isOuterJoin = true; outerJoinPerStream[1] = true; } } outerJoinEqualsNode = outerJoinDesc.MakeExprNode(statementRawInfo, services); } // Determine filter for indexing purposes ExprNode filterForIndexing = null; if (outerJoinEqualsNode != null && whereClause != null && isInnerJoinOnly) { // both filter and outer join, add filterForIndexing = new ExprAndNodeImpl(); filterForIndexing.AddChildNode(whereClause); filterForIndexing.AddChildNode(outerJoinEqualsNode); } else if (outerJoinEqualsNode == null && whereClause != null) { filterForIndexing = whereClause; } else if (outerJoinEqualsNode != null) { filterForIndexing = outerJoinEqualsNode; } var indexStrategies = DetermineIndexing( filterForIndexing, streamTypes[polledViewNum], streamTypes[streamViewNum], polledViewNum, streamViewNum, streamNames, statementRawInfo, services); QueryPlanIndexHook hook = QueryPlanIndexHookUtil.GetHook( statementRawInfo.Annotations, services.ImportServiceCompileTime); if (queryPlanLogging && (QUERY_PLAN_LOG.IsInfoEnabled || hook != null)) { QUERY_PLAN_LOG.Info("historical lookup strategy: " + indexStrategies.LookupForge.ToQueryPlan()); QUERY_PLAN_LOG.Info("historical index strategy: " + indexStrategies.IndexingForge.ToQueryPlan()); hook?.Historical( new QueryPlanIndexDescHistorical( indexStrategies.LookupForge.GetType().GetSimpleName(), indexStrategies.IndexingForge.GetType().GetSimpleName())); } JoinSetComposerPrototypeHistorical2StreamForge forge = new JoinSetComposerPrototypeHistorical2StreamForge( streamTypes, whereClause, isOuterJoin, polledViewNum, streamViewNum, outerJoinEqualsNode, indexStrategies.LookupForge, indexStrategies.IndexingForge, isAllHistoricalNoSubordinate, outerJoinPerStream); return new JoinSetComposerPrototypeHistorical2StreamDesc( forge, indexStrategies.AdditionalForgeables); }