Exemplo n.º 1
0
        public static Pair <ExprTableAccessNode, ExprDotNode> CheckTableNameGetExprForSubproperty(
            TableService tableService,
            string tableName,
            string subproperty)
        {
            var metadata = tableService.GetTableMetadata(tableName);

            if (metadata == null)
            {
                return(null);
            }

            var index = ASTUtil.UnescapedIndexOfDot(subproperty);

            if (index == -1)
            {
                if (metadata.KeyTypes.Length > 0)
                {
                    return(null);
                }
                var tableNodeX = new ExprTableAccessNodeSubprop(tableName, subproperty);
                return(new Pair <ExprTableAccessNode, ExprDotNode>(tableNodeX, null));
            }

            // we have a nested subproperty such as "tablename.subproperty.abc"
            var chainedSpecs = new List <ExprChainedSpec>(1);

            chainedSpecs.Add(new ExprChainedSpec(subproperty.Substring(index + 1), Collections.GetEmptyList <ExprNode>(), true));
            var tableNode = new ExprTableAccessNodeSubprop(tableName, subproperty.Substring(0, index));
            var dotNode   = new ExprDotNodeImpl(chainedSpecs, false, false);

            dotNode.AddChildNode(tableNode);
            return(new Pair <ExprTableAccessNode, ExprDotNode>(tableNode, dotNode));
        }
Exemplo n.º 2
0
        public static Pair <ExprTableAccessNode, ExprDotNode> MapPropertyToTableNested(
            TableCompileTimeResolver resolver,
            string stream,
            string subproperty)
        {
            var table          = resolver.Resolve(stream);
            int?indexIfIndexed = null;

            if (table == null)
            {
                // try indexed property
                var pair = MapPropertyToTable(stream, resolver);
                if (pair == null)
                {
                    return(null);
                }

                table          = pair.Second;
                indexIfIndexed = pair.First.Index;
            }

            if (table.IsKeyed && indexIfIndexed == null)
            {
                return(null);
            }

            if (!table.IsKeyed && indexIfIndexed != null)
            {
                return(null);
            }

            var index = StringValue.UnescapedIndexOfDot(subproperty);

            if (index == -1)
            {
                var tableNodeX = new ExprTableAccessNodeSubprop(table.TableName, subproperty);
                if (indexIfIndexed != null)
                {
                    tableNodeX.AddChildNode(new ExprConstantNodeImpl(indexIfIndexed));
                }

                return(new Pair <ExprTableAccessNode, ExprDotNode>(tableNodeX, null));
            }

            // we have a nested subproperty such as "tablename.subproperty.abc"
            IList <Chainable> chainedSpecs = new List <Chainable>(1);

            chainedSpecs.Add(new ChainableName(subproperty.Substring(index + 1)));
            var tableNode = new ExprTableAccessNodeSubprop(table.TableName, subproperty.Substring(0, index));

            if (indexIfIndexed != null)
            {
                tableNode.AddChildNode(new ExprConstantNodeImpl(indexIfIndexed));
            }

            ExprDotNode dotNode = new ExprDotNodeImpl(chainedSpecs, false, false);

            dotNode.AddChildNode(tableNode);
            return(new Pair <ExprTableAccessNode, ExprDotNode>(tableNode, dotNode));
        }
Exemplo n.º 3
0
 public SettingsApplicationDotMethodPointInsideRectangle(
     ExprDotNodeImpl parent,
     string lhsName,
     ExprNode[] lhs,
     string dotMethodName,
     string rhsName,
     ExprNode[] rhs,
     ExprNode[] indexNamedParameter)
     : base(parent, lhsName, lhs, dotMethodName, rhsName, rhs, indexNamedParameter)
 {
 }
 public SettingsApplicationDotMethodBase(
     ExprDotNodeImpl parent,
     string lhsName,
     ExprNode[] lhs,
     string dotMethodName,
     string rhsName,
     ExprNode[] rhs,
     ExprNode[] indexNamedParameter)
 {
     this.parent = parent;
     LhsName = lhsName;
     Lhs = lhs;
     DotMethodName = dotMethodName;
     RhsName = rhsName;
     Rhs = rhs;
     this.indexNamedParameter = indexNamedParameter;
 }
Exemplo n.º 5
0
        public static ExprNode ProcessDot(
            bool useChainAsIs,
            bool resolveObjects,
            IList <Chainable> chain,
            StatementSpecMapContext mapContext)
        {
            if (chain.IsEmpty())
            {
                throw new ArgumentException("Empty chain");
            }

            Func <IList <Chainable>, ExprDotNodeImpl> dotNodeFunction = chainSpec => {
                var dotNode = new ExprDotNodeImpl(
                    chainSpec,
                    mapContext.Configuration.Compiler.Expression.IsDuckTyping,
                    mapContext.Configuration.Compiler.Expression.IsUdfCache);
                // add any variables that are referenced
                var variable = dotNode.IsVariableOpGetName(mapContext.VariableCompileTimeResolver);
                if (variable != null)
                {
                    mapContext.VariableNames.Add(variable.VariableName);
                }

                return(dotNode);
            };

            // Resolve objects if required
            if (resolveObjects)
            {
                var resolved = ResolveObject(chain, mapContext, dotNodeFunction);
                if (resolved != null)
                {
                    return(resolved);
                }
            }

            // Check if we are dealing with a plain event property expression, i.e. one without any eventstream-dependent expression
            var plain = DeterminePlainProperty(chain);

            if (plain)
            {
                return(HandlePlain(chain, dotNodeFunction, useChainAsIs));
            }

            return(HandleNonPlain(chain, dotNodeFunction));
        }
 public PointIntersectsRectangleForge(
     ExprDotNodeImpl parent,
     ExprForge pxEval,
     ExprForge pyEval,
     ExprForge xEval,
     ExprForge yEval,
     ExprForge widthEval,
     ExprForge heightEval)
 {
     this.parent     = parent;
     this.pxEval     = pxEval;
     this.pyEval     = pyEval;
     this.xEval      = xEval;
     this.yEval      = yEval;
     this.widthEval  = widthEval;
     this.heightEval = heightEval;
 }
 public RectangleIntersectsRectangleForge(
     ExprDotNodeImpl parent,
     ExprForge meXEval,
     ExprForge meYEval,
     ExprForge meWidthEval,
     ExprForge meHeightEval,
     ExprForge otherXEval,
     ExprForge otherYEval,
     ExprForge otherWidthEval,
     ExprForge otherHeightEval)
 {
     this.parent = parent;
     this.meXEval = meXEval;
     this.meYEval = meYEval;
     this.meWidthEval = meWidthEval;
     this.meHeightEval = meHeightEval;
     this.otherXEval = otherXEval;
     this.otherYEval = otherYEval;
     this.otherWidthEval = otherWidthEval;
     this.otherHeightEval = otherHeightEval;
 }
Exemplo n.º 8
0
        public static void HandleLibFunc(
            CommonTokenStream tokenStream,
            EsperEPL2GrammarParser.LibFunctionContext ctx,
            ConfigurationInformation configurationInformation,
            EngineImportService engineImportService,
            IDictionary <ITree, ExprNode> astExprNodeMap,
            LazyAllocatedMap <ConfigurationPlugInAggregationMultiFunction, PlugInAggregationMultiFunctionFactory> plugInAggregations,
            string engineURI,
            ExpressionDeclDesc expressionDeclarations,
            ExprDeclaredService exprDeclaredService,
            IList <ExpressionScriptProvided> scriptExpressions,
            ContextDescriptor contextDescriptor,
            TableService tableService,
            StatementSpecRaw statementSpec,
            VariableService variableService)
        {
            var model    = GetModel(ctx, tokenStream);
            var duckType = configurationInformation.EngineDefaults.Expression.IsDuckTyping;
            var udfCache = configurationInformation.EngineDefaults.Expression.IsUdfCache;

            // handle "some.Xyz(...)" or "some.other.Xyz(...)"
            if (model.ChainElements.Count == 1 &&
                model.OptionalClassIdent != null &&
                ASTTableExprHelper.CheckTableNameGetExprForProperty(tableService, model.OptionalClassIdent) == null)
            {
                var chainSpec = GetLibFunctionChainSpec(model.ChainElements[0], astExprNodeMap);

                var declaredNodeX = ExprDeclaredHelper.GetExistsDeclaredExpr(
                    model.OptionalClassIdent, Collections.GetEmptyList <ExprNode>(), expressionDeclarations.Expressions,
                    exprDeclaredService, contextDescriptor);
                if (declaredNodeX != null)
                {
                    var exprNode = new ExprDotNodeImpl(Collections.SingletonList(chainSpec), duckType, udfCache);
                    exprNode.AddChildNode(declaredNodeX);
                    ASTExprHelper.ExprCollectAddSubNodesAddParentNode(exprNode, ctx, astExprNodeMap);
                    return;
                }

                var chainX = new List <ExprChainedSpec>(2);
                chainX.Add(new ExprChainedSpec(model.OptionalClassIdent, Collections.GetEmptyList <ExprNode>(), true));
                chainX.Add(chainSpec);
                var dotNodeX = new ExprDotNodeImpl(
                    chainX, configurationInformation.EngineDefaults.Expression.IsDuckTyping,
                    configurationInformation.EngineDefaults.Expression.IsUdfCache);
                if (dotNodeX.IsVariableOpGetName(variableService) != null)
                {
                    statementSpec.HasVariables = true;
                }
                ASTExprHelper.ExprCollectAddSubNodesAddParentNode(dotNodeX, ctx, astExprNodeMap);
                return;
            }

            // try additional built-in single-row function
            var singleRowExtNode =
                engineImportService.ResolveSingleRowExtendedBuiltin(model.ChainElements[0].FuncName);

            if (singleRowExtNode != null)
            {
                if (model.ChainElements.Count == 1)
                {
                    ASTExprHelper.ExprCollectAddSubNodesAddParentNode(singleRowExtNode, ctx, astExprNodeMap);
                    return;
                }
                var spec             = new List <ExprChainedSpec>();
                var firstArgs        = model.ChainElements[0].Args;
                var childExpressions = GetExprNodesLibFunc(firstArgs, astExprNodeMap);
                singleRowExtNode.AddChildNodes(childExpressions);
                AddChainRemainderFromOffset(model.ChainElements, 1, spec, astExprNodeMap);
                var dotNodeX = new ExprDotNodeImpl(
                    spec, configurationInformation.EngineDefaults.Expression.IsDuckTyping,
                    configurationInformation.EngineDefaults.Expression.IsUdfCache);
                dotNodeX.AddChildNode(singleRowExtNode);
                ASTExprHelper.ExprCollectAddSubNodesAddParentNode(dotNodeX, ctx, astExprNodeMap);
                return;
            }

            // try plug-in single-row function
            try
            {
                var firstFunctionX          = model.ChainElements[0].FuncName;
                var firstFunctionIsProperty = !model.ChainElements[0].HasLeftParen;
                var classMethodPair         =
                    engineImportService.ResolveSingleRow(firstFunctionX);
                var spec             = new List <ExprChainedSpec>();
                var firstArgs        = model.ChainElements[0].Args;
                var childExpressions = GetExprNodesLibFunc(firstArgs, astExprNodeMap);
                spec.Add(
                    new ExprChainedSpec(classMethodPair.Second.MethodName, childExpressions, firstFunctionIsProperty));
                AddChainRemainderFromOffset(model.ChainElements, 1, spec, astExprNodeMap);
                var plugin = new ExprPlugInSingleRowNode(
                    firstFunctionX, classMethodPair.First, spec, classMethodPair.Second);
                ASTExprHelper.ExprCollectAddSubNodesAddParentNode(plugin, ctx, astExprNodeMap);
                return;
            }
            catch (EngineImportUndefinedException)
            {
                // Not an single-row function
            }
            catch (EngineImportException e)
            {
                throw new IllegalStateException("Error resolving single-row function: " + e.Message, e);
            }

            // special case for min,max
            var firstFunction = model.ChainElements[0].FuncName;

            if ((firstFunction.ToLowerInvariant().Equals("max")) || (firstFunction.ToLowerInvariant().Equals("min")) ||
                (firstFunction.ToLowerInvariant().Equals("fmax")) || (firstFunction.ToLowerInvariant().Equals("fmin")))
            {
                var firstArgs = model.ChainElements[0].Args;
                HandleMinMax(firstFunction, firstArgs, astExprNodeMap);
                return;
            }

            // obtain chain with actual expressions
            IList <ExprChainedSpec> chain = new List <ExprChainedSpec>();

            AddChainRemainderFromOffset(model.ChainElements, 0, chain, astExprNodeMap);

            // add chain element for class INFO, if any
            var distinct = model.ChainElements[0].Args != null && model.ChainElements[0].Args.DISTINCT() != null;

            if (model.OptionalClassIdent != null)
            {
                chain.Insert(
                    0, new ExprChainedSpec(model.OptionalClassIdent, Collections.GetEmptyList <ExprNode>(), true));
                distinct = false;
            }
            firstFunction = chain[0].Name;

            // try plug-in aggregation function
            var aggregationNode = ASTAggregationHelper.TryResolveAsAggregation(
                engineImportService, distinct, firstFunction, plugInAggregations, engineURI);

            if (aggregationNode != null)
            {
                var firstSpec = chain.DeleteAt(0);
                aggregationNode.AddChildNodes(firstSpec.Parameters);
                ExprNode exprNode;
                if (chain.IsEmpty())
                {
                    exprNode = aggregationNode;
                }
                else
                {
                    exprNode = new ExprDotNodeImpl(chain, duckType, udfCache);
                    exprNode.AddChildNode(aggregationNode);
                }
                ASTExprHelper.ExprCollectAddSubNodesAddParentNode(exprNode, ctx, astExprNodeMap);
                return;
            }

            // try declared or alias expression
            var declaredNode = ExprDeclaredHelper.GetExistsDeclaredExpr(
                firstFunction, chain[0].Parameters, expressionDeclarations.Expressions, exprDeclaredService,
                contextDescriptor);

            if (declaredNode != null)
            {
                chain.RemoveAt(0);
                ExprNode exprNode;
                if (chain.IsEmpty())
                {
                    exprNode = declaredNode;
                }
                else
                {
                    exprNode = new ExprDotNodeImpl(chain, duckType, udfCache);
                    exprNode.AddChildNode(declaredNode);
                }
                ASTExprHelper.ExprCollectAddSubNodesAddParentNode(exprNode, ctx, astExprNodeMap);
                return;
            }

            // try script
            var scriptNode =
                ExprDeclaredHelper.GetExistsScript(
                    configurationInformation.EngineDefaults.Scripts.DefaultDialect, chain[0].Name, chain[0].Parameters,
                    scriptExpressions, exprDeclaredService);

            if (scriptNode != null)
            {
                chain.RemoveAt(0);
                ExprNode exprNode;
                if (chain.IsEmpty())
                {
                    exprNode = scriptNode;
                }
                else
                {
                    exprNode = new ExprDotNodeImpl(chain, duckType, udfCache);
                    exprNode.AddChildNode(scriptNode);
                }
                ASTExprHelper.ExprCollectAddSubNodesAddParentNode(exprNode, ctx, astExprNodeMap);
                return;
            }

            // try table
            var tableInfo = ASTTableExprHelper.CheckTableNameGetLibFunc(
                tableService, engineImportService, plugInAggregations, engineURI, firstFunction, chain);

            if (tableInfo != null)
            {
                ASTTableExprHelper.AddTableExpressionReference(statementSpec, tableInfo.First);
                chain = tableInfo.Second;
                ExprNode exprNode;
                if (chain.IsEmpty())
                {
                    exprNode = tableInfo.First;
                }
                else
                {
                    exprNode = new ExprDotNodeImpl(chain, duckType, udfCache);
                    exprNode.AddChildNode(tableInfo.First);
                }
                ASTExprHelper.ExprCollectAddSubNodesAddParentNode(exprNode, ctx, astExprNodeMap);
                return;
            }

            // Could be a mapped property with an expression-parameter "Mapped(expr)" or array property with an expression-parameter "Array(expr)".
            ExprDotNode dotNode;

            if (chain.Count == 1)
            {
                dotNode = new ExprDotNodeImpl(chain, false, false);
            }
            else
            {
                dotNode = new ExprDotNodeImpl(chain, duckType, udfCache);
            }
            ASTExprHelper.ExprCollectAddSubNodesAddParentNode(dotNode, ctx, astExprNodeMap);
        }
Exemplo n.º 9
0
        // Since static method calls such as "Class.method('a')" and mapped properties "Stream.property('key')"
        // look the same, however as the validation could not resolve "Stream.property('key')" before calling this method,
        // this method tries to resolve the mapped property as a static method.
        // Assumes that this is an ExprIdentNode.
        private static ExprNode ResolveStaticMethodOrField(
            ExprIdentNode identNode,
            ExprValidationException propertyException,
            ExprValidationContext validationContext)
        {
            // Reconstruct the original string
            StringBuilder mappedProperty = new StringBuilder(identNode.UnresolvedPropertyName);
            if (identNode.StreamOrPropertyName != null) {
                mappedProperty.Insert(0, identNode.StreamOrPropertyName + '.');
            }

            // Parse the mapped property format into a class name, method and single string parameter
            MappedPropertyParseResult parse = ParseMappedProperty(mappedProperty.ToString());
            if (parse == null) {
                ExprConstantNode constNode = ResolveIdentAsEnumConst(
                    mappedProperty.ToString(),
                    validationContext.ImportService);
                if (constNode == null) {
                    throw propertyException;
                }
                else {
                    return constNode;
                }
            }

            // If there is a class name, assume a static method is possible.
            if (parse.ClassName != null) {
                IList<ExprNode> parameters =
                    Collections.SingletonList((ExprNode) new ExprConstantNodeImpl(parse.ArgString));
                IList<ExprChainedSpec> chain = new List<ExprChainedSpec>();
                chain.Add(new ExprChainedSpec(parse.ClassName, Collections.GetEmptyList<ExprNode>(), false));
                chain.Add(new ExprChainedSpec(parse.MethodName, parameters, false));
                ConfigurationCompilerExpression exprConfig =
                    validationContext.StatementCompileTimeService.Configuration.Compiler.Expression;
                ExprNode result = new ExprDotNodeImpl(chain, exprConfig.IsDuckTyping, exprConfig.IsUdfCache);

                // Validate
                try {
                    result.Validate(validationContext);
                }
                catch (ExprValidationException e) {
                    throw new ExprValidationException(
                        $"Failed to resolve enumeration method, date-time method or mapped property '{mappedProperty}': {e.Message}",
                        e);
                }

                return result;
            }

            // There is no class name, try a single-row function
            string functionName = parse.MethodName;
            try {
                Pair<Type, ImportSingleRowDesc> classMethodPair =
                    validationContext.ImportService.ResolveSingleRow(functionName);
                IList<ExprNode> parameters =
                    Collections.SingletonList((ExprNode) new ExprConstantNodeImpl(parse.ArgString));
                IList<ExprChainedSpec> chain = Collections.SingletonList(
                    new ExprChainedSpec(classMethodPair.Second.MethodName, parameters, false));
                ExprNode result = new ExprPlugInSingleRowNode(
                    functionName,
                    classMethodPair.First,
                    chain,
                    classMethodPair.Second);

                // Validate
                try {
                    result.Validate(validationContext);
                }
                catch (EPException) {
                    throw;
                }
                catch (Exception ex) {
                    throw new ExprValidationException(
                        "Plug-in aggregation function '" + parse.MethodName + "' failed validation: " + ex.Message);
                }

                return result;
            }
            catch (ImportUndefinedException) {
                // Not an single-row function
            }
            catch (ImportException e) {
                throw new IllegalStateException("Error resolving single-row function: " + e.Message, e);
            }

            // Try an aggregation function factory
            try {
                AggregationFunctionForge aggregationForge =
                    validationContext.ImportService.ResolveAggregationFunction(parse.MethodName);
                ExprNode result = new ExprPlugInAggNode(false, aggregationForge, parse.MethodName);
                result.AddChildNode(new ExprConstantNodeImpl(parse.ArgString));

                // Validate
                try {
                    result.Validate(validationContext);
                }
                catch (EPException) {
                    throw;
                }
                catch (Exception e) {
                    throw new ExprValidationException(
                        "Plug-in aggregation function '" + parse.MethodName + "' failed validation: " + e.Message);
                }

                return result;
            }
            catch (ImportUndefinedException) {
                // Not an aggregation function
            }
            catch (ImportException e) {
                throw new IllegalStateException("Error resolving aggregation: " + e.Message, e);
            }

            // absolutely cannot be resolved
            throw propertyException;
        }