Пример #1
0
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            ExprNodeUtilityValidate.Validate(ExprNodeOrigin.PLUGINSINGLEROWPARAM, ChainSpec, validationContext);

            // get first chain item
            IList<ExprChainedSpec> chainList = new List<ExprChainedSpec>(ChainSpec);
            var firstItem = chainList.DeleteAt(0);

            // Get the types of the parameters for the first invocation
            var allowWildcard = validationContext.StreamTypeService.EventTypes.Length == 1;
            EventType streamZeroType = null;
            if (validationContext.StreamTypeService.EventTypes.Length > 0) {
                streamZeroType = validationContext.StreamTypeService.EventTypes[0];
            }

            var staticMethodDesc = ExprNodeUtilityResolve.ResolveMethodAllowWildcardAndStream(
                clazz.FullName,
                null,
                firstItem.Name,
                firstItem.Parameters,
                allowWildcard,
                streamZeroType,
                new ExprNodeUtilResolveExceptionHandlerDefault(firstItem.Name, true),
                FunctionName,
                validationContext.StatementRawInfo,
                validationContext.StatementCompileTimeService);

            var allowValueCache = true;
            bool isReturnsConstantResult;
            switch (config.ValueCache) {
                case ConfigurationCompilerPlugInSingleRowFunction.ValueCacheEnum.DISABLED:
                    isReturnsConstantResult = false;
                    allowValueCache = false;
                    break;

                case ConfigurationCompilerPlugInSingleRowFunction.ValueCacheEnum.CONFIGURED: {
                    var isUDFCache = validationContext.StatementCompileTimeService.Configuration.Compiler.Expression
                        .IsUdfCache;
                    isReturnsConstantResult = isUDFCache && staticMethodDesc.IsAllConstants && chainList.IsEmpty();
                    allowValueCache = isUDFCache;
                    break;
                }

                case ConfigurationCompilerPlugInSingleRowFunction.ValueCacheEnum.ENABLED:
                    isReturnsConstantResult = staticMethodDesc.IsAllConstants && chainList.IsEmpty();
                    break;

                default:
                    throw new IllegalStateException("Invalid value cache code " + config.ValueCache);
            }

            // this may return a pair of null if there is no lambda or the result cannot be wrapped for lambda-function use
            ExprDotStaticMethodWrap optionalLambdaWrap = ExprDotStaticMethodWrapFactory.Make(
                staticMethodDesc.ReflectionMethod,
                chainList,
                config.OptionalEventTypeName,
                validationContext);
            var typeInfo = optionalLambdaWrap != null
                ? optionalLambdaWrap.TypeInfo
                : EPTypeHelper.SingleValue(staticMethodDesc.ReflectionMethod.ReturnType);

            var eval = ExprDotNodeUtility.GetChainEvaluators(
                    -1,
                    typeInfo,
                    chainList,
                    validationContext,
                    false,
                    new ExprDotNodeFilterAnalyzerInputStatic())
                .ChainWithUnpack;
            var staticMethodForge = new ExprDotNodeForgeStaticMethod(
                this,
                isReturnsConstantResult,
                clazz.Name,
                staticMethodDesc.ReflectionMethod,
                staticMethodDesc.ChildForges,
                allowValueCache && staticMethodDesc.IsAllConstants,
                eval,
                optionalLambdaWrap,
                config.IsRethrowExceptions,
                null,
                validationContext.StatementName);

            // If caching the result, evaluate now and return the result.
            if (isReturnsConstantResult) {
                forge = new ExprPlugInSingleRowNodeForgeConst(this, staticMethodForge);
            }
            else {
                forge = new ExprPlugInSingleRowNodeForgeNC(this, staticMethodForge);
            }

            return null;
        }
Пример #2
0
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            ExprNodeUtility.Validate(ExprNodeOrigin.PLUGINSINGLEROWPARAM, _chainSpec, validationContext);

            // get first chain item
            var chainList = new List <ExprChainedSpec>(_chainSpec);
            var firstItem = chainList.Pluck(0);

            // Get the types of the parameters for the first invocation
            var       allowWildcard  = validationContext.StreamTypeService.EventTypes.Length == 1;
            EventType streamZeroType = null;

            if (validationContext.StreamTypeService.EventTypes.Length > 0)
            {
                streamZeroType = validationContext.StreamTypeService.EventTypes[0];
            }
            var staticMethodDesc = ExprNodeUtility.ResolveMethodAllowWildcardAndStream(
                _clazz.FullName, null, firstItem.Name, firstItem.Parameters, validationContext.MethodResolutionService,
                validationContext.EventAdapterService, validationContext.StatementId, allowWildcard, streamZeroType,
                new ExprNodeUtilResolveExceptionHandlerDefault(firstItem.Name, true), _functionName,
                validationContext.TableService);

            var allowValueCache = true;

            switch (_config.ValueCache)
            {
            case ValueCache.DISABLED:
                _isReturnsConstantResult = false;
                allowValueCache          = false;
                break;

            case ValueCache.CONFIGURED:
                _isReturnsConstantResult = validationContext.MethodResolutionService.IsUdfCache && staticMethodDesc.IsAllConstants && chainList.IsEmpty();
                allowValueCache          = validationContext.MethodResolutionService.IsUdfCache;
                break;

            case ValueCache.ENABLED:
                _isReturnsConstantResult = staticMethodDesc.IsAllConstants && chainList.IsEmpty();
                break;

            default:
                throw new IllegalStateException("Invalid value cache code " + _config.ValueCache);
            }

            // this may return a pair of null if there is no lambda or the result cannot be wrapped for lambda-function use
            var optionalLambdaWrap = ExprDotStaticMethodWrapFactory.Make(staticMethodDesc.ReflectionMethod, validationContext.EventAdapterService, chainList);
            var typeInfo           = optionalLambdaWrap != null ? optionalLambdaWrap.TypeInfo : EPTypeHelper.SingleValue(staticMethodDesc.ReflectionMethod.ReturnType);

            var eval = ExprDotNodeUtility.GetChainEvaluators(-1, typeInfo, chainList, validationContext, false, new ExprDotNodeFilterAnalyzerInputStatic()).ChainWithUnpack;

            _evaluator = new ExprDotEvalStaticMethod(validationContext.StatementName, _clazz.FullName, staticMethodDesc.FastMethod, staticMethodDesc.ChildEvals, allowValueCache && staticMethodDesc.IsAllConstants, optionalLambdaWrap, eval, _config.RethrowExceptions, null);

            // If caching the result, evaluate now and return the result.
            if (_isReturnsConstantResult)
            {
                var result = _evaluator.Evaluate(new EvaluateParams(null, true, null));
                _evaluator = new ProxyExprEvaluator {
                    ProcEvaluate = args => {
                        if (InstrumentationHelper.ENABLED)
                        {
                            InstrumentationHelper.Get().QExprPlugInSingleRow(staticMethodDesc.ReflectionMethod);
                            InstrumentationHelper.Get().AExprPlugInSingleRow(result);
                        }
                        return(result);
                    },
                    ReturnType = staticMethodDesc.FastMethod.ReturnType
                };
            }

            return(null);
        }