예제 #1
0
        private EventType GetAssignAnonymousType(EventAdapterService eventAdapterService, string statementId)
        {
            IDictionary <string, object> rowType = RowType;
            EventType resultEventType            = eventAdapterService.CreateAnonymousMapType(statementId + "_subquery_" + SubselectNumber, rowType);

            subselectMultirowType = new SubselectMultirowType(resultEventType, eventAdapterService);
            return(resultEventType);
        }
예제 #2
0
        public static EventType GetEventType(int statementId, EventAdapterService eventAdapterService, VariableMetaData variableMetaData)
        {
            var variableTypes = new Dictionary <String, Object>();

            variableTypes.Put(variableMetaData.VariableName, variableMetaData.VariableType);
            String outputEventTypeName = statementId + "_outcreatevar";

            return(eventAdapterService.CreateAnonymousMapType(outputEventTypeName, variableTypes, true));
        }
예제 #3
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="statementId">The statement identifier.</param>
        /// <param name="desc">specification for the on-set statement</param>
        /// <param name="eventAdapterService">for creating statements</param>
        /// <param name="variableService">for setting variables</param>
        /// <param name="statementResultService">for coordinating on whether insert and remove stream events should be posted</param>
        /// <param name="exprEvaluatorContext">context for expression evalauation</param>
        /// <throws>com.espertech.esper.epl.expression.core.ExprValidationException if the assignment expressions are invalid</throws>
        public OnSetVariableViewFactory(string statementId, OnTriggerSetDesc desc, EventAdapterService eventAdapterService, VariableService variableService, StatementResultService statementResultService, ExprEvaluatorContext exprEvaluatorContext)
        {
            EventAdapterService    = eventAdapterService;
            VariableService        = variableService;
            StatementResultService = statementResultService;

            VariableReadWritePackage = new VariableReadWritePackage(desc.Assignments, variableService, eventAdapterService);
            var outputEventTypeName = statementId + "_outsetvar";

            EventType = eventAdapterService.CreateAnonymousMapType(outputEventTypeName, VariableReadWritePackage.VariableTypes);
        }
예제 #4
0
        /// <summary>
        /// Creates an event type from the query meta data.
        /// </summary>
        /// <param name="statementId">The statement id.</param>
        /// <param name="streamNumber">The stream number.</param>
        /// <param name="queryMetaData">The query meta data.</param>
        /// <param name="eventAdapterService">The event adapter service.</param>
        /// <param name="databaseStreamSpec">The database stream spec.</param>
        /// <param name="columnTypeConversionHook">The column type conversion hook.</param>
        /// <param name="outputRowConversionHook">The output row conversion hook.</param>
        /// <returns></returns>
        private static EventType CreateEventType(
            int statementId,
            int streamNumber,
            QueryMetaData queryMetaData,
            EventAdapterService eventAdapterService,
            DBStatementStreamSpec databaseStreamSpec,
            Func <SQLColumnTypeContext, Type> columnTypeConversionHook,
            Func <SQLOutputRowTypeContext, Type> outputRowConversionHook)
        {
            var columnNum       = 1;
            var eventTypeFields = new Dictionary <String, Object>();

            foreach (var entry in queryMetaData.OutputParameters)
            {
                var name         = entry.Key;
                var dbOutputDesc = entry.Value;

                Type clazz;
                if (dbOutputDesc.OptionalBinding != null)
                {
                    clazz = dbOutputDesc.OptionalBinding.DataType;
                }
                else
                {
                    clazz = dbOutputDesc.DataType;
                }

                if (columnTypeConversionHook != null)
                {
                    var newValue = columnTypeConversionHook.Invoke(
                        new SQLColumnTypeContext(
                            databaseStreamSpec.DatabaseName,
                            databaseStreamSpec.SqlWithSubsParams,
                            name, clazz,
                            dbOutputDesc.SqlType,
                            columnNum));
                    if (newValue != null)
                    {
                        clazz = newValue;
                    }
                }

                eventTypeFields[name] = clazz.GetBoxedType();
                columnNum++;
            }

            EventType eventType;

            if (outputRowConversionHook == null)
            {
                var outputEventType = statementId + "_dbpoll_" + streamNumber;
                eventType = eventAdapterService.CreateAnonymousMapType(outputEventType, eventTypeFields, true);
            }
            else
            {
                var carrierClass = outputRowConversionHook.Invoke(
                    new SQLOutputRowTypeContext(
                        databaseStreamSpec.DatabaseName,
                        databaseStreamSpec.SqlWithSubsParams,
                        eventTypeFields));
                if (carrierClass == null)
                {
                    throw new ExprValidationException("Output row conversion hook returned no type");
                }

                eventType = eventAdapterService.AddBeanType(carrierClass.FullName, carrierClass, false, false, false);
            }

            return(eventType);
        }
예제 #5
0
        public static SelectExprProcessor Create(
            ICollection <int> assignedTypeNumberStack,
            int statementId,
            string statementName,
            string[] streamNames,
            EventType[] streamTypes,
            EventAdapterService eventAdapterService,
            InsertIntoDesc insertIntoDesc,
            SelectExprEventTypeRegistry selectExprEventTypeRegistry,
            EngineImportService engineImportService,
            Attribute[] annotations,
            ConfigurationInformation configuration,
            TableService tableService,
            string engineURI)

        {
            if ((streamNames.Length < 2) || (streamTypes.Length < 2) || (streamNames.Length != streamTypes.Length))
            {
                throw new ArgumentException(
                          "Stream names and types parameter length is invalid, expected use of this class is for join statements");
            }

            // Create EventType of result join events
            var  selectProperties   = new LinkedHashMap <string, Object>();
            var  streamTypesWTables = new EventType[streamTypes.Length];
            bool hasTables          = false;

            for (int i = 0; i < streamTypes.Length; i++)
            {
                streamTypesWTables[i] = streamTypes[i];
                string tableName = TableServiceUtil.GetTableNameFromEventType(streamTypesWTables[i]);
                if (tableName != null)
                {
                    hasTables             = true;
                    streamTypesWTables[i] = tableService.GetTableMetadata(tableName).PublicEventType;
                }
                selectProperties.Put(streamNames[i], streamTypesWTables[i]);
            }

            // If we have a name for this type, add it
            EventUnderlyingType representation = EventRepresentationUtil.GetRepresentation(
                annotations, configuration, AssignedType.NONE);
            EventType resultEventType;

            SelectExprProcessor processor = null;

            if (insertIntoDesc != null)
            {
                EventType existingType = eventAdapterService.GetEventTypeByName(insertIntoDesc.EventTypeName);
                if (existingType != null)
                {
                    processor = SelectExprInsertEventBeanFactory.GetInsertUnderlyingJoinWildcard(
                        eventAdapterService, existingType, streamNames, streamTypesWTables, engineImportService,
                        statementName, engineURI);
                }
            }

            if (processor == null)
            {
                if (insertIntoDesc != null)
                {
                    try
                    {
                        if (representation == EventUnderlyingType.MAP)
                        {
                            resultEventType = eventAdapterService.AddNestableMapType(
                                insertIntoDesc.EventTypeName, selectProperties, null, false, false, false, false, true);
                        }
                        else if (representation == EventUnderlyingType.OBJECTARRAY)
                        {
                            resultEventType = eventAdapterService.AddNestableObjectArrayType(
                                insertIntoDesc.EventTypeName, selectProperties, null, false, false, false, false, true,
                                false, null);
                        }
                        else if (representation == EventUnderlyingType.AVRO)
                        {
                            resultEventType = eventAdapterService.AddAvroType(
                                insertIntoDesc.EventTypeName, selectProperties, false, false, false, false, true,
                                annotations, null, statementName, engineURI);
                        }
                        else
                        {
                            throw new IllegalStateException("Unrecognized code " + representation);
                        }
                        selectExprEventTypeRegistry.Add(resultEventType);
                    }
                    catch (EventAdapterException ex)
                    {
                        throw new ExprValidationException(ex.Message, ex);
                    }
                }
                else
                {
                    if (representation == EventUnderlyingType.MAP)
                    {
                        resultEventType =
                            eventAdapterService.CreateAnonymousMapType(
                                statementId + "_join_" + CollectionUtil.ToString(assignedTypeNumberStack, "_"),
                                selectProperties, true);
                    }
                    else if (representation == EventUnderlyingType.OBJECTARRAY)
                    {
                        resultEventType =
                            eventAdapterService.CreateAnonymousObjectArrayType(
                                statementId + "_join_" + CollectionUtil.ToString(assignedTypeNumberStack, "_"),
                                selectProperties);
                    }
                    else if (representation == EventUnderlyingType.AVRO)
                    {
                        resultEventType =
                            eventAdapterService.CreateAnonymousAvroType(
                                statementId + "_join_" + CollectionUtil.ToString(assignedTypeNumberStack, "_"),
                                selectProperties, annotations, statementName, engineURI);
                    }
                    else
                    {
                        throw new IllegalStateException("Unrecognized enum " + representation);
                    }
                }
                if (resultEventType is ObjectArrayEventType)
                {
                    processor = new SelectExprJoinWildcardProcessorObjectArray(
                        streamNames, resultEventType, eventAdapterService);
                }
                else if (resultEventType is MapEventType)
                {
                    processor = new SelectExprJoinWildcardProcessorMap(
                        streamNames, resultEventType, eventAdapterService);
                }
                else if (resultEventType is AvroSchemaEventType)
                {
                    processor = eventAdapterService.EventAdapterAvroHandler.GetOutputFactory().MakeJoinWildcard(
                        streamNames, resultEventType, eventAdapterService);
                }
            }

            if (!hasTables)
            {
                return(processor);
            }
            return(new SelectExprJoinWildcardProcessorTableRows(streamTypes, processor, tableService));
        }
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="assignedTypeNumberStack">The assigned type number stack.</param>
        /// <param name="statementId">The statement identifier.</param>
        /// <param name="streamNames">name of each stream</param>
        /// <param name="streamTypes">type of each stream</param>
        /// <param name="eventAdapterService">service for generating events and handling event types</param>
        /// <param name="insertIntoDesc">describes the insert-into clause</param>
        /// <param name="selectExprEventTypeRegistry">registry for event type to statements</param>
        /// <param name="methodResolutionService">for resolving writable properties</param>
        /// <param name="annotations">The annotations.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="tableService">The table service.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">Stream names and types parameter length is invalid, expected use of this class is for join statements</exception>
        /// <exception cref="ExprValidationException"></exception>
        /// <throws>com.espertech.esper.epl.expression.core.ExprValidationException if the expression validation failed</throws>
        public static SelectExprProcessor Create(
            ICollection <int> assignedTypeNumberStack,
            string statementId,
            string[] streamNames,
            EventType[] streamTypes,
            EventAdapterService eventAdapterService,
            InsertIntoDesc insertIntoDesc,
            SelectExprEventTypeRegistry selectExprEventTypeRegistry,
            MethodResolutionService methodResolutionService,
            Attribute[] annotations,
            ConfigurationInformation configuration,
            TableService tableService)
        {
            if ((streamNames.Length < 2) || (streamTypes.Length < 2) || (streamNames.Length != streamTypes.Length))
            {
                throw new ArgumentException(
                          "Stream names and types parameter length is invalid, expected use of this class is for join statements");
            }

            // Create EventType of result join events
            var eventTypeMap       = new LinkedHashMap <string, object>();
            var streamTypesWTables = new EventType[streamTypes.Length];
            var hasTables          = false;

            for (var i = 0; i < streamTypes.Length; i++)
            {
                streamTypesWTables[i] = streamTypes[i];
                var tableName = TableServiceUtil.GetTableNameFromEventType(streamTypesWTables[i]);
                if (tableName != null)
                {
                    hasTables             = true;
                    streamTypesWTables[i] = tableService.GetTableMetadata(tableName).PublicEventType;
                }
                eventTypeMap.Put(streamNames[i], streamTypesWTables[i]);
            }

            // If we have a name for this type, add it
            var       useMap = EventRepresentationUtil.IsMap(annotations, configuration, AssignedType.NONE);
            EventType resultEventType;

            SelectExprProcessor processor = null;

            if (insertIntoDesc != null)
            {
                EventType existingType = eventAdapterService.GetEventTypeByName(insertIntoDesc.EventTypeName);
                if (existingType != null)
                {
                    processor = SelectExprInsertEventBeanFactory.GetInsertUnderlyingJoinWildcard(
                        eventAdapterService, existingType, streamNames, streamTypesWTables,
                        methodResolutionService.EngineImportService);
                }
            }

            if (processor == null)
            {
                if (insertIntoDesc != null)
                {
                    try
                    {
                        if (useMap)
                        {
                            resultEventType = eventAdapterService.AddNestableMapType(
                                insertIntoDesc.EventTypeName, eventTypeMap, null, false, false, false, false, true);
                        }
                        else
                        {
                            resultEventType = eventAdapterService.AddNestableObjectArrayType(
                                insertIntoDesc.EventTypeName, eventTypeMap, null, false, false, false, false, true, false, null);
                        }
                        selectExprEventTypeRegistry.Add(resultEventType);
                    }
                    catch (EventAdapterException ex)
                    {
                        throw new ExprValidationException(ex.Message);
                    }
                }
                else
                {
                    if (useMap)
                    {
                        resultEventType =
                            eventAdapterService.CreateAnonymousMapType(
                                statementId + "_join_" + CollectionUtil.ToString(assignedTypeNumberStack, "_"), eventTypeMap);
                    }
                    else
                    {
                        resultEventType =
                            eventAdapterService.CreateAnonymousObjectArrayType(
                                statementId + "_join_" + CollectionUtil.ToString(assignedTypeNumberStack, "_"), eventTypeMap);
                    }
                }
                if (resultEventType is ObjectArrayEventType)
                {
                    processor = new SelectExprJoinWildcardProcessorObjectArray(
                        streamNames, resultEventType, eventAdapterService);
                }
                else
                {
                    processor = new SelectExprJoinWildcardProcessorMap(streamNames, resultEventType, eventAdapterService);
                }
            }

            if (!hasTables)
            {
                return(processor);
            }
            return(new SelectExprJoinWildcardProcessorTableRows(streamTypes, processor, tableService));
        }