public EvalSelectNoWildcardAvro(
            SelectExprForgeContext selectExprForgeContext,
            ExprForge[] exprForges,
            EventType resultEventTypeAvro,
            string statementName)
        {
            _selectExprForgeContext = selectExprForgeContext;
            _resultEventTypeAvro = (AvroEventType) resultEventTypeAvro;

            _forges = new ExprForge[selectExprForgeContext.ExprForges.Length];
            var typeWidenerCustomizer =
                selectExprForgeContext.EventTypeAvroHandler.GetTypeWidenerCustomizer(resultEventTypeAvro);
            for (var i = 0; i < _forges.Length; i++) {
                _forges[i] = selectExprForgeContext.ExprForges[i];
                var forge = exprForges[i];
                var forgeEvaluationType = forge.EvaluationType;

                if (forge is ExprEvalByGetterFragment) {
                    _forges[i] = HandleFragment((ExprEvalByGetterFragment) forge);
                }
                else if (forge is ExprEvalStreamInsertBean) {
                    var und = (ExprEvalStreamInsertBean) forge;
                    _forges[i] =
                        new SelectExprInsertEventBeanFactory.ExprForgeStreamUnderlying(und.StreamNum, typeof(object));
                }
                else if (forge is SelectExprProcessorTypableMapForge) {
                    var typableMap = (SelectExprProcessorTypableMapForge) forge;
                    _forges[i] = new SelectExprProcessorEvalAvroMapToAvro(
                        typableMap.InnerForge,
                        ((AvroEventType) resultEventTypeAvro).SchemaAvro,
                        selectExprForgeContext.ColumnNames[i]);
                }
                else if (forge is ExprEvalStreamInsertNamedWindow) {
                    var nw = (ExprEvalStreamInsertNamedWindow) forge;
                    _forges[i] =
                        new SelectExprInsertEventBeanFactory.ExprForgeStreamUnderlying(nw.StreamNum, typeof(object));
                }
                else if (forgeEvaluationType != null && forgeEvaluationType.IsArray) {
                    var widener = TypeWidenerFactory.GetArrayToCollectionCoercer(forgeEvaluationType.GetElementType());
                    var resultType = typeof(ICollection<object>);
                    _forges[i] = new SelectExprProcessorEvalAvroArrayCoercer(forge, widener, resultType);
                }
                else {
                    var propertyName = selectExprForgeContext.ColumnNames[i];
                    var propertyType = resultEventTypeAvro.GetPropertyType(propertyName);
                    TypeWidenerSPI widener;
                    try {
                        widener = TypeWidenerFactory.GetCheckPropertyAssignType(
                            propertyName,
                            forgeEvaluationType,
                            propertyType,
                            propertyName,
                            true,
                            typeWidenerCustomizer,
                            statementName);
                    }
                    catch (TypeWidenerException ex) {
                        throw new ExprValidationException(ex.Message, ex);
                    }

                    if (widener != null) {
                        _forges[i] = new SelectExprProcessorEvalAvroArrayCoercer(forge, widener, propertyType);
                    }
                }
            }
        }
示例#2
0
        public EvalSelectNoWildcardAvro(
            SelectExprContext selectExprContext,
            EventType resultEventType,
            string statementName,
            string engineURI)
        {
            _selectExprContext = selectExprContext;
            _resultEventType = (AvroEventType) resultEventType;

            _evaluator = new ExprEvaluator[selectExprContext.ExpressionNodes.Length];
            var typeWidenerCustomizer =
                selectExprContext.EventAdapterService.GetTypeWidenerCustomizer(resultEventType);
            for (var i = 0; i < _evaluator.Length; i++)
            {
                var eval = selectExprContext.ExpressionNodes[i];
                _evaluator[i] = eval;

                if (eval is SelectExprProcessorEvalByGetterFragment)
                {
                    _evaluator[i] = HandleFragment((SelectExprProcessorEvalByGetterFragment) eval);
                }
                else if (eval is SelectExprProcessorEvalStreamInsertUnd)
                {
                    var und = (SelectExprProcessorEvalStreamInsertUnd) eval;
                    _evaluator[i] = new ProxyExprEvaluator
                    {
                        ProcEvaluate = (evaluateParams) =>
                        {
                            var @event = evaluateParams.EventsPerStream[und.StreamNum];
                            if (@event == null)
                            {
                                return null;
                            }
                            return @event.Underlying;
                        },
                        ProcReturnType = () => { return typeof (GenericRecord); }
                    };
                }
                else if (eval is SelectExprProcessorEvalTypableMap)
                {
                    var typableMap = (SelectExprProcessorEvalTypableMap) eval;
                    _evaluator[i] = new SelectExprProcessorEvalAvroMapToAvro(
                        typableMap.InnerEvaluator, ((AvroEventType) resultEventType).SchemaAvro,
                        selectExprContext.ColumnNames[i]);
                }
                else if (eval is SelectExprProcessorEvalStreamInsertNamedWindow)
                {
                    var nw = (SelectExprProcessorEvalStreamInsertNamedWindow) eval;
                    _evaluator[i] = new ProxyExprEvaluator
                    {
                        ProcEvaluate = (evaluateParams) =>
                        {
                            var @event = evaluateParams.EventsPerStream[nw.StreamNum];
                            if (@event == null)
                            {
                                return null;
                            }
                            return @event.Underlying;
                        },
                        ProcReturnType = () => { return typeof (GenericRecord); }
                    };
                }
                else if (eval.ReturnType != null && eval.ReturnType.IsArray)
                {
                    var widener = TypeWidenerFactory.GetArrayToCollectionCoercer(eval.ReturnType.GetElementType());
                    //if (eval.ReturnType == typeof (byte[]))
                    //{
                    //    widener = TypeWidenerFactory.BYTE_ARRAY_TO_BYTE_BUFFER_COERCER;
                    //}
                    _evaluator[i] = new SelectExprProcessorEvalAvroArrayCoercer(eval, widener);
                }
                else
                {
                    var propertyName = selectExprContext.ColumnNames[i];
                    var propertyType = resultEventType.GetPropertyType(propertyName);
                    var widener = TypeWidenerFactory.GetCheckPropertyAssignType(
                        propertyName, eval.ReturnType, propertyType, propertyName, true, typeWidenerCustomizer,
                        statementName, engineURI);
                    if (widener != null)
                    {
                        _evaluator[i] = new SelectExprProcessorEvalAvroArrayCoercer(eval, widener);
                    }
                }
            }
        }