private static FilterSpecParamForge MakeBooleanExprParam( ExprNode exprNode, FilterSpecCompilerArgs args) { bool hasSubselectFilterStream = DetermineSubselectFilterStream(exprNode); bool hasTableAccess = DetermineTableAccessFilterStream(exprNode); ExprNodeVariableVisitor visitor = new ExprNodeVariableVisitor(args.compileTimeServices.VariableCompileTimeResolver); exprNode.Accept(visitor); bool hasVariable = visitor.IsVariables; ExprFilterSpecLookupableForge lookupable = new ExprFilterSpecLookupableForge( PROPERTY_NAME_BOOLEAN_EXPRESSION, null, exprNode.Forge.EvaluationType, false); return new FilterSpecParamExprNodeForge( lookupable, FilterOperator.BOOLEAN_EXPRESSION, exprNode, args.taggedEventTypes, args.arrayEventTypes, args.streamTypeService, hasSubselectFilterStream, hasTableAccess, hasVariable, args.compileTimeServices); }
/// <summary> /// Ctor. /// </summary> /// <param name="lookupable">is the lookup-able</param> /// <param name="filterOperator">is expected to be the BOOLEAN_EXPR operator</param> /// <param name="exprNode">represents the boolean expression</param> /// <param name="taggedEventTypes">is null if the expression doesn't need other streams, or is filled with a ordered list of stream names and types</param> /// <param name="arrayEventTypes">is a map of name tags and event type per tag for repeat-expressions that generate an array of events</param> /// <param name="variableService">provides access to variables</param> /// <param name="tableService">The table service.</param> /// <param name="eventAdapterService">for creating event types and event beans</param> /// <param name="configurationInformation">The configuration information.</param> /// <param name="statementName">Name of the statement.</param> /// <param name="hasSubquery">if set to <c>true</c> [has subquery].</param> /// <param name="hasTableAccess">if set to <c>true</c> [has table access].</param> /// <exception cref="System.ArgumentException">Invalid filter operator for filter expression node</exception> /// <throws>IllegalArgumentException for illegal args</throws> public FilterSpecParamExprNode( FilterSpecLookupable lookupable, FilterOperator filterOperator, ExprNode exprNode, IDictionary <string, Pair <EventType, string> > taggedEventTypes, IDictionary <string, Pair <EventType, string> > arrayEventTypes, VariableService variableService, TableService tableService, EventAdapterService eventAdapterService, ConfigurationInformation configurationInformation, string statementName, bool hasSubquery, bool hasTableAccess) : base(lookupable, filterOperator) { if (filterOperator != FilterOperator.BOOLEAN_EXPRESSION) { throw new ArgumentException("Invalid filter operator for filter expression node"); } _exprNode = exprNode; _taggedEventTypes = taggedEventTypes; _arrayEventTypes = arrayEventTypes; _variableService = variableService; _tableService = tableService; _eventAdapterService = eventAdapterService; _useLargeThreadingProfile = configurationInformation.EngineDefaults.ExecutionConfig.ThreadingProfile == ConfigurationEngineDefaults.ThreadingProfile.LARGE; _hasFilterStreamSubquery = hasSubquery; _hasTableAccess = hasTableAccess; var visitor = new ExprNodeVariableVisitor(); exprNode.Accept(visitor); _hasVariable = visitor.HasVariables; }
public OutputConditionExpressionFactory( ExprNode whenExpressionNode, IList<OnTriggerSetAssignment> assignments, StatementContext statementContext, ExprNode andWhenTerminatedExpr, IList<OnTriggerSetAssignment> afterTerminateAssignments, bool isStartConditionOnCreation) { _whenExpressionNodeEval = whenExpressionNode.ExprEvaluator; _andWhenTerminatedExpressionNodeEval = andWhenTerminatedExpr != null ? andWhenTerminatedExpr.ExprEvaluator : null; _isStartConditionOnCreation = isStartConditionOnCreation; // determine if using variables var variableVisitor = new ExprNodeVariableVisitor(statementContext.VariableService); whenExpressionNode.Accept(variableVisitor); _variableNames = variableVisitor.VariableNames; // determine if using properties bool containsBuiltinProperties = ContainsBuiltinProperties(whenExpressionNode); if (!containsBuiltinProperties && assignments != null) { foreach (OnTriggerSetAssignment assignment in assignments) { if (ContainsBuiltinProperties(assignment.Expression)) { containsBuiltinProperties = true; } } } if (!containsBuiltinProperties && _andWhenTerminatedExpressionNodeEval != null) { containsBuiltinProperties = ContainsBuiltinProperties(andWhenTerminatedExpr); } if (!containsBuiltinProperties && afterTerminateAssignments != null) { foreach (OnTriggerSetAssignment assignment in afterTerminateAssignments) { if (ContainsBuiltinProperties(assignment.Expression)) { containsBuiltinProperties = true; } } } if (containsBuiltinProperties) { _builtinPropertiesEventType = GetBuiltInEventType(statementContext.EventAdapterService); } if (assignments != null) { _variableReadWritePackage = new VariableReadWritePackage( assignments, statementContext.VariableService, statementContext.EventAdapterService); } else { _variableReadWritePackage = null; } if (afterTerminateAssignments != null) { _variableReadWritePackageAfterTerminated = new VariableReadWritePackage( afterTerminateAssignments, statementContext.VariableService, statementContext.EventAdapterService); } else { _variableReadWritePackageAfterTerminated = null; } }
public OutputConditionExpressionForge( ExprNode whenExpressionNode, IList<OnTriggerSetAssignment> assignments, ExprNode andWhenTerminatedExpr, IList<OnTriggerSetAssignment> afterTerminateAssignments, bool isStartConditionOnCreation, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { whenExpressionNodeEval = whenExpressionNode; andWhenTerminatedExpressionNodeEval = andWhenTerminatedExpr; this.isStartConditionOnCreation = isStartConditionOnCreation; // determine if using variables var variableVisitor = new ExprNodeVariableVisitor(services.VariableCompileTimeResolver); whenExpressionNode.Accept(variableVisitor); variableNames = variableVisitor.VariableNames; // determine if using properties var containsBuiltinProperties = ContainsBuiltinProperties(whenExpressionNode); if (!containsBuiltinProperties && assignments != null) { foreach (var assignment in assignments) { if (ContainsBuiltinProperties(assignment.Expression)) { containsBuiltinProperties = true; } } } if (!containsBuiltinProperties && andWhenTerminatedExpressionNodeEval != null) { containsBuiltinProperties = ContainsBuiltinProperties(andWhenTerminatedExpr); } if (!containsBuiltinProperties && afterTerminateAssignments != null) { foreach (var assignment in afterTerminateAssignments) { if (ContainsBuiltinProperties(assignment.Expression)) { containsBuiltinProperties = true; } } } isUsingBuiltinProperties = containsBuiltinProperties; if (assignments != null && !assignments.IsEmpty()) { variableReadWritePackage = new VariableReadWritePackageForge( assignments, statementRawInfo.StatementName, services); } else { variableReadWritePackage = null; } if (afterTerminateAssignments != null) { variableReadWritePackageAfterTerminated = new VariableReadWritePackageForge( afterTerminateAssignments, statementRawInfo.StatementName, services); } else { variableReadWritePackageAfterTerminated = null; } }
public void Attach(EventType parentEventType, StatementContext statementContext, ViewFactory optionalParentFactory, IList <ViewFactory> parentViewFactories) { _eventType = parentEventType; // define built-in fields var builtinTypeDef = ExpressionViewOAFieldEnumExtensions.AsMapOfTypes(_eventType); _builtinMapType = statementContext.EventAdapterService.CreateAnonymousObjectArrayType( statementContext.StatementId + "_exprview", builtinTypeDef); StreamTypeService streamTypeService = new StreamTypeServiceImpl(new EventType[] { _eventType, _builtinMapType }, new String[2], new bool[2], statementContext.EngineURI, false); // validate expression ExpiryExpression = ViewFactorySupport.ValidateExpr(ViewName, statementContext, ExpiryExpression, streamTypeService, 0); var summaryVisitor = new ExprNodeSummaryVisitor(); ExpiryExpression.Accept(summaryVisitor); if (summaryVisitor.HasSubselect || summaryVisitor.HasStreamSelect || summaryVisitor.HasPreviousPrior) { throw new ViewParameterException("Invalid expiry expression: Sub-select, previous or prior functions are not supported in this context"); } var returnType = ExpiryExpression.ExprEvaluator.ReturnType; if (returnType.GetBoxedType() != typeof(bool?)) { throw new ViewParameterException("Invalid return value for expiry expression, expected a bool return value but received " + returnType.GetParameterAsString()); } // determine variables used, if any var visitor = new ExprNodeVariableVisitor(); ExpiryExpression.Accept(visitor); VariableNames = visitor.VariableNames; // determine aggregation nodes, if any var aggregateNodes = new List <ExprAggregateNode>(); ExprAggregateNodeUtil.GetAggregatesBottomUp(ExpiryExpression, aggregateNodes); if (aggregateNodes.IsNotEmpty()) { try { AggregationServiceFactoryDesc = AggregationServiceFactoryFactory.GetService( Collections.GetEmptyList <ExprAggregateNode>(), Collections.GetEmptyMap <ExprNode, String>(), Collections.GetEmptyList <ExprDeclaredNode>(), null, aggregateNodes, Collections.GetEmptyList <ExprAggregateNode>(), Collections.GetEmptyList <ExprAggregateNodeGroupKey>(), false, statementContext.Annotations, statementContext.VariableService, false, false, null, null, AggregationServiceFactoryServiceImpl.DEFAULT_FACTORY, streamTypeService.EventTypes, statementContext.MethodResolutionService, null, statementContext.ContextName, null, null); } catch (ExprValidationException ex) { throw new ViewParameterException(ex.Message, ex); } } }
public VariableReadWritePackageForge( IList <OnTriggerSetAssignment> assignments, string statementName, StatementCompileTimeServices services) { _variables = new VariableMetaData[assignments.Count]; _mustCoerce = new bool[assignments.Count]; _writers = new VariableTriggerWriteForge[assignments.Count]; _variableTypes = new Dictionary <string, object>(); IDictionary <EventTypeSPI, CopyMethodDesc> eventTypeWrittenProps = new Dictionary <EventTypeSPI, CopyMethodDesc>(); var count = 0; IList <ExprAssignment> assignmentList = new List <ExprAssignment>(); foreach (var spec in assignments) { var assignmentDesc = spec.Validated; assignmentList.Add(assignmentDesc); try { if (assignmentDesc is ExprAssignmentStraight) { var assignment = (ExprAssignmentStraight)assignmentDesc; var identAssignment = assignment.Lhs; var variableName = identAssignment.Ident; var variableMetadata = services.VariableCompileTimeResolver.Resolve(variableName); if (variableMetadata == null) { throw new ExprValidationException("Variable by name '" + variableName + "' has not been created or configured"); } _variables[count] = variableMetadata; var expressionType = assignment.Rhs.Forge.EvaluationType; if (assignment.Lhs is ExprAssignmentLHSIdent) { // determine types if (variableMetadata.EventType != null) { if ((expressionType != null) && (!TypeHelper.IsSubclassOrImplementsInterface(expressionType, variableMetadata.EventType.UnderlyingType))) { throw new ExprValidationException( "Variable '" + variableName + "' of declared event type '" + variableMetadata.EventType.Name + "' underlying type '" + variableMetadata.EventType.UnderlyingType.Name + "' cannot be assigned a value of type '" + expressionType.Name + "'"); } _variableTypes.Put(variableName, variableMetadata.EventType.UnderlyingType); } else { var variableType = variableMetadata.Type; _variableTypes.Put(variableName, variableType); // determine if the expression type can be assigned if (variableType != typeof(object)) { if ((expressionType.GetBoxedType() != variableType.GetBoxedType()) && (expressionType != null)) { if ((!TypeHelper.IsNumeric(variableType)) || (!TypeHelper.IsNumeric(expressionType))) { throw new ExprValidationException(VariableUtil.GetAssigmentExMessage(variableName, variableType, expressionType)); } if (!(TypeHelper.CanCoerce(expressionType, variableType))) { throw new ExprValidationException(VariableUtil.GetAssigmentExMessage(variableName, variableType, expressionType)); } _mustCoerce[count] = true; } } } } else if (assignment.Lhs is ExprAssignmentLHSIdentWSubprop) { var subpropAssignment = (ExprAssignmentLHSIdentWSubprop)assignment.Lhs; var subPropertyName = subpropAssignment.SubpropertyName; if (variableMetadata.EventType == null) { throw new ExprValidationException( "Variable by name '" + variableName + "' does not have a property named '" + subPropertyName + "'"); } var type = variableMetadata.EventType; if (!(type is EventTypeSPI)) { throw new ExprValidationException("Variable by name '" + variableName + "' event type '" + type.Name + "' not writable"); } var spi = (EventTypeSPI)type; var writer = spi.GetWriter(subPropertyName); var getter = spi.GetGetterSPI(subPropertyName); var getterType = spi.GetPropertyType(subPropertyName); if (writer == null) { throw new ExprValidationException( "Variable by name '" + variableName + "' the property '" + subPropertyName + "' is not writable"); } var fullVariableName = variableName + "." + subPropertyName; _variableTypes.Put(fullVariableName, spi.GetPropertyType(subPropertyName)); var writtenProps = eventTypeWrittenProps.Get(spi); if (writtenProps == null) { writtenProps = new CopyMethodDesc(variableName, new List <string>()); eventTypeWrittenProps.Put(spi, writtenProps); } writtenProps.PropertiesCopied.Add(subPropertyName); _writers[count] = new VariableTriggerWriteDescForge( spi, variableName, writer, getter, getterType, assignment.Rhs.Forge.EvaluationType); } else if (assignment.Lhs is ExprAssignmentLHSArrayElement) { var arrayAssign = (ExprAssignmentLHSArrayElement)assignment.Lhs; var variableType = variableMetadata.Type; if (!variableType.IsArray) { throw new ExprValidationException("Variable '" + variableMetadata.VariableName + "' is not an array"); } TypeWidenerSPI widener; try { widener = TypeWidenerFactory.GetCheckPropertyAssignType( ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(assignment.Rhs), expressionType, variableType.GetElementType(), variableMetadata.VariableName, false, null, statementName); } catch (TypeWidenerException ex) { throw new ExprValidationException(ex.Message, ex); } _writers[count] = new VariableTriggerWriteArrayElementForge(variableName, arrayAssign.IndexExpression.Forge, widener); } else { throw new IllegalStateException("Unrecognized left hand side assignment " + assignment.Lhs); } } else if (assignmentDesc is ExprAssignmentCurly) { var curly = (ExprAssignmentCurly)assignmentDesc; if (curly.Expression is ExprVariableNode) { throw new ExprValidationException("Missing variable assignment expression in assignment number " + count); } var variableVisitor = new ExprNodeVariableVisitor(services.VariableCompileTimeResolver); curly.Expression.Accept(variableVisitor); if (variableVisitor.VariableNames == null || variableVisitor.VariableNames.Count != 1) { throw new ExprValidationException("Assignment expression must receive a single variable value"); } var variable = variableVisitor.VariableNames.First(); _variables[count] = variable.Value; _writers[count] = new VariableTriggerWriteCurlyForge(variable.Key, curly.Expression.Forge); } else { throw new IllegalStateException("Unrecognized assignment expression " + assignmentDesc); } if (_variables[count].IsConstant) { throw new ExprValidationException("Variable by name '" + _variables[count].VariableName + "' is declared constant and may not be set"); } count++; } catch (ExprValidationException ex) { throw new ExprValidationException( "Failed to validate assignment expression '" + ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(assignmentDesc.OriginalExpression) + "': " + ex.Message, ex); } } _assignments = assignmentList.ToArray(); if (eventTypeWrittenProps.IsEmpty()) { _copyMethods = EmptyDictionary <EventTypeSPI, EventBeanCopyMethodForge> .Instance; return; } _copyMethods = new Dictionary <EventTypeSPI, EventBeanCopyMethodForge>(); foreach (var entry in eventTypeWrittenProps) { var propsWritten = entry.Value.PropertiesCopied; var props = propsWritten.ToArray(); var copyMethod = entry.Key.GetCopyMethodForge(props); if (copyMethod == null) { throw new ExprValidationException( "Variable '" + entry.Value.VariableName + "' of declared type " + entry.Key.UnderlyingType.CleanName() + "' cannot be assigned to"); } _copyMethods.Put(entry.Key, copyMethod); } }