public void AppendFilterPlanPath( int indexPath, StringBuilder stringBuilder) { stringBuilder .Append(" -path #") .Append(indexPath) .Append(" there are ") .Append(Triplets.Length) .Append(" triplets") .Append(FilterSpecCompiler.NEWLINE); if (PathNegate != null) { stringBuilder .Append(" -path-negate-expression: ") .Append(ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(PathNegate)) .Append(FilterSpecCompiler.NEWLINE); } var indextriplet = 0; foreach (var forge in Triplets) { forge.AppendFilterPlanTriplet(indextriplet, stringBuilder); indextriplet++; } }
private void AssertRanges( object[][] ranges, QueryGraphValueForge value) { Assert.AreEqual(ranges.Length, value.Items.Count); var count = -1; foreach (var desc in value.Items) { count++; var r = (QueryGraphValueEntryRangeForge) desc.Entry; Assert.AreEqual(ranges[count][3], r.Type); Assert.AreEqual(ranges[count][4], ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(desc.IndexExprs[0])); if (r is QueryGraphValueEntryRangeRelOpForge) { var relOp = (QueryGraphValueEntryRangeRelOpForge) r; Assert.AreEqual(ranges[count][0], GetProp(relOp.Expression)); } else { var rangeIn = (QueryGraphValueEntryRangeInForge) r; Assert.AreEqual(ranges[count][1], GetProp(rangeIn.ExprStart)); Assert.AreEqual(ranges[count][2], GetProp(rangeIn.ExprEnd)); } } }
public static void ValidateFilterWQueryGraphSafe( QueryGraphForge queryGraph, ExprNode filterExpression, StreamTypeServiceImpl typeService, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { try { var validationContext = new ExprValidationContextBuilder(typeService, statementRawInfo, services) .WithAllowBindingConsumption(true) .WithIsFilterExpression(true) .Build(); var validated = ExprNodeUtilityValidate.GetValidatedSubtree( ExprNodeOrigin.FILTER, filterExpression, validationContext); FilterExprAnalyzer.Analyze(validated, queryGraph, false); } catch (Exception ex) { Log.Warn( "Unexpected exception analyzing filterable expression '" + ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(filterExpression) + "': " + ex.Message, ex); } }
public override void ToPrecedenceFreeEPL(TextWriter writer) { if (OptionalMaxExpressions == null || OptionalMaxExpressions.IsEmpty()) { PatternExpressionUtil.ToPrecedenceFreeEPL(writer, "->", ChildNodes, Precedence); } else { ChildNodes[0].ToEPL(writer, PatternExpressionPrecedenceEnum.MINIMUM); for (var i = 1; i < ChildNodes.Count; i++) { ExprNode optionalMaxExpression = null; if (OptionalMaxExpressions.Count > i - 1) { optionalMaxExpression = OptionalMaxExpressions[i - 1]; } if (optionalMaxExpression == null) { writer.Write(" -> "); } else { writer.Write(" -["); writer.Write(ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(optionalMaxExpression)); writer.Write("]> "); } ChildNodes[i].ToEPL(writer, PatternExpressionPrecedenceEnum.MINIMUM); } } }
public void TestToExpressionString() { andNode.AddChildNode(new SupportExprNode(true)); andNode.AddChildNode(new SupportExprNode(false)); Assert.AreEqual("true and false", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(andNode)); }
private static void ValidateIntoTableCompatible( string tableName, string columnName, TableMetadataColumnAggregation columnMetadata, AggregationServiceAggExpressionDesc aggDesc) { var factoryProvided = aggDesc.Factory.AggregationPortableValidation; var factoryRequired = columnMetadata.AggregationPortableValidation; try { factoryRequired.ValidateIntoTableCompatible( columnMetadata.AggregationExpression, factoryProvided, ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(aggDesc.AggregationNode), aggDesc.Factory); } catch (ExprValidationException ex) { var text = GetMessage( tableName, columnName, columnMetadata.AggregationExpression, aggDesc.Factory.AggregationExpression); throw new ExprValidationException(text + ": " + ex.Message, ex); } }
public override void ToPrecedenceFreeEPL( TextWriter writer, ExprNodeRenderableFlags flags) { writer.Write(NAME); ExprNodeUtilityPrint.ToExpressionStringParams(writer, this.ChildNodes); }
public static ExprNode ValidateSingleIndexExpr( IList<ExprNode> indexes, Supplier<string> supplier) { if (indexes.Count != 1) { throw new ExprValidationException( "Incorrect number of index expressions for array operation, expected a single expression returning an integer value but received " + indexes.Count + " expressions for " + supplier.Invoke()); } ExprNode node = indexes[0]; var evaluationType = node.Forge.EvaluationType; if (!evaluationType.IsInt32()) { throw new ExprValidationException( "Incorrect index expression for array operation, expected an expression returning an integer value but the expression '" + ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(node) + "' returns '" + evaluationType.CleanName() + "' for " + supplier.Invoke()); } return node; }
public override void ToPrecedenceFreeEPL( TextWriter writer, ExprNodeRenderableFlags flags) { writer.Write(Script.Name); ExprNodeUtilityPrint.ToExpressionStringIncludeParen(Parameters, writer); }
private static FilterSpecParamFilterForEvalDoubleForge ResolveFilterIndexDoubleEval( string indexName, ExprNode indexExpression, IDictionary<string, Pair<EventType, string>> arrayEventTypes, string statementName) { FilterSpecParamFilterForEvalDoubleForge resolved = null; if (indexExpression is ExprIdentNode) { resolved = GetIdentNodeDoubleEval((ExprIdentNode) indexExpression, arrayEventTypes, statementName); } else if (indexExpression is ExprContextPropertyNode) { var node = (ExprContextPropertyNode) indexExpression; resolved = new FilterForEvalContextPropDoubleForge(node.Getter, node.PropertyName); } else if (indexExpression.Forge.ForgeConstantType.IsCompileTimeConstant) { double d = indexExpression.Forge.ExprEvaluator.Evaluate(null, true, null).AsDouble(); resolved = new FilterForEvalConstantDoubleForge(d); } else if (indexExpression.Forge.ForgeConstantType.IsConstant) { resolved = new FilterForEvalConstRuntimeExprForge(indexExpression); } if (resolved != null) { return resolved; } throw new ExprValidationException( "Invalid filter-indexable expression '" + ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(indexExpression) + "' in respect to index '" + indexName + "': expected either a constant, context-builtin or property from a previous pattern match"); }
public static IList<ExprNode> ValidateAllowSubquery( ExprNodeOrigin exprNodeOrigin, IList<ExprNode> exprNodes, StreamTypeService streamTypeService, IDictionary<string, Pair<EventType, string>> taggedEventTypes, IDictionary<string, Pair<EventType, string>> arrayEventTypes, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { IList<ExprNode> validatedNodes = new List<ExprNode>(); ExprValidationContext validationContext = new ExprValidationContextBuilder(streamTypeService, statementRawInfo, services) .WithAllowBindingConsumption(true) .WithIsFilterExpression(true) .Build(); foreach (var node in exprNodes) { // Determine subselects var visitor = new ExprNodeSubselectDeclaredDotVisitor(); node.Accept(visitor); // Compile subselects if (!visitor.Subselects.IsEmpty()) { // The outer event type is the filtered-type itself foreach (var subselect in visitor.Subselects) { try { SubSelectHelperFilters.HandleSubselectSelectClauses( subselect, streamTypeService.EventTypes[0], streamTypeService.StreamNames[0], streamTypeService.StreamNames[0], taggedEventTypes, arrayEventTypes, statementRawInfo, services); } catch (ExprValidationException ex) { throw new ExprValidationException( "Failed to validate " + ExprNodeUtilityMake.GetSubqueryInfoText(subselect) + ": " + ex.Message, ex); } } } var validated = ExprNodeUtilityValidate.GetValidatedSubtree(exprNodeOrigin, node, validationContext); validatedNodes.Add(validated); if (validated.Forge.EvaluationType != typeof(bool?) && validated.Forge.EvaluationType != typeof(bool)) { throw new ExprValidationException( "Filter expression not returning a boolean value: '" + ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(validated) + "'"); } } return validatedNodes; }
public CodegenExpression Make( CodegenMethodScope parent, SAIFFInitializeSymbol symbols, CodegenClassScope classScope) { var method = parent.MakeChild( typeof(SubordInKeywordSingleTableLookupStrategyFactory), GetType(), classScope); var expressions = new string[exprNodes.Count]; method.Block.DeclareVar<ExprEvaluator[]>( "evals", NewArrayByLength(typeof(ExprEvaluator), Constant(exprNodes.Count))); for (var i = 0; i < exprNodes.Count; i++) { CodegenExpression eval = ExprNodeUtilityCodegen.CodegenEvaluatorNoCoerce( exprNodes[i].Forge, method, GetType(), classScope); method.Block.AssignArrayElement(Ref("evals"), Constant(i), eval); expressions[i] = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(exprNodes[i]); } method.Block.MethodReturn( NewInstance<SubordInKeywordSingleTableLookupStrategyFactory>( Constant(_isNwOnTrigger), Constant(_streamCountOuter), Ref("evals"), Constant(expressions))); return LocalMethod(method); }
private static void LogFilterPlans( IList<ExprNode> validatedNodes, FilterSpecPlanForge plan, EventType eventType, string optionalStreamName, StatementRawInfo statementRawInfo) { var buf = new StringBuilder(); buf .Append("Filter plan for statement '") .Append(statementRawInfo.StatementName) .Append("' filtering event type '") .Append(eventType.Name + "'"); if (optionalStreamName != null) { buf.Append(" alias '" + optionalStreamName + "'"); } if (validatedNodes.IsEmpty()) { buf.Append(" empty"); } else { var andNode = ExprNodeUtilityMake.ConnectExpressionsByLogicalAndWhenNeeded(validatedNodes); var expression = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(andNode); buf .Append(" expression '") .Append(expression) .Append("' for ") .Append(plan.Paths.Length) .Append(" paths"); } buf.Append(Environment.NewLine); plan.AppendPlan(buf); Log.Info(buf.ToString()); }
private static void ComparePlan(string[] expectedCSV) { var plan = SupportGroupRollupPlanHook.GetPlan(); var levels = plan.RollupDesc.Levels; var received = new string[levels.Length][]; for (var i = 0; i < levels.Length; i++) { var level = levels[i]; if (level.IsAggregationTop) { received[i] = new string[0]; } else { received[i] = new string[level.RollupKeys.Length]; for (var j = 0; j < received[i].Length; j++) { var key = level.RollupKeys[j]; received[i][j] = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(plan.Expressions[key]); } } } Assert.AreEqual(expectedCSV.Length, received.Length, "Received: " + ToCSV(received)); for (var i = 0; i < expectedCSV.Length; i++) { var receivedCSV = ToCSV(received[i]); Assert.AreEqual(expectedCSV[i], receivedCSV, "Failed at row " + i); } }
public CodegenExpression CodegenMake( CodegenMethodScope parent, CodegenClassScope classScope) { var method = parent.MakeChild( typeof(EventAdvancedIndexProvisionRuntime), typeof(EventAdvancedIndexProvisionCompileTime), classScope); var indexExpressions = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceAsArray(IndexDesc.IndexedExpressions); var indexProperties = GetPropertiesPerExpressionExpectSingle(IndexDesc.IndexedExpressions); method.Block .DeclareVar<EventAdvancedIndexProvisionRuntime>( "desc", NewInstance(typeof(EventAdvancedIndexProvisionRuntime))) .SetProperty(Ref("desc"), "IndexExpressionTexts", Constant(indexExpressions)) .SetProperty(Ref("desc"), "IndexProperties", Constant(indexProperties)) .SetProperty( Ref("desc"), "IsIndexExpressionsAllProps", Constant(IsExpressionsAllPropsOnly(IndexDesc.IndexedExpressions))) .SetProperty(Ref("desc"), "Factory", Factory.CodegenMake(parent, classScope)) .SetProperty( Ref("desc"), "ParameterExpressionTexts", Constant(ExprNodeUtilityPrint.ToExpressionStringsMinPrecedence(Parameters))) .SetProperty( Ref("desc"), "ParameterEvaluators", ExprNodeUtilityCodegen.CodegenEvaluators(Parameters, parent, GetType(), classScope)) .SetProperty(Ref("desc"), "ConfigStatement", ConfigStatement.CodegenMake(parent, classScope)) .SetProperty(Ref("desc"), "IndexTypeName", Constant(IndexDesc.IndexTypeName)) .MethodReturn(Ref("desc")); return LocalMethod(method); }
public SubordTableLookupStrategyFactoryQuadTreeForge GetSubordinateLookupStrategy( string operationName, IDictionary<int, ExprNode> positionalExpressions, bool isNWOnTrigger, int numOuterstreams) { ExprForge x = positionalExpressions.Get(0).Forge; ExprForge y = positionalExpressions.Get(1).Forge; ExprForge width = positionalExpressions.Get(2).Forge; ExprForge height = positionalExpressions.Get(3).Forge; string[] expressions = new string[positionalExpressions.Count]; foreach (KeyValuePair<int, ExprNode> entry in positionalExpressions) { expressions[entry.Key] = ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(entry.Value); } LookupStrategyDesc lookupStrategyDesc = new LookupStrategyDesc(LookupStrategyType.ADVANCED, expressions); return new SubordTableLookupStrategyFactoryQuadTreeForge( x, y, width, height, isNWOnTrigger, numOuterstreams, lookupStrategyDesc); }
public override void ToPrecedenceFreeEPL( TextWriter writer, ExprNodeRenderableFlags flags) { writer.Write(AggregationFunctionName); ExprNodeUtilityPrint.ToExpressionStringParams(writer, positionalParams); }
public override void ToPrecedenceFreeEPL( TextWriter writer, ExprNodeRenderableFlags flags) { writer.Write(_stateType?.GetNameInvariant()); ExprNodeUtilityPrint.ToExpressionStringParams(writer, this.ChildNodes); }
public void TestToExpressionString() { Assert.AreEqual("{}", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(arrayNodes[0])); Assert.AreEqual("{2,3}", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(arrayNodes[1])); Assert.AreEqual("{1.5d,1}", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(arrayNodes[2])); Assert.AreEqual("{\"a\",1}", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(arrayNodes[3])); }
public override void ToPrecedenceFreeEPL(TextWriter writer) { if (ChildNodes.Length != 0) { writer.Write(ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(ChildNodes[0])); } ExprNodeUtilityPrint.ToExpressionString(ChainSpec, writer, ChildNodes.Length != 0, null); }
public override void ValueExprToString( StringBuilder @out, int i) { @out.Append("expression '") .Append(ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(ExprNode)) .Append("'"); }
public void TestToExpressionString() { log.Debug(".testToExpressionString"); _bitWiseNode = new ExprBitWiseNode(BitWiseOpEnum.BAND); _bitWiseNode.AddChildNode(new SupportExprNode(4)); _bitWiseNode.AddChildNode(new SupportExprNode(2)); Assert.AreEqual("4&2", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(_bitWiseNode)); }
public void TestToExpressionString() { Assert.AreEqual("s0.TheString like \"%abc__\"", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(likeNodeNormal)); Assert.AreEqual("s0.TheString not like \"%abc__\"", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(likeNodeNot)); Assert.AreEqual( "s0.TheString like \"%abc__\" escape \"!\"", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(likeNodeNormalEscaped)); }
public void TestToExpressionString() { minMaxNode.AddChildNode(new SupportExprNode(9d)); minMaxNode.AddChildNode(new SupportExprNode(6)); Assert.AreEqual("max(9.0d,6)", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(minMaxNode)); minMaxNode.AddChildNode(new SupportExprNode(0.5d)); Assert.AreEqual("max(9.0d,6,0.5d)", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(minMaxNode)); }
public override string ToString() { return GetType().Name + " " + base.ToString() + " keyProperties=" + ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceAsList(Expressions); }
public void TestToExpressionString() { concatNode = new ExprConcatNode(); concatNode.AddChildNode(new SupportExprNode("a")); concatNode.AddChildNode(new SupportExprNode("b")); Assert.AreEqual("\"a\"||\"b\"", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(concatNode)); concatNode.AddChildNode(new SupportExprNode("c")); Assert.AreEqual("\"a\"||\"b\"||\"c\"", ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(concatNode)); }
public CodegenExpression Make( CodegenMethodScope parent, SAIFFInitializeSymbol symbols, CodegenClassScope classScope) { var methodNode = parent.MakeChild(typeof(SubordTableLookupStrategyFactory), GetType(), classScope); if (_isStrictKeys) { int[] keyStreamNums = IntArrayUtil.Copy(_keyStreamNumbers); var keyStreamTypes = _outerStreamTypesZeroIndexed; if (isNWOnTrigger) { keyStreamTypes = EventTypeUtility.ShiftRight(_outerStreamTypesZeroIndexed); for (var i = 0; i < keyStreamNums.Length; i++) { keyStreamNums[i] = keyStreamNums[i] + 1; } } var forges = ExprNodeUtilityQuery.ForgesForProperties( keyStreamTypes, _hashStrictKeys, keyStreamNums); var eval = MultiKeyCodegen.CodegenExprEvaluatorMayMultikey( forges, _hashKeyCoercionTypes.CoercionTypes, _hashMultikeyClasses, methodNode, classScope); methodNode.Block.MethodReturn( NewInstance<SubordHashedTableLookupStrategyPropFactory>( Constant(_hashStrictKeys), Constant(keyStreamNums), eval)); return LocalMethod(methodNode); } else { var forges = new ExprForge[_hashKeys.Count]; for (var i = 0; i < _hashKeys.Count; i++) { forges[i] = _hashKeys[i].HashKey.KeyExpr.Forge; } var expressions = ExprNodeUtilityPrint.ToExpressionStringsMinPrecedence(forges); var eval = MultiKeyCodegen.CodegenExprEvaluatorMayMultikey( forges, _hashKeyCoercionTypes.CoercionTypes, _hashMultikeyClasses, methodNode, classScope); methodNode.Block.MethodReturn( NewInstance<SubordHashedTableLookupStrategyExprFactory>( Constant(expressions), eval, Constant(isNWOnTrigger), Constant(_numStreamsOuter))); return LocalMethod(methodNode); } }
public static CodegenMethod GenerateGroupKeySingleCodegen( ExprNode[] groupKeyExpressions, MultiKeyClassRef optionalMultiKeyClasses, CodegenClassScope classScope, CodegenInstanceAux instance) { Consumer<CodegenMethod> code = methodNode => { string[] expressions = null; if (classScope.IsInstrumented) { expressions = ExprNodeUtilityPrint.ToExpressionStringsMinPrecedence(groupKeyExpressions); } methodNode.Block.Apply( Instblock( classScope, "qResultSetProcessComputeGroupKeys", ExprForgeCodegenNames.REF_ISNEWDATA, Constant(expressions), REF_EPS)); if (optionalMultiKeyClasses != null && optionalMultiKeyClasses.ClassNameMK != null) { var method = MultiKeyCodegen.CodegenMethod(groupKeyExpressions, optionalMultiKeyClasses, methodNode, classScope); methodNode .Block .DeclareVar<object>("key", LocalMethod(method, REF_EPS, ExprForgeCodegenNames.REF_ISNEWDATA, MEMBER_AGENTINSTANCECONTEXT)) .Apply(Instblock(classScope, "aResultSetProcessComputeGroupKeys", ExprForgeCodegenNames.REF_ISNEWDATA, Ref("key"))) .MethodReturn(Ref("key")); return; } if (groupKeyExpressions.Length > 1) { throw new IllegalStateException("Multiple group-by expression and no multikey"); } var expression = CodegenLegoMethodExpression.CodegenExpression(groupKeyExpressions[0].Forge, methodNode, classScope); methodNode .Block .DeclareVar<object>("key", LocalMethod(expression, REF_EPS, ExprForgeCodegenNames.REF_ISNEWDATA, MEMBER_AGENTINSTANCECONTEXT)) .Apply(Instblock(classScope, "aResultSetProcessComputeGroupKeys", ExprForgeCodegenNames.REF_ISNEWDATA, Ref("key"))) .MethodReturn(Ref("key")); }; return instance.Methods.AddMethod( typeof(object), "GenerateGroupKeySingle", CodegenNamedParam.From( typeof(EventBean[]), NAME_EPS, typeof(bool), ResultSetProcessorCodegenNames.NAME_ISNEWDATA), typeof(ResultSetProcessorUtil), classScope, code); }
private static void AssertExpressionOpt( string expected, ExprNode expression) { if (expected == null) { Assert.IsNull(expression); } else { Assert.AreEqual(expected, ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(expression)); } }
private static void LogFilterPlanExpr( StringBuilder buf, string name, ExprNode exprNode) { buf.Append(" -") .Append(name) .Append(": ") .Append(ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(exprNode)) .Append(FilterSpecCompiler.NEWLINE); }