private AggSvcGroupByReclaimAgedEvalFuncFactory GetEvaluationFunction(VariableService variableService, String hintValue, String optionalContextName)
        {
            VariableMetaData variableMetaData = variableService.GetVariableMetaData(hintValue);

            if (variableMetaData != null)
            {
                if (!variableMetaData.VariableType.IsNumeric())
                {
                    throw new ExprValidationException("Variable type of variable '" + variableMetaData.VariableName + "' is not numeric");
                }
                String message = VariableServiceUtil.CheckVariableContextName(optionalContextName, variableMetaData);
                if (message != null)
                {
                    throw new ExprValidationException(message);
                }
                return(new ProxyAggSvcGroupByReclaimAgedEvalFuncFactory
                {
                    ProcMake = agentInstanceContext =>
                    {
                        VariableReader reader = variableService.GetReader(
                            variableMetaData.VariableName, agentInstanceContext.AgentInstanceId);
                        return new AggSvcGroupByReclaimAgedEvalFuncVariable(reader);
                    }
                });
            }
            else
            {
                double valueDouble;
                try {
                    valueDouble = DoubleValue.ParseString(hintValue);
                }
                catch (Exception) {
                    throw new ExprValidationException("Failed to parse hint parameter value '" + hintValue + "' as a double-typed seconds value or variable name");
                }
                if (valueDouble <= 0)
                {
                    throw new ExprValidationException("Hint parameter value '" + hintValue + "' is an invalid value, expecting a double-typed seconds value or variable name");
                }
                return(new ProxyAggSvcGroupByReclaimAgedEvalFuncFactory
                {
                    ProcMake = agentInstanceContext => new AggSvcGroupByReclaimAgedEvalFuncConstant(valueDouble)
                });
            }
        }
Пример #2
0
        public static ExprNode ResolvePropertyOrVariableIdentifier(String identifier, VariableService variableService, StatementSpecRaw spec)
        {
            var metaData = variableService.GetVariableMetaData(identifier);

            if (metaData != null)
            {
                var exprNode = new ExprVariableNodeImpl(metaData, null);
                spec.HasVariables = true;
                AddVariableReference(spec, metaData.VariableName);
                var message = VariableServiceUtil.CheckVariableContextName(spec.OptionalContextName, metaData);
                if (message != null)
                {
                    throw ASTWalkException.From(message);
                }
                return(exprNode);
            }
            else
            {
                return(new ExprIdentNodeImpl(identifier));
            }
        }
Пример #3
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="rowLimitSpec">specification for row limit, or null if no row limit is defined</param>
        /// <param name="variableService">for retrieving variable state for use with row limiting</param>
        /// <param name="optionalContextName">Name of the optional context.</param>
        /// <exception cref="ExprValidationException">
        /// Limit clause variable by name '" + rowLimitSpec.NumRowsVariable + "' has not been declared
        /// or
        /// or
        /// Limit clause requires a variable of numeric type
        /// or
        /// Limit clause variable by name '" + rowLimitSpec.OptionalOffsetVariable + "' has not been declared
        /// or
        /// or
        /// Limit clause requires a variable of numeric type
        /// or
        /// Limit clause requires a positive offset
        /// </exception>
        /// <throws>com.espertech.esper.epl.expression.core.ExprValidationException if row limit specification validation fails</throws>
        public RowLimitProcessorFactory(RowLimitSpec rowLimitSpec, VariableService variableService, string optionalContextName)
        {
            if (rowLimitSpec.NumRowsVariable != null)
            {
                _numRowsVariableMetaData = variableService.GetVariableMetaData(rowLimitSpec.NumRowsVariable);
                if (_numRowsVariableMetaData == null)
                {
                    throw new ExprValidationException("Limit clause variable by name '" + rowLimitSpec.NumRowsVariable + "' has not been declared");
                }
                string message = VariableServiceUtil.CheckVariableContextName(optionalContextName, _numRowsVariableMetaData);
                if (message != null)
                {
                    throw new ExprValidationException(message);
                }
                if (!TypeHelper.IsNumeric(_numRowsVariableMetaData.VariableType))
                {
                    throw new ExprValidationException("Limit clause requires a variable of numeric type");
                }
            }
            else
            {
                _numRowsVariableMetaData = null;
                _currentRowLimit         = rowLimitSpec.NumRows.GetValueOrDefault();

                if (_currentRowLimit < 0)
                {
                    _currentRowLimit = int.MaxValue;
                }
            }

            if (rowLimitSpec.OptionalOffsetVariable != null)
            {
                _offsetVariableMetaData = variableService.GetVariableMetaData(rowLimitSpec.OptionalOffsetVariable);
                if (_offsetVariableMetaData == null)
                {
                    throw new ExprValidationException("Limit clause variable by name '" + rowLimitSpec.OptionalOffsetVariable + "' has not been declared");
                }
                string message = VariableServiceUtil.CheckVariableContextName(optionalContextName, _offsetVariableMetaData);
                if (message != null)
                {
                    throw new ExprValidationException(message);
                }
                if (!TypeHelper.IsNumeric(_offsetVariableMetaData.VariableType))
                {
                    throw new ExprValidationException("Limit clause requires a variable of numeric type");
                }
            }
            else
            {
                _offsetVariableMetaData = null;
                if (rowLimitSpec.OptionalOffset != null)
                {
                    _currentOffset = rowLimitSpec.OptionalOffset.GetValueOrDefault();

                    if (_currentOffset <= 0)
                    {
                        throw new ExprValidationException("Limit clause requires a positive offset");
                    }
                }
                else
                {
                    _currentOffset = 0;
                }
            }
        }
Пример #4
0
        public static OutputConditionFactory CreateCondition(
            OutputLimitSpec outputLimitSpec,
            StatementContext statementContext,
            bool isGrouped,
            bool isWithHavingClause,
            bool isStartConditionOnCreation,
            ResultSetProcessorHelperFactory resultSetProcessorHelperFactory)
        {
            if (outputLimitSpec == null)
            {
                return new OutputConditionNullFactory();
            }

            // Check if a variable is present
            VariableMetaData variableMetaData = null;
            if (outputLimitSpec.VariableName != null)
            {
                variableMetaData = statementContext.VariableService.GetVariableMetaData(outputLimitSpec.VariableName);
                if (variableMetaData == null)
                {
                    throw new ExprValidationException(
                        "Variable named '" + outputLimitSpec.VariableName + "' has not been declared");
                }
                string message = VariableServiceUtil.CheckVariableContextName(
                    statementContext.ContextDescriptor, variableMetaData);
                if (message != null)
                {
                    throw new ExprValidationException(message);
                }
            }

            if (outputLimitSpec.DisplayLimit == OutputLimitLimitType.FIRST && isGrouped)
            {
                return new OutputConditionNullFactory();
            }

            if (outputLimitSpec.RateType == OutputLimitRateType.CRONTAB)
            {
                return resultSetProcessorHelperFactory.MakeOutputConditionCrontab(
                    outputLimitSpec.CrontabAtSchedule, statementContext, isStartConditionOnCreation);
            }
            else if (outputLimitSpec.RateType == OutputLimitRateType.WHEN_EXPRESSION)
            {
                return resultSetProcessorHelperFactory.MakeOutputConditionExpression(
                    outputLimitSpec.WhenExpressionNode, outputLimitSpec.ThenExpressions, statementContext,
                    outputLimitSpec.AndAfterTerminateExpr, outputLimitSpec.AndAfterTerminateThenExpressions,
                    isStartConditionOnCreation);
            }
            else if (outputLimitSpec.RateType == OutputLimitRateType.EVENTS)
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug(".createCondition creating OutputConditionCount with event rate " + outputLimitSpec);
                }

                if ((variableMetaData != null) && (!variableMetaData.VariableType.IsNumericNonFP()))
                {
                    throw new ArgumentException(
                        "Variable named '" + outputLimitSpec.VariableName + "' must be type integer, long or short");
                }

                int rate = -1;
                if (outputLimitSpec.Rate != null)
                {
                    rate = outputLimitSpec.Rate.AsInt();
                }
                return resultSetProcessorHelperFactory.MakeOutputConditionCount(
                    rate, variableMetaData, statementContext);
            }
            else if (outputLimitSpec.RateType == OutputLimitRateType.TERM)
            {
                if (outputLimitSpec.AndAfterTerminateExpr == null &&
                    (outputLimitSpec.AndAfterTerminateThenExpressions == null ||
                     outputLimitSpec.AndAfterTerminateThenExpressions.IsEmpty()))
                {
                    return new OutputConditionTermFactory();
                }
                else
                {
                    return resultSetProcessorHelperFactory.MakeOutputConditionExpression(
                        new ExprConstantNodeImpl(false), Collections.GetEmptyList<OnTriggerSetAssignment>(),
                        statementContext, outputLimitSpec.AndAfterTerminateExpr,
                        outputLimitSpec.AndAfterTerminateThenExpressions, isStartConditionOnCreation);
                }
            }
            else
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug(
                        ".createCondition creating OutputConditionTime with interval length " + outputLimitSpec.Rate);
                }
                if ((variableMetaData != null) && (!variableMetaData.VariableType.IsNumeric()))
                {
                    throw new ArgumentException(
                        "Variable named '" + outputLimitSpec.VariableName + "' must be of numeric type");
                }

                return resultSetProcessorHelperFactory.MakeOutputConditionTime(
                    outputLimitSpec.TimePeriodExpr, isStartConditionOnCreation);
            }
        }