Пример #1
0
        public RavenFileSystem(InMemoryRavenConfiguration systemConfiguration, string name, TransportState recievedTransportState = null)
        {
            this.Name = name;
            this.systemConfiguration = systemConfiguration;

            var storageType = systemConfiguration.FileSystem.DefaultStorageTypeName;

            storage      = CreateTransactionalStorage(storageType, systemConfiguration);
            search       = new IndexStorage(systemConfiguration.FileSystem.IndexStoragePath, systemConfiguration.Settings);
            sigGenerator = new SigGenerator();
            var replicationHiLo = new SynchronizationHiLo(storage);
            var sequenceActions = new SequenceActions(storage);

            transportState        = recievedTransportState ?? new TransportState();
            notificationPublisher = new NotificationPublisher(transportState);
            fileLockManager       = new FileLockManager();
            storage.Initialize();
            search.Initialize();
            var uuidGenerator = new UuidGenerator(sequenceActions);

            historian  = new Historian(storage, replicationHiLo, uuidGenerator);
            BufferPool = new BufferPool(1024 * 1024 * 1024, 65 * 1024);
            conflictArtifactManager = new ConflictArtifactManager(storage, search);
            conflictDetector        = new ConflictDetector();
            conflictResolver        = new ConflictResolver(storage, new CompositionContainer(systemConfiguration.Catalog));
            synchronizationTask     = new SynchronizationTask(storage, sigGenerator, notificationPublisher, systemConfiguration);
            storageOperationsTask   = new StorageOperationsTask(storage, search, notificationPublisher);
            metricsCounters         = new MetricsCountersManager();

            AppDomain.CurrentDomain.ProcessExit  += ShouldDispose;
            AppDomain.CurrentDomain.DomainUnload += ShouldDispose;
        }
Пример #2
0
        public void Initialize(UuidGenerator generator, OrderedPartCollection <AbstractFileCodec> codecs, Action <string> putResourceMarker = null)
        {
            if (codecs == null)
            {
                throw new ArgumentNullException("codecs");
            }

            fileCodecs    = codecs;
            uuidGenerator = generator;

            var persistenceSource = CreateStorageOptionsFromConfiguration(path, configuration);

            tableStorage = new TableStorage(persistenceSource, bufferPool);
            var schemaCreator = new SchemaCreator(configuration, tableStorage, Output, Log);

            schemaCreator.CreateSchema();
            schemaCreator.SetupDatabaseIdAndSchemaVersion();
            schemaCreator.UpdateSchemaIfNecessary();

            SetupDatabaseId();
            idGenerator = new IdGenerator(tableStorage);

            if (putResourceMarker != null)
            {
                putResourceMarker(path);
            }
        }
Пример #3
0
        /// <summary>
        /// Add an index specification element.
        /// </summary>
        /// <param name="indexProperties">list of property names to index</param>
        /// <param name="coercionTypes">list of coercion types if required, or null if no coercion required</param>
        /// <returns>number indicating position of index that was added</returns>
        public string AddIndex(string[] indexProperties, Type[] coercionTypes)
        {
            string uuid = UuidGenerator.Generate();

            _items.Put(new TableLookupIndexReqKey(uuid), new QueryPlanIndexItem(indexProperties, coercionTypes, null, null, false));
            return(uuid);
        }
Пример #4
0
        public void Initialize(UuidGenerator generator, OrderedPartCollection <AbstractFileCodec> codecs, Action <string> putResourceMarker = null)
        {
            if (codecs == null)
            {
                throw new ArgumentException("codecs");
            }

            uuidGenerator = generator;
            fileCodecs    = codecs;

            try
            {
                new TransactionalStorageConfigurator(configuration).ConfigureInstance(instance, path);

                Api.JetInit(ref instance);

                EnsureDatabaseIsCreatedAndAttachToDatabase();

                SetIdFromDb();

                tableColumnsCache.InitColumDictionaries(instance, database);

                if (putResourceMarker != null)
                {
                    putResourceMarker(path);
                }
            }
            catch (Exception e)
            {
                Dispose();
                throw new InvalidOperationException("Could not open transactional storage: " + database, e);
            }
        }
Пример #5
0
 public EventType CreateMapType(IDictionary<string, object> map)
 {
     var metadata = new EventTypeMetadata(UuidGenerator.Generate(), null, EventTypeTypeClass.STREAM, EventTypeApplicationType.MAP, NameAccessModifier.INTERNAL, EventTypeBusModifier.NONBUS, false, EventTypeIdPair.Unassigned());
     return new MapEventType(
         metadata, map, null, null, null, null,
         BEAN_EVENT_TYPE_FACTORY);
 }
Пример #6
0
        public void Initialize(UuidGenerator generator, OrderedPartCollection <AbstractFileCodec> codecs)
        {
            if (codecs == null)
            {
                throw new ArgumentNullException("codecs");
            }

            fileCodecs    = codecs;
            uuidGenerator = generator;

            bool runInMemory;

            bool.TryParse(settings[Constants.RunInMemory], out runInMemory);

            var persistenceSource = runInMemory ? StorageEnvironmentOptions.CreateMemoryOnly() :
                                    CreateStorageOptionsFromConfiguration(path, settings);

            tableStorage = new TableStorage(persistenceSource, bufferPool);
            var schemaCreator = new SchemaCreator(configuration, tableStorage, Output, Log);

            schemaCreator.CreateSchema();
            schemaCreator.SetupDatabaseIdAndSchemaVersion();
            schemaCreator.UpdateSchemaIfNecessary();

            SetupDatabaseId();
            idGenerator = new IdGenerator(tableStorage);
        }
Пример #7
0
 public StorageActionsAccessor(TableColumnsCache tableColumnsCache, JET_INSTANCE instance, string databaseName, UuidGenerator uuidGenerator, OrderedPartCollection <AbstractFileCodec> fileCodecs)
 {
     this.tableColumnsCache = tableColumnsCache;
     this.uuidGenerator     = uuidGenerator;
     this.fileCodecs        = fileCodecs;
     try
     {
         session     = new Session(instance);
         transaction = new Transaction(session);
         Api.JetOpenDatabase(session, databaseName, null, out database, OpenDatabaseGrbit.None);
     }
     catch (Exception original)
     {
         log.WarnException("Could not create accessor", original);
         try
         {
             Dispose();
         }
         catch (Exception e)
         {
             log.WarnException("Could not properly dispose accessor after exception in ctor.", e);
         }
         throw;
     }
 }
Пример #8
0
        private NamedWindowOnMergeActionIns SetupInsert(string namedWindowName, InternalEventRouter internalEventRouter, EventTypeSPI eventTypeNamedWindow, int selectClauseNumber, OnTriggerMergeActionInsert desc, EventType triggeringEventType, string triggeringStreamName, StatementContext statementContext)
        {
            // Compile insert-into INFO
            string streamName     = desc.OptionalStreamName ?? eventTypeNamedWindow.Name;
            var    insertIntoDesc = InsertIntoDesc.FromColumns(streamName, desc.Columns);

            // rewrite any wildcards to use "stream.wildcard"
            if (triggeringStreamName == null)
            {
                triggeringStreamName = UuidGenerator.Generate();
            }
            var selectNoWildcard = CompileSelectNoWildcard(triggeringStreamName, desc.SelectClauseCompiled);

            // Set up event types for select-clause evaluation: The first type does not contain anything as its the named window row which is not present for insert
            var dummyTypeNoProperties = new MapEventType(EventTypeMetadata.CreateAnonymous("merge_named_window_insert", ApplicationType.MAP), "merge_named_window_insert", 0, null, Collections.EmptyDataMap, null, null, null);
            var eventTypes            = new EventType[] { dummyTypeNoProperties, triggeringEventType };
            var streamNames           = new string[] { UuidGenerator.Generate(), triggeringStreamName };
            var streamTypeService     = new StreamTypeServiceImpl(eventTypes, streamNames, new bool[1], statementContext.EngineURI, false);

            // Get select expr processor
            var selectExprEventTypeRegistry = new SelectExprEventTypeRegistry(statementContext.StatementName, statementContext.StatementEventTypeRef);
            var exprEvaluatorContext        = new ExprEvaluatorContextStatement(statementContext, false);
            var insertHelper = SelectExprProcessorFactory.GetProcessor(
                statementContext.Container,
                Collections.SingletonList(selectClauseNumber),
                selectNoWildcard.ToArray(), false,
                insertIntoDesc, null, null, streamTypeService,
                statementContext.EventAdapterService,
                statementContext.StatementResultService,
                statementContext.ValueAddEventService,
                selectExprEventTypeRegistry,
                statementContext.EngineImportService,
                exprEvaluatorContext,
                statementContext.VariableService,
                statementContext.ScriptingService,
                statementContext.TableService,
                statementContext.TimeProvider,
                statementContext.EngineURI,
                statementContext.StatementId,
                statementContext.StatementName,
                statementContext.Annotations,
                statementContext.ContextDescriptor,
                statementContext.ConfigSnapshot, null,
                statementContext.NamedWindowMgmtService, null, null,
                statementContext.StatementExtensionServicesContext);
            var filterEval = desc.OptionalWhereClause == null ? null : desc.OptionalWhereClause.ExprEvaluator;

            var routerToUser = streamName.Equals(namedWindowName) ? null : internalEventRouter;
            var audit        = AuditEnum.INSERT.GetAudit(statementContext.Annotations) != null;

            string insertIntoTableName = null;

            if (statementContext.TableService.GetTableMetadata(insertIntoDesc.EventTypeName) != null)
            {
                insertIntoTableName = insertIntoDesc.EventTypeName;
            }

            return(new NamedWindowOnMergeActionIns(filterEval, insertHelper, routerToUser, insertIntoTableName, statementContext.TableService, statementContext.EpStatementHandle, statementContext.InternalEventEngineRouteDest, audit));
        }
Пример #9
0
 public StorageActionsAccessor(TableStorage storage, Reference <WriteBatch> writeBatch, Reference <SnapshotReader> snapshot, IdGenerator generator, IBufferPool bufferPool, UuidGenerator uuidGenerator, OrderedPartCollection <AbstractFileCodec> fileCodecs)
     : base(snapshot, generator, bufferPool)
 {
     this.storage       = storage;
     this.writeBatch    = writeBatch;
     this.uuidGenerator = uuidGenerator;
     this.fileCodecs    = fileCodecs;
 }
Пример #10
0
 private static void SendAssertDotObjectEquals(
     RegressionEnvironment env,
     int intPrimitive,
     bool expected)
 {
     env.SendEventBean(new SupportBean(UuidGenerator.Generate(), intPrimitive));
     EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), "c0".SplitCsv(), expected);
 }
Пример #11
0
 private void TryInvalidCompile(EPServiceProvider epService, string epl, string message)
 {
     try {
         epService.EPAdministrator.CreateEPL(epl, UuidGenerator.Generate());
         Assert.Fail();
     } catch (EPStatementException ex) {
         AssertException(message, ex.Message);
     }
 }
Пример #12
0
        public void GetFilesAfterWhereFileEtagsHaveDifferentRestartValues(string requestedStorage)
        {
            var etagGenerator = new UuidGenerator();

            using (var storage = NewTransactionalStorage(requestedStorage, uuidGenerator: etagGenerator))
            {
                storage.Batch(accessor => accessor.PutFile("/file1", null, new RavenJObject()));

                etagGenerator.EtagBase = 7;
                storage.Batch(accessor => accessor.PutFile("/file2", 10, new RavenJObject()));

                etagGenerator.EtagBase = 12;
                storage.Batch(accessor => accessor.PutFile("/file3", null, new RavenJObject()));

                etagGenerator.EtagBase = 300;
                storage.Batch(accessor => accessor.PutFile("/file4", 10, new RavenJObject()));

                etagGenerator.EtagBase = 450;
                storage.Batch(accessor => accessor.PutFile("/file5", null, new RavenJObject()));

                etagGenerator.EtagBase = 1024;
                storage.Batch(accessor => accessor.PutFile("/file6", 10, new RavenJObject()));

                etagGenerator.EtagBase = 3333;
                storage.Batch(accessor => accessor.PutFile("/file7", null, new RavenJObject()));

                etagGenerator.EtagBase = 10000;
                storage.Batch(accessor => accessor.PutFile("/file8", 10, new RavenJObject()));

                storage.Batch(accessor =>
                {
                    var files = accessor
                                .GetFilesAfter(Etag.Empty, 10)
                                .ToList();

                    Assert.Equal(8, files.Count);
                    Assert.Equal("file1", files[0].Name);
                    Assert.Equal("file2", files[1].Name);
                    Assert.Equal("file3", files[2].Name);
                    Assert.Equal("file4", files[3].Name);
                    Assert.Equal("file5", files[4].Name);
                    Assert.Equal("file6", files[5].Name);
                    Assert.Equal("file7", files[6].Name);
                    Assert.Equal("file8", files[7].Name);

                    files = accessor
                            .GetFilesAfter(files[4].Etag, 100)
                            .ToList();

                    Assert.Equal(3, files.Count);
                    Assert.Equal("file6", files[0].Name);
                    Assert.Equal("file7", files[1].Name);
                    Assert.Equal("file8", files[2].Name);
                });
            }
        }
Пример #13
0
        public static QueryPlanIndex MakeIndex(IList <QueryPlanIndexItem> indexesSet)
        {
            IDictionary <TableLookupIndexReqKey, QueryPlanIndexItem> items = new LinkedHashMap <TableLookupIndexReqKey, QueryPlanIndexItem>();

            foreach (QueryPlanIndexItem item in indexesSet)
            {
                items.Put(new TableLookupIndexReqKey(UuidGenerator.Generate()), item);
            }
            return(new QueryPlanIndex(items));
        }
Пример #14
0
        public static QueryPlanIndex MakeIndex(params QueryPlanIndexItem[] items)
        {
            IDictionary <TableLookupIndexReqKey, QueryPlanIndexItem> result = new LinkedHashMap <TableLookupIndexReqKey, QueryPlanIndexItem>();

            foreach (QueryPlanIndexItem item in items)
            {
                result.Put(new TableLookupIndexReqKey(UuidGenerator.Generate()), item);
            }
            return(new QueryPlanIndex(result));
        }
Пример #15
0
        public static QueryPlanIndexForge MakeIndex(IList<QueryPlanIndexItemForge> indexesSet)
        {
            IDictionary<TableLookupIndexReqKey, QueryPlanIndexItemForge> items =
                new LinkedHashMap<TableLookupIndexReqKey, QueryPlanIndexItemForge>();
            foreach (var item in indexesSet) {
                items.Put(new TableLookupIndexReqKey(UuidGenerator.Generate(), null), item);
            }

            return new QueryPlanIndexForge(items);
        }
Пример #16
0
        public void Initialize()
        {
            this.storage.Initialize();

            var replicationHiLo = new SynchronizationHiLo(storage);
            var sequenceActions = new SequenceActions(storage);
            var uuidGenerator   = new UuidGenerator(sequenceActions);

            this.historian = new Historian(storage, replicationHiLo, uuidGenerator);

            this.search.Initialize(this);
        }
Пример #17
0
        public void Initialize(UuidGenerator generator, OrderedPartCollection <AbstractFileCodec> codecs, Action <string> putResourceMarker = null)
        {
            if (codecs == null)
            {
                throw new ArgumentException("codecs");
            }

            uuidGenerator = generator;
            fileCodecs    = codecs;

            try
            {
                new TransactionalStorageConfigurator(configuration).ConfigureInstance(instance, path);
                bool lockTaken = false;
                //locking only the compaction didn't resolve the problem it seems this is the minimal amount of code that needs to be locked
                //to prevent errors from esent
                try
                {
                    Monitor.TryEnter(locker, 30 * 1000, ref lockTaken);
                    if (lockTaken == false)
                    {
                        throw new TimeoutException("Couldn't take FS lock for initializing a new FS (Esent bug requires us to lock the storage), we have waited for 30 seconds, aborting.");
                    }
                    Api.JetInit(ref instance);

                    EnsureDatabaseIsCreatedAndAttachToDatabase();
                }
                finally
                {
                    if (lockTaken)
                    {
                        Monitor.Exit(locker);
                    }
                }
                SetIdFromDb();

                tableColumnsCache.InitColumDictionaries(instance, database);

                if (putResourceMarker != null)
                {
                    putResourceMarker(path);
                }
            }
            catch (Exception e)
            {
                Dispose();
                throw new InvalidOperationException("Could not open transactional storage: " + database, e);
            }
        }
Пример #18
0
        public void Initialize()
        {
            var generator = new UuidGenerator();

            storage.Initialize(generator, FileCodecs);
            generator.EtagBase = new SequenceActions(storage).GetNextValue("Raven/Etag");

            historian = new Historian(storage, new SynchronizationHiLo(storage));

            InitializeTriggersExceptIndexCodecs();

            search.Initialize(this);

            SecondStageInitialization();
        }
Пример #19
0
        private static void LoadUuid(IDatabaseSettingDao dao)
        {
            string uuid = dao.GetUuid();

            if (string.IsNullOrEmpty(uuid))
            {
                UuidGenerator g = Guid.NewGuid();
                uuid = g.ToString().Replace("-", "");
                dao.SetUuid(uuid);
            }

            RuntimeSettings.Uuid   = uuid;
            ExceptionReporter.Uuid = uuid;
            Logger.InfoFormat("Your user id is {0}, use this for any bug reports", RuntimeSettings.Uuid);
        }
Пример #20
0
        public void Initialize()
        {
            storage.Initialize(FileCodecs);

            var replicationHiLo = new SynchronizationHiLo(storage);
            var sequenceActions = new SequenceActions(storage);
            var uuidGenerator   = new UuidGenerator(sequenceActions);

            historian = new Historian(storage, replicationHiLo, uuidGenerator);

            search.Initialize(this);

            InitializeTriggersExceptIndexCodecs();
            SecondStageInitialization();
        }
Пример #21
0
        private static string GetUuid()
        {
            using (RegistryKey registryKey = Registry.CurrentUser.CreateSubKey(@"Software\EvilSoft\GrimDamage")) {
                string uuid = (string)registryKey?.GetValue("uuid");
                if (!string.IsNullOrEmpty(uuid))
                {
                    return(uuid);
                }

                UuidGenerator g = Guid.NewGuid();
                uuid = g.ToString().Replace("-", "");

                registryKey?.SetValue("uuid", uuid);
                return(uuid);
            }
        }
Пример #22
0
        public RavenFileSystem(InMemoryRavenConfiguration systemConfiguration, TransportState transportState, string name)
        {
            this.Name = name;
            this.systemConfiguration = systemConfiguration;

            var storageType = systemConfiguration.DefaultFileSystemStorageTypeName;

            if (string.Equals(InMemoryRavenConfiguration.VoronTypeName, storageType, StringComparison.OrdinalIgnoreCase) == false)
            {
                if (Directory.Exists(systemConfiguration.FileSystemDataDirectory) &&
                    Directory.EnumerateFileSystemEntries(systemConfiguration.FileSystemDataDirectory).Any())
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  "We do not allow to run on a storage engine other then Voron, while we are in the early pre-release phase of RavenDB 3.0. You are currently running on {0}",
                                  storageType));
                }

                Trace.WriteLine("Forcing filesystem to run on Voron - pre release behavior only, mind " + Path.GetFileName(Path.GetDirectoryName(systemConfiguration.FileSystemDataDirectory)));
                storageType = InMemoryRavenConfiguration.VoronTypeName;
            }

            storage      = CreateTransactionalStorage(storageType, systemConfiguration);
            search       = new IndexStorage(systemConfiguration.FileSystemIndexStoragePath, systemConfiguration.Settings);
            sigGenerator = new SigGenerator();
            var replicationHiLo = new SynchronizationHiLo(storage);
            var sequenceActions = new SequenceActions(storage);

            this.transportState   = transportState;
            notificationPublisher = new NotificationPublisher(transportState);
            fileLockManager       = new FileLockManager();
            storage.Initialize();
            search.Initialize();
            var uuidGenerator = new UuidGenerator(sequenceActions);

            historian  = new Historian(storage, replicationHiLo, uuidGenerator);
            BufferPool = new BufferPool(1024 * 1024 * 1024, 65 * 1024);
            conflictArtifactManager = new ConflictArtifactManager(storage, search);
            conflictDetector        = new ConflictDetector();
            conflictResolver        = new ConflictResolver();
            synchronizationTask     = new SynchronizationTask(storage, sigGenerator, notificationPublisher, systemConfiguration);
            storageOperationsTask   = new StorageOperationsTask(storage, search, notificationPublisher);
            metricsCounters         = new MetricsCountersManager();

            AppDomain.CurrentDomain.ProcessExit  += ShouldDispose;
            AppDomain.CurrentDomain.DomainUnload += ShouldDispose;
        }
Пример #23
0
        public void Initialize()
        {
            try
            {
                var generator = new UuidGenerator();
                storage.Initialize(generator, FileCodecs, storagePath =>
                {
                    if (configuration.RunInMemory)
                    {
                        return;
                    }

                    var resourceTypeFile = Path.Combine(storagePath, Constants.FileSystem.FsResourceMarker);

                    if (File.Exists(resourceTypeFile) == false)
                    {
                        using (File.Create(resourceTypeFile)) { }
                    }
                });
                generator.EtagBase = new SequenceActions(storage).GetNextValue("Raven/Etag");

                historian = new Historian(storage, new SynchronizationHiLo(storage));

                InitializeTriggersExceptIndexCodecs();

                search.Initialize(this);

                SecondStageInitialization();

                synchronizationTask.Start();
            }
            catch (Exception e)
            {
                Log.ErrorException(string.Format("Could not create file system '{0}'", Name ?? "unknown name"), e);
                try
                {
                    Dispose();
                }
                catch (Exception ex)
                {
                    Log.FatalException("Failed to dispose when already getting an error during file system initialization", ex);
                }
                throw;
            }
        }
Пример #24
0
        public StmtNamedWindowIterateCallable(
            string threadKey,
            RegressionEnvironment env,
            RegressionPath path,
            int numRepeats)
        {
            this.env = env;
            this.numRepeats = numRepeats;
            this.threadKey = threadKey;

            var stmtName = UuidGenerator.Generate();
            env.CompileDeploy(
                "@Name('" +
                stmtName +
                "') select TheString, sum(LongPrimitive) as sumLong from MyWindow group by TheString",
                path);
            statement = env.Statement(stmtName);
        }
Пример #25
0
 public string AddIndex(
     string[] indexProperties,
     Type[] coercionTypes,
     EventType eventType)
 {
     var uuid = UuidGenerator.Generate();
     Items.Put(
         new TableLookupIndexReqKey(uuid, null),
         new QueryPlanIndexItemForge(
             indexProperties,
             coercionTypes,
             new string[0],
             new Type[0],
             false,
             null,
             eventType));
     return uuid;
 }
Пример #26
0
        private void ScheduleNextCallback()
        {
            var nextScheduleCallback = new ProxyScheduleHandleCallback(delegate { ContinueSendingEvents(); });
            var spi           = (EPRuntimeSPI)_runtime;
            var deploymentId  = "CSV-adapter-" + UuidGenerator.Generate();
            var metricsHandle = spi.ServicesContext.MetricReportingService.GetStatementHandle(-1, deploymentId, "AbstractCoordinatedAdapter");
            var lockImpl      = _container.RWLockManager().CreateLock("CSV");
            var stmtHandle    = new EPStatementHandle(
                "AbstractCoordinatedAdapter", deploymentId, -1, null, 0, false, false,
                spi.ServicesContext.MultiMatchHandlerFactory.Make(false, false), false, false, metricsHandle, null, null);
            var agentInstanceHandle = new EPStatementAgentInstanceHandle(stmtHandle, -1, lockImpl);
            var scheduleCSVHandle   = new EPStatementHandleCallbackSchedule(agentInstanceHandle, nextScheduleCallback);

            long nextScheduleSlot;

            if (EventsToSend.IsEmpty())
            {
                if ((ExecutionPathDebugLog.IsDebugEnabled) && (Log.IsDebugEnabled))
                {
                    Log.Debug(".scheduleNextCallback no events to send, scheduling callback in 100 ms");
                }
                nextScheduleSlot = 0L;
                _schedulingService.Add(100, scheduleCSVHandle, nextScheduleSlot);
            }
            else
            {
                // Offset is not a function of the currentTime alone.
                var  first     = EventsToSend.First();
                long baseMsec  = _currentTime - _startTime;
                long afterMsec = first.SendTime - baseMsec;
                nextScheduleSlot = first.ScheduleSlot;
                if ((ExecutionPathDebugLog.IsDebugEnabled) && (Log.IsDebugEnabled))
                {
                    Log.Debug(".scheduleNextCallback schedulingCallback in " + afterMsec + " milliseconds");
                }
                _schedulingService.Add(afterMsec, scheduleCSVHandle, nextScheduleSlot);
            }
        }
Пример #27
0
        private static void RecursiveCompile(
            EvalFactoryNode evalNode,
            StatementContext context,
            ExprEvaluatorContext evaluatorContext,
            ICollection <string> eventTypeReferences,
            bool isInsertInto,
            MatchEventSpec tags,
            Deque <int> subexpressionIdStack,
            Stack <EvalFactoryNode> parentNodeStack,
            ICollection <string> allTagNamesOrdered)
        {
            var counter = 0;

            parentNodeStack.Push(evalNode);
            foreach (var child in evalNode.ChildNodes)
            {
                subexpressionIdStack.AddLast(counter++);
                RecursiveCompile(
                    child, context, evaluatorContext, eventTypeReferences, isInsertInto, tags, subexpressionIdStack,
                    parentNodeStack, allTagNamesOrdered);
                subexpressionIdStack.RemoveLast();
            }
            parentNodeStack.Pop();

            LinkedHashMap <string, Pair <EventType, string> > newTaggedEventTypes = null;
            LinkedHashMap <string, Pair <EventType, string> > newArrayEventTypes  = null;

            if (evalNode is EvalFilterFactoryNode)
            {
                var filterNode = (EvalFilterFactoryNode)evalNode;
                var eventName  = filterNode.RawFilterSpec.EventTypeName;
                if (context.TableService.GetTableMetadata(eventName) != null)
                {
                    throw new ExprValidationException("Tables cannot be used in pattern filter atoms");
                }

                var resolvedEventType = FilterStreamSpecRaw.ResolveType(
                    context.EngineURI, eventName, context.EventAdapterService, context.PlugInTypeResolutionURIs);
                var finalEventType       = resolvedEventType;
                var optionalTag          = filterNode.EventAsName;
                var isPropertyEvaluation = false;
                var isParentMatchUntil   = IsParentMatchUntil(evalNode, parentNodeStack);

                // obtain property event type, if final event type is properties
                if (filterNode.RawFilterSpec.OptionalPropertyEvalSpec != null)
                {
                    var optionalPropertyEvaluator =
                        PropertyEvaluatorFactory.MakeEvaluator(
                            context.Container,
                            filterNode.RawFilterSpec.OptionalPropertyEvalSpec,
                            resolvedEventType,
                            filterNode.EventAsName,
                            context.EventAdapterService,
                            context.EngineImportService,
                            context.SchedulingService,
                            context.VariableService,
                            context.ScriptingService,
                            context.TableService,
                            context.EngineURI,
                            context.StatementId,
                            context.StatementName,
                            context.Annotations,
                            subexpressionIdStack,
                            context.ConfigSnapshot,
                            context.NamedWindowMgmtService,
                            context.StatementExtensionServicesContext);
                    finalEventType       = optionalPropertyEvaluator.FragmentEventType;
                    isPropertyEvaluation = true;
                }

                if (finalEventType is EventTypeSPI)
                {
                    eventTypeReferences.Add(((EventTypeSPI)finalEventType).Metadata.PrimaryName);
                }

                // If a tag was supplied for the type, the tags must stay with this type, i.e. a=BeanA -> b=BeanA -> a=BeanB is a no
                if (optionalTag != null)
                {
                    var       pair         = tags.TaggedEventTypes.Get(optionalTag);
                    EventType existingType = null;
                    if (pair != null)
                    {
                        existingType = pair.First;
                    }
                    if (existingType == null)
                    {
                        pair = tags.ArrayEventTypes.Get(optionalTag);
                        if (pair != null)
                        {
                            throw new ExprValidationException(
                                      "Tag '" + optionalTag + "' for event '" + eventName +
                                      "' used in the repeat-until operator cannot also appear in other filter expressions");
                        }
                    }
                    if ((existingType != null) && (existingType != finalEventType))
                    {
                        throw new ExprValidationException(
                                  "Tag '" + optionalTag + "' for event '" + eventName +
                                  "' has already been declared for events of type " + existingType.UnderlyingType.FullName);
                    }
                    pair = new Pair <EventType, string>(finalEventType, eventName);

                    // add tagged type
                    if (isPropertyEvaluation || isParentMatchUntil)
                    {
                        newArrayEventTypes = new LinkedHashMap <string, Pair <EventType, string> >();
                        newArrayEventTypes.Put(optionalTag, pair);
                    }
                    else
                    {
                        newTaggedEventTypes = new LinkedHashMap <string, Pair <EventType, string> >();
                        newTaggedEventTypes.Put(optionalTag, pair);
                    }
                }

                // For this filter, filter types are all known tags at this time,
                // and additionally stream 0 (self) is our event type.
                // Stream type service allows resolution by property name event if that name appears in other tags.
                // by defaulting to stream zero.
                // Stream zero is always the current event type, all others follow the order of the map (stream 1 to N).
                var selfStreamName = optionalTag;
                if (selfStreamName == null)
                {
                    selfStreamName = "s_" + UuidGenerator.Generate();
                }
                var filterTypes = new LinkedHashMap <string, Pair <EventType, string> >();
                var typePair    = new Pair <EventType, string>(finalEventType, eventName);
                filterTypes.Put(selfStreamName, typePair);
                filterTypes.PutAll(tags.TaggedEventTypes);

                // for the filter, specify all tags used
                var filterTaggedEventTypes = new LinkedHashMap <string, Pair <EventType, string> >(tags.TaggedEventTypes);
                filterTaggedEventTypes.Remove(optionalTag);

                // handle array tags (match-until clause)
                LinkedHashMap <string, Pair <EventType, string> > arrayCompositeEventTypes = null;
                if (tags.ArrayEventTypes != null && !tags.ArrayEventTypes.IsEmpty())
                {
                    arrayCompositeEventTypes = new LinkedHashMap <string, Pair <EventType, string> >();
                    var patternSubexEventType = GetPatternSubexEventType(
                        context.StatementId, "pattern", subexpressionIdStack);

                    foreach (var entry in tags.ArrayEventTypes)
                    {
                        var specificArrayType = new LinkedHashMap <string, Pair <EventType, string> >();
                        specificArrayType.Put(entry.Key, entry.Value);
                        var arrayTagCompositeEventType =
                            context.EventAdapterService.CreateSemiAnonymousMapType(
                                patternSubexEventType, Collections.GetEmptyMap <string, Pair <EventType, string> >(),
                                specificArrayType, isInsertInto);
                        context.StatementSemiAnonymousTypeRegistry.Register(arrayTagCompositeEventType);

                        var tag = entry.Key;
                        if (!filterTypes.ContainsKey(tag))
                        {
                            var pair = new Pair <EventType, string>(arrayTagCompositeEventType, tag);
                            filterTypes.Put(tag, pair);
                            arrayCompositeEventTypes.Put(tag, pair);
                        }
                    }
                }

                StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                    filterTypes, context.EngineURI, true, false);
                var exprNodes = filterNode.RawFilterSpec.FilterExpressions;

                var spec = FilterSpecCompiler.MakeFilterSpec(
                    resolvedEventType, eventName, exprNodes,
                    filterNode.RawFilterSpec.OptionalPropertyEvalSpec,
                    filterTaggedEventTypes,
                    arrayCompositeEventTypes,
                    streamTypeService,
                    null, context, subexpressionIdStack);
                filterNode.FilterSpec = spec;
            }
            else if (evalNode is EvalObserverFactoryNode)
            {
                var observerNode = (EvalObserverFactoryNode)evalNode;
                try
                {
                    var observerFactory = context.PatternResolutionService.Create(observerNode.PatternObserverSpec);

                    var streamTypeService = GetStreamTypeService(
                        context.EngineURI, context.StatementId, context.EventAdapterService, tags.TaggedEventTypes,
                        tags.ArrayEventTypes, subexpressionIdStack, "observer", context);
                    var validationContext = new ExprValidationContext(
                        context.Container,
                        streamTypeService,
                        context.EngineImportService,
                        context.StatementExtensionServicesContext, null,
                        context.SchedulingService,
                        context.VariableService,
                        context.TableService, evaluatorContext,
                        context.EventAdapterService,
                        context.StatementName,
                        context.StatementId,
                        context.Annotations,
                        context.ContextDescriptor,
                        context.ScriptingService,
                        false, false, false, false, null, false);
                    var validated = ValidateExpressions(
                        ExprNodeOrigin.PATTERNOBSERVER, observerNode.PatternObserverSpec.ObjectParameters,
                        validationContext);

                    MatchedEventConvertor convertor = new MatchedEventConvertorImpl(
                        tags.TaggedEventTypes, tags.ArrayEventTypes, allTagNamesOrdered, context.EventAdapterService);

                    observerNode.ObserverFactory = observerFactory;
                    observerFactory.SetObserverParameters(validated, convertor, validationContext);
                }
                catch (ObserverParameterException e)
                {
                    throw new ExprValidationException(
                              "Invalid parameter for pattern observer '" + observerNode.ToPrecedenceFreeEPL() + "': " +
                              e.Message, e);
                }
                catch (PatternObjectException e)
                {
                    throw new ExprValidationException(
                              "Failed to resolve pattern observer '" + observerNode.ToPrecedenceFreeEPL() + "': " + e.Message,
                              e);
                }
            }
            else if (evalNode is EvalGuardFactoryNode)
            {
                var guardNode = (EvalGuardFactoryNode)evalNode;
                try
                {
                    var guardFactory = context.PatternResolutionService.Create(guardNode.PatternGuardSpec);

                    var streamTypeService = GetStreamTypeService(
                        context.EngineURI, context.StatementId, context.EventAdapterService, tags.TaggedEventTypes,
                        tags.ArrayEventTypes, subexpressionIdStack, "guard", context);
                    var validationContext = new ExprValidationContext(
                        context.Container,
                        streamTypeService,
                        context.EngineImportService,
                        context.StatementExtensionServicesContext, null,
                        context.SchedulingService,
                        context.VariableService,
                        context.TableService, evaluatorContext,
                        context.EventAdapterService,
                        context.StatementName,
                        context.StatementId,
                        context.Annotations,
                        context.ContextDescriptor,
                        context.ScriptingService,
                        false, false, false, false, null, false);
                    var validated = ValidateExpressions(
                        ExprNodeOrigin.PATTERNGUARD, guardNode.PatternGuardSpec.ObjectParameters, validationContext);

                    MatchedEventConvertor convertor = new MatchedEventConvertorImpl(
                        tags.TaggedEventTypes, tags.ArrayEventTypes, allTagNamesOrdered, context.EventAdapterService);

                    guardNode.GuardFactory = guardFactory;
                    guardFactory.SetGuardParameters(validated, convertor);
                }
                catch (GuardParameterException e)
                {
                    throw new ExprValidationException(
                              "Invalid parameter for pattern guard '" + guardNode.ToPrecedenceFreeEPL() + "': " + e.Message, e);
                }
                catch (PatternObjectException e)
                {
                    throw new ExprValidationException(
                              "Failed to resolve pattern guard '" + guardNode.ToPrecedenceFreeEPL() + "': " + e.Message, e);
                }
            }
            else if (evalNode is EvalEveryDistinctFactoryNode)
            {
                var distinctNode             = (EvalEveryDistinctFactoryNode)evalNode;
                var matchEventFromChildNodes = AnalyzeMatchEvent(distinctNode);
                var streamTypeService        = GetStreamTypeService(
                    context.EngineURI, context.StatementId, context.EventAdapterService,
                    matchEventFromChildNodes.TaggedEventTypes, matchEventFromChildNodes.ArrayEventTypes,
                    subexpressionIdStack, "every-distinct", context);
                var validationContext = new ExprValidationContext(
                    context.Container,
                    streamTypeService,
                    context.EngineImportService,
                    context.StatementExtensionServicesContext, null,
                    context.SchedulingService,
                    context.VariableService,
                    context.TableService, evaluatorContext,
                    context.EventAdapterService,
                    context.StatementName,
                    context.StatementId,
                    context.Annotations,
                    context.ContextDescriptor,
                    context.ScriptingService,
                    false, false, false, false, null, false);
                IList <ExprNode> validated;
                try
                {
                    validated = ValidateExpressions(
                        ExprNodeOrigin.PATTERNEVERYDISTINCT, distinctNode.Expressions, validationContext);
                }
                catch (ExprValidationPropertyException ex)
                {
                    throw new ExprValidationPropertyException(
                              ex.Message +
                              ", every-distinct requires that all properties resolve from sub-expressions to the every-distinct",
                              ex.InnerException);
                }

                MatchedEventConvertor convertor =
                    new MatchedEventConvertorImpl(
                        matchEventFromChildNodes.TaggedEventTypes, matchEventFromChildNodes.ArrayEventTypes,
                        allTagNamesOrdered, context.EventAdapterService);

                distinctNode.Convertor = convertor;

                // Determine whether some expressions are constants or time period
                IList <ExprNode>             distinctExpressions  = new List <ExprNode>();
                ExprTimePeriodEvalDeltaConst timeDeltaComputation = null;
                ExprNode expiryTimeExp = null;
                var      count         = -1;
                var      last          = validated.Count - 1;
                foreach (var expr in validated)
                {
                    count++;
                    if (count == last && expr is ExprTimePeriod)
                    {
                        expiryTimeExp = expr;
                        var timePeriodExpr = (ExprTimePeriod)expiryTimeExp;
                        timeDeltaComputation =
                            timePeriodExpr.ConstEvaluator(new ExprEvaluatorContextStatement(context, false));
                    }
                    else if (expr.IsConstantResult)
                    {
                        if (count == last)
                        {
                            var evaluateParams = new EvaluateParams(null, true, evaluatorContext);
                            var value          = expr.ExprEvaluator.Evaluate(evaluateParams);
                            if (!(value.IsNumber()))
                            {
                                throw new ExprValidationException(
                                          "Invalid parameter for every-distinct, expected number of seconds constant (constant not considered for distinct)");
                            }

                            var secondsExpire = expr.ExprEvaluator.Evaluate(evaluateParams);

                            long?timeExpire;
                            if (secondsExpire == null)
                            {
                                timeExpire = null;
                            }
                            else
                            {
                                timeExpire = context.TimeAbacus.DeltaForSecondsNumber(secondsExpire);
                            }

                            if (timeExpire != null && timeExpire > 0)
                            {
                                timeDeltaComputation = new ExprTimePeriodEvalDeltaConstGivenDelta(timeExpire.Value);
                                expiryTimeExp        = expr;
                            }
                            else
                            {
                                Log.Warn("Invalid seconds-expire " + timeExpire + " for " + ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(expr));
                            }
                        }
                        else
                        {
                            Log.Warn(
                                "Every-distinct node utilizes an expression returning a constant value, please check expression '{0}', not adding expression to distinct-value expression list",
                                expr.ToExpressionStringMinPrecedenceSafe());
                        }
                    }
                    else
                    {
                        distinctExpressions.Add(expr);
                    }
                }
                if (distinctExpressions.IsEmpty())
                {
                    throw new ExprValidationException(
                              "Every-distinct node requires one or more distinct-value expressions that each return non-constant result values");
                }
                distinctNode.SetDistinctExpressions(distinctExpressions, timeDeltaComputation, expiryTimeExp);
            }
            else if (evalNode is EvalMatchUntilFactoryNode)
            {
                var matchUntilNode = (EvalMatchUntilFactoryNode)evalNode;

                // compile bounds expressions, if any
                var untilMatchEventSpec = new MatchEventSpec(tags.TaggedEventTypes, tags.ArrayEventTypes);
                var streamTypeService   = GetStreamTypeService(
                    context.EngineURI, context.StatementId, context.EventAdapterService,
                    untilMatchEventSpec.TaggedEventTypes, untilMatchEventSpec.ArrayEventTypes, subexpressionIdStack,
                    "until", context);
                var validationContext = new ExprValidationContext(
                    context.Container,
                    streamTypeService,
                    context.EngineImportService,
                    context.StatementExtensionServicesContext, null,
                    context.SchedulingService,
                    context.VariableService,
                    context.TableService, evaluatorContext,
                    context.EventAdapterService,
                    context.StatementName,
                    context.StatementId,
                    context.Annotations,
                    context.ContextDescriptor,
                    context.ScriptingService,
                    false, false, false, false, null, false);

                var lower = ValidateBounds(matchUntilNode.LowerBounds, validationContext);
                matchUntilNode.LowerBounds = lower;

                var upper = ValidateBounds(matchUntilNode.UpperBounds, validationContext);
                matchUntilNode.UpperBounds = upper;

                var single = ValidateBounds(matchUntilNode.SingleBound, validationContext);
                matchUntilNode.SingleBound = single;

                var convertor = new MatchedEventConvertorImpl(
                    untilMatchEventSpec.TaggedEventTypes, untilMatchEventSpec.ArrayEventTypes, allTagNamesOrdered,
                    context.EventAdapterService);
                matchUntilNode.Convertor = convertor;

                // compile new tag lists
                ISet <string> arrayTags = null;
                var           matchUntilAnalysisResult = EvalNodeUtil.RecursiveAnalyzeChildNodes(matchUntilNode.ChildNodes[0]);
                foreach (var filterNode in matchUntilAnalysisResult.FilterNodes)
                {
                    var optionalTag = filterNode.EventAsName;
                    if (optionalTag != null)
                    {
                        if (arrayTags == null)
                        {
                            arrayTags = new HashSet <string>();
                        }
                        arrayTags.Add(optionalTag);
                    }
                }

                if (arrayTags != null)
                {
                    foreach (var arrayTag in arrayTags)
                    {
                        if (!tags.ArrayEventTypes.ContainsKey(arrayTag))
                        {
                            tags.ArrayEventTypes.Put(arrayTag, tags.TaggedEventTypes.Get(arrayTag));
                            tags.TaggedEventTypes.Remove(arrayTag);
                        }
                    }
                }
                matchUntilNode.TagsArrayed = GetIndexesForTags(allTagNamesOrdered, arrayTags);
            }
            else if (evalNode is EvalFollowedByFactoryNode)
            {
                var followedByNode = (EvalFollowedByFactoryNode)evalNode;
                StreamTypeService streamTypeService = new StreamTypeServiceImpl(context.EngineURI, false);
                var validationContext = new ExprValidationContext(
                    context.Container,
                    streamTypeService,
                    context.EngineImportService,
                    context.StatementExtensionServicesContext, null,
                    context.SchedulingService,
                    context.VariableService,
                    context.TableService,
                    evaluatorContext,
                    context.EventAdapterService,
                    context.StatementName,
                    context.StatementId,
                    context.Annotations,
                    context.ContextDescriptor,
                    context.ScriptingService,
                    false, false, false, false, null, false);

                if (followedByNode.OptionalMaxExpressions != null)
                {
                    IList <ExprNode> validated = new List <ExprNode>();
                    foreach (var maxExpr in followedByNode.OptionalMaxExpressions)
                    {
                        if (maxExpr == null)
                        {
                            validated.Add(null);
                        }
                        else
                        {
                            var visitor = new ExprNodeSummaryVisitor();
                            maxExpr.Accept(visitor);
                            if (!visitor.IsPlain)
                            {
                                var errorMessage = "Invalid maximum expression in followed-by, " + visitor.GetMessage() +
                                                   " are not allowed within the expression";
                                Log.Error(errorMessage);
                                throw new ExprValidationException(errorMessage);
                            }

                            var validatedExpr = ExprNodeUtility.GetValidatedSubtree(
                                ExprNodeOrigin.FOLLOWEDBYMAX, maxExpr, validationContext);
                            validated.Add(validatedExpr);
                            if ((validatedExpr.ExprEvaluator.ReturnType == null) ||
                                (!validatedExpr.ExprEvaluator.ReturnType.IsNumeric()))
                            {
                                var message = "Invalid maximum expression in followed-by, the expression must return an integer value";
                                throw new ExprValidationException(message);
                            }
                        }
                    }
                    followedByNode.OptionalMaxExpressions = validated;
                }
            }

            if (newTaggedEventTypes != null)
            {
                tags.TaggedEventTypes.PutAll(newTaggedEventTypes);
            }
            if (newArrayEventTypes != null)
            {
                tags.ArrayEventTypes.PutAll(newArrayEventTypes);
            }
        }
Пример #28
0
        public void FaultyOverflowPagesHandling_CannotModifyReadOnlyPages(int initialNumberOfDocs, int numberOfModifications, int seed)
        {
            const string documents = "documents";
            const string keyByEtag = "documents_key_by_etag";
            const string metadata  = "documents_metadata";

            var inMemoryKeysByEtag = new Dictionary <Guid, string>();
            var inMemoryKeys       = new HashSet <string>();
            var r             = new Random(seed);
            var uuidGenerator = new UuidGenerator();

            using (var tx = Env.WriteTransaction())
            {
                var docsTree     = tx.CreateTree(documents);
                var metadataTree = tx.CreateTree(metadata);
                var indexTree    = tx.CreateTree(keyByEtag);

                for (int i = 0; i < initialNumberOfDocs; i++)
                {
                    var etag   = uuidGenerator.CreateSequentialUuid();
                    var docKey = get_id(etag, r);

                    put_doc(r, etag, inMemoryKeysByEtag, inMemoryKeys, docKey, docsTree, metadataTree, indexTree);
                }

                tx.Commit();
            }

            for (int i = 0; i < numberOfModifications; i++)
            {
                using (var tx = Env.WriteTransaction())
                {
                    var docsTree     = tx.ReadTree(documents);
                    var metadataTree = tx.ReadTree(metadata);
                    var indexTree    = tx.ReadTree(keyByEtag);

                    if (r.Next(3) == 0)
                    {
                        // insert new
                        var etag   = uuidGenerator.CreateSequentialUuid();
                        var docKey = get_id(etag, r);

                        put_doc(r, etag, inMemoryKeysByEtag, inMemoryKeys, docKey, docsTree, metadataTree, indexTree);
                    }
                    else
                    {
                        // update existing
                        var docCount = inMemoryKeysByEtag.Values.Count;

                        var docKeyToUpdate = inMemoryKeysByEtag.Values.Skip(r.Next(0, docCount - 1)).First();
                        var etag           = uuidGenerator.CreateSequentialUuid();

                        put_doc(r, etag, inMemoryKeysByEtag, inMemoryKeys, docKeyToUpdate, docsTree, metadataTree, indexTree);
                    }

                    tx.Commit();
                }
            }

            using (var tx = Env.ReadTransaction())
            {
                var docsTree      = tx.ReadTree(documents);
                var metadataTree  = tx.ReadTree(metadata);
                var keyByEtagTree = tx.ReadTree(keyByEtag);

                var count = 0;
                using (var iterator = keyByEtagTree.Iterate(false))
                {
                    iterator.Seek(Slices.BeforeAllKeys);
                    do
                    {
                        var etag = Guid.Parse(iterator.CurrentKey.ToString());

                        var reader = iterator.CreateReaderForCurrent();

                        var key = reader.ReadString(reader.Length);

                        var inMemoryKey = inMemoryKeysByEtag[etag];

                        Assert.Equal(inMemoryKey, key);

                        var docReadResult = docsTree.Read(key);

                        Assert.NotNull(docReadResult);

                        var metadataReader = metadataTree.Read(key).Reader;

                        Assert.NotNull(metadataReader);

                        var etagFromMetadata = new byte[16];
                        metadataReader.Read(etagFromMetadata, 0, 16);

                        var readEtag = new Guid(etagFromMetadata);


                        Assert.Equal(etag, readEtag);

                        count++;
                    }while (iterator.MoveNext());
                }

                Assert.Equal(inMemoryKeysByEtag.Count, count);
            }
        }
Пример #29
0
        private static void RecursiveCompile(
            EvalForgeNode evalNode,
            ISet<string> eventTypeReferences,
            bool isInsertInto,
            MatchEventSpec tags,
            Stack<EvalForgeNode> parentNodeStack,
            ISet<string> allTagNamesOrdered,
            int streamNum,
            StatementRawInfo statementRawInfo,
            StatementCompileTimeServices services)
        {
            parentNodeStack.Push(evalNode);
            foreach (var child in evalNode.ChildNodes) {
                RecursiveCompile(
                    child,
                    eventTypeReferences,
                    isInsertInto,
                    tags,
                    parentNodeStack,
                    allTagNamesOrdered,
                    streamNum,
                    statementRawInfo,
                    services);
            }

            parentNodeStack.Pop();

            IDictionary<string, Pair<EventType, string>> newTaggedEventTypes = null;
            IDictionary<string, Pair<EventType, string>> newArrayEventTypes = null;

            if (evalNode is EvalFilterForgeNode) {
                var filterNode = (EvalFilterForgeNode) evalNode;
                var eventName = filterNode.RawFilterSpec.EventTypeName;
                if (services.TableCompileTimeResolver.Resolve(eventName) != null) {
                    throw new ExprValidationException("Tables cannot be used in pattern filter atoms");
                }

                var resolvedEventType = ResolveTypeName(eventName, services.EventTypeCompileTimeResolver);
                var finalEventType = resolvedEventType;
                var optionalTag = filterNode.EventAsName;
                var isPropertyEvaluation = false;
                var isParentMatchUntil = IsParentMatchUntil(evalNode, parentNodeStack);

                // obtain property event type, if final event type is properties
                if (filterNode.RawFilterSpec.OptionalPropertyEvalSpec != null) {
                    var optionalPropertyEvaluator = PropertyEvaluatorForgeFactory.MakeEvaluator(
                        filterNode.RawFilterSpec.OptionalPropertyEvalSpec,
                        resolvedEventType,
                        filterNode.EventAsName,
                        statementRawInfo,
                        services);
                    finalEventType = optionalPropertyEvaluator.FragmentEventType;
                    isPropertyEvaluation = true;
                }

                // If a tag was supplied for the type, the tags must stay with this type, i.e. a=BeanA -> b=BeanA -> a=BeanB is a no
                if (optionalTag != null) {
                    var pair = tags.TaggedEventTypes.Get(optionalTag);
                    EventType existingType = null;
                    if (pair != null) {
                        existingType = pair.First;
                    }

                    if (existingType == null) {
                        pair = tags.ArrayEventTypes.Get(optionalTag);
                        if (pair != null) {
                            throw new ExprValidationException(
                                "Tag '" +
                                optionalTag +
                                "' for event '" +
                                eventName +
                                "' used in the repeat-until operator cannot also appear in other filter expressions");
                        }
                    }

                    if (existingType != null && existingType != finalEventType) {
                        throw new ExprValidationException(
                            "Tag '" +
                            optionalTag +
                            "' for event '" +
                            eventName +
                            "' has already been declared for events of type " +
                            existingType.UnderlyingType.Name);
                    }

                    pair = new Pair<EventType, string>(finalEventType, eventName);

                    // add tagged type
                    if (isPropertyEvaluation || isParentMatchUntil) {
                        newArrayEventTypes = new LinkedHashMap<string, Pair<EventType, string>>();
                        newArrayEventTypes.Put(optionalTag, pair);
                    }
                    else {
                        newTaggedEventTypes = new LinkedHashMap<string, Pair<EventType, string>>();
                        newTaggedEventTypes.Put(optionalTag, pair);
                    }
                }

                // For this filter, filter types are all known tags at this time,
                // and additionally stream 0 (self) is our event type.
                // Stream type service allows resolution by property name event if that name appears in other tags.
                // by defaulting to stream zero.
                // Stream zero is always the current event type, all others follow the order of the map (stream 1 to N).
                var selfStreamName = optionalTag;
                if (selfStreamName == null) {
                    selfStreamName = "s_" + UuidGenerator.Generate();
                }

                var filterTypes = new LinkedHashMap<string, Pair<EventType, string>>();
                var typePair = new Pair<EventType, string>(finalEventType, eventName);
                filterTypes.Put(selfStreamName, typePair);
                filterTypes.PutAll(tags.TaggedEventTypes);

                // for the filter, specify all tags used
                var filterTaggedEventTypes = new LinkedHashMap<string, Pair<EventType, string>>(tags.TaggedEventTypes);
                filterTaggedEventTypes.Remove(optionalTag);

                // handle array tags (match-until clause)
                IDictionary<string, Pair<EventType, string>> arrayCompositeEventTypes = null;
                if (tags.ArrayEventTypes != null && !tags.ArrayEventTypes.IsEmpty()) {
                    arrayCompositeEventTypes = new LinkedHashMap<string, Pair<EventType, string>>();

                    foreach (var entry in tags.ArrayEventTypes) {
                        var specificArrayType = new LinkedHashMap<string, Pair<EventType, string>>();
                        specificArrayType.Put(entry.Key, entry.Value);

                        var eventTypeName = services.EventTypeNameGeneratorStatement.GetAnonymousPatternNameWTag(
                            streamNum,
                            evalNode.FactoryNodeId,
                            entry.Key);
                        var mapProps = GetMapProperties(
                            Collections.GetEmptyMap<string, Pair<EventType, string>>(),
                            specificArrayType);
                        var metadata = new EventTypeMetadata(
                            eventTypeName,
                            statementRawInfo.ModuleName,
                            EventTypeTypeClass.PATTERNDERIVED,
                            EventTypeApplicationType.MAP,
                            NameAccessModifier.TRANSIENT,
                            EventTypeBusModifier.NONBUS,
                            false,
                            EventTypeIdPair.Unassigned());
                        var mapEventType = BaseNestableEventUtil.MakeMapTypeCompileTime(
                            metadata,
                            mapProps,
                            null,
                            null,
                            null,
                            null,
                            services.BeanEventTypeFactoryPrivate,
                            services.EventTypeCompileTimeResolver);
                        services.EventTypeCompileTimeRegistry.NewType(mapEventType);

                        var tag = entry.Key;
                        if (!filterTypes.ContainsKey(tag)) {
                            var pair = new Pair<EventType, string>(mapEventType, tag);
                            filterTypes.Put(tag, pair);
                            arrayCompositeEventTypes.Put(tag, pair);
                        }
                    }
                }

                StreamTypeService streamTypeService = new StreamTypeServiceImpl(filterTypes, true, false);
                var exprNodes = filterNode.RawFilterSpec.FilterExpressions;

                var spec = FilterSpecCompiler.MakeFilterSpec(
                    resolvedEventType,
                    eventName,
                    exprNodes,
                    filterNode.RawFilterSpec.OptionalPropertyEvalSpec,
                    filterTaggedEventTypes,
                    arrayCompositeEventTypes,
                    streamTypeService,
                    null,
                    statementRawInfo,
                    services);
                filterNode.FilterSpec = spec;
            }
            else if (evalNode is EvalObserverForgeNode) {
                var observerNode = (EvalObserverForgeNode) evalNode;
                try {
                    var observerForge =
                        services.PatternResolutionService.Create(observerNode.PatternObserverSpec);

                    var streamTypeService = GetStreamTypeService(
                        tags.TaggedEventTypes,
                        tags.ArrayEventTypes,
                        observerNode,
                        streamNum,
                        statementRawInfo,
                        services);
                    var validationContext = new ExprValidationContextBuilder(
                        streamTypeService,
                        statementRawInfo,
                        services).Build();
                    var validated = ValidateExpressions(
                        ExprNodeOrigin.PATTERNOBSERVER,
                        observerNode.PatternObserverSpec.ObjectParameters,
                        validationContext);

                    var convertor = new MatchedEventConvertorForge(
                        tags.TaggedEventTypes,
                        tags.ArrayEventTypes,
                        allTagNamesOrdered);

                    observerNode.ObserverFactory = observerForge;
                    observerForge.SetObserverParameters(validated, convertor, validationContext);
                }
                catch (ObserverParameterException e) {
                    throw new ExprValidationException(
                        "Invalid parameter for pattern observer '" +
                        observerNode.ToPrecedenceFreeEPL() +
                        "': " +
                        e.Message,
                        e);
                }
                catch (PatternObjectException e) {
                    throw new ExprValidationException(
                        "Failed to resolve pattern observer '" + observerNode.ToPrecedenceFreeEPL() + "': " + e.Message,
                        e);
                }
            }
            else if (evalNode is EvalGuardForgeNode) {
                var guardNode = (EvalGuardForgeNode) evalNode;
                try {
                    var guardForge = services.PatternResolutionService.Create(guardNode.PatternGuardSpec);

                    var streamTypeService = GetStreamTypeService(
                        tags.TaggedEventTypes,
                        tags.ArrayEventTypes,
                        guardNode,
                        streamNum,
                        statementRawInfo,
                        services);
                    var validationContext = new ExprValidationContextBuilder(
                        streamTypeService,
                        statementRawInfo,
                        services).Build();
                    var validated = ValidateExpressions(
                        ExprNodeOrigin.PATTERNGUARD,
                        guardNode.PatternGuardSpec.ObjectParameters,
                        validationContext);

                    var convertor = new MatchedEventConvertorForge(
                        tags.TaggedEventTypes,
                        tags.ArrayEventTypes,
                        allTagNamesOrdered);

                    guardNode.GuardForge = guardForge;
                    guardForge.SetGuardParameters(validated, convertor, services);
                }
                catch (GuardParameterException e) {
                    throw new ExprValidationException(
                        "Invalid parameter for pattern guard '" + guardNode.ToPrecedenceFreeEPL() + "': " + e.Message,
                        e);
                }
                catch (PatternObjectException e) {
                    throw new ExprValidationException(
                        "Failed to resolve pattern guard '" + guardNode.ToPrecedenceFreeEPL() + "': " + e.Message,
                        e);
                }
            }
            else if (evalNode is EvalEveryDistinctForgeNode) {
                var distinctNode = (EvalEveryDistinctForgeNode) evalNode;
                var matchEventFromChildNodes = AnalyzeMatchEvent(distinctNode);
                var streamTypeService = GetStreamTypeService(
                    matchEventFromChildNodes.TaggedEventTypes,
                    matchEventFromChildNodes.ArrayEventTypes,
                    distinctNode,
                    streamNum,
                    statementRawInfo,
                    services);
                var validationContext =
                    new ExprValidationContextBuilder(streamTypeService, statementRawInfo, services).Build();
                IList<ExprNode> validated;
                try {
                    validated = ValidateExpressions(
                        ExprNodeOrigin.PATTERNEVERYDISTINCT,
                        distinctNode.Expressions,
                        validationContext);
                }
                catch (ExprValidationPropertyException ex) {
                    throw new ExprValidationPropertyException(
                        ex.Message +
                        ", every-distinct requires that all properties resolve from sub-expressions to the every-distinct",
                        ex.InnerException);
                }

                var convertor = new MatchedEventConvertorForge(
                    matchEventFromChildNodes.TaggedEventTypes,
                    matchEventFromChildNodes.ArrayEventTypes,
                    allTagNamesOrdered);

                distinctNode.Convertor = convertor;

                // Determine whether some expressions are constants or time period
                IList<ExprNode> distinctExpressions = new List<ExprNode>();
                TimePeriodComputeForge timePeriodComputeForge = null;
                ExprNode expiryTimeExp = null;
                var count = -1;
                var last = validated.Count - 1;
                foreach (var expr in validated) {
                    count++;
                    if (count == last && expr is ExprTimePeriod) {
                        expiryTimeExp = expr;
                        var timePeriodExpr = (ExprTimePeriod) expiryTimeExp;
                        timePeriodComputeForge = timePeriodExpr.TimePeriodComputeForge;
                    }
                    else if (expr.Forge.ForgeConstantType.IsCompileTimeConstant) {
                        if (count == last) {
                            var value = expr.Forge.ExprEvaluator.Evaluate(null, true, null);
                            if (!value.IsNumber()) {
                                throw new ExprValidationException(
                                    "Invalid parameter for every-distinct, expected number of seconds constant (constant not considered for distinct)");
                            }

                            var secondsExpire = expr.Forge.ExprEvaluator.Evaluate(null, true, null);
                            var timeExpire = secondsExpire == null
                                ? (long?) null
                                : (long?) services.ImportServiceCompileTime.TimeAbacus.DeltaForSecondsNumber(
                                    secondsExpire);
                            if (timeExpire != null && timeExpire > 0) {
                                timePeriodComputeForge = new TimePeriodComputeConstGivenDeltaForge(timeExpire.Value);
                                expiryTimeExp = expr;
                            }
                            else {
                                Log.Warn(
                                    "Invalid seconds-expire " +
                                    timeExpire +
                                    " for " +
                                    ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(expr));
                            }
                        }
                        else {
                            Log.Warn(
                                "Every-distinct node utilizes an expression returning a constant value, please check expression '" +
                                ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(expr) +
                                "', not adding expression to distinct-value expression list");
                        }
                    }
                    else {
                        distinctExpressions.Add(expr);
                    }
                }

                if (distinctExpressions.IsEmpty()) {
                    throw new ExprValidationException(
                        "Every-distinct node requires one or more distinct-value expressions that each return non-constant result values");
                }

                distinctNode.SetDistinctExpressions(distinctExpressions, timePeriodComputeForge, expiryTimeExp);
            }
            else if (evalNode is EvalMatchUntilForgeNode) {
                var matchUntilNode = (EvalMatchUntilForgeNode) evalNode;

                // compile bounds expressions, if any
                var untilMatchEventSpec = new MatchEventSpec(tags.TaggedEventTypes, tags.ArrayEventTypes);
                var streamTypeService = GetStreamTypeService(
                    untilMatchEventSpec.TaggedEventTypes,
                    untilMatchEventSpec.ArrayEventTypes,
                    matchUntilNode,
                    streamNum,
                    statementRawInfo,
                    services);
                var validationContext =
                    new ExprValidationContextBuilder(streamTypeService, statementRawInfo, services).Build();

                var lower = ValidateBounds(matchUntilNode.LowerBounds, validationContext);
                matchUntilNode.LowerBounds = lower;

                var upper = ValidateBounds(matchUntilNode.UpperBounds, validationContext);
                matchUntilNode.UpperBounds = upper;

                var single = ValidateBounds(matchUntilNode.SingleBound, validationContext);
                matchUntilNode.SingleBound = single;

                bool tightlyBound;
                if (matchUntilNode.SingleBound != null) {
                    ValidateMatchUntil(matchUntilNode.SingleBound, matchUntilNode.SingleBound, false);
                    tightlyBound = true;
                }
                else {
                    var allowZeroLowerBounds = matchUntilNode.LowerBounds != null && matchUntilNode.UpperBounds != null;
                    tightlyBound = ValidateMatchUntil(
                        matchUntilNode.LowerBounds,
                        matchUntilNode.UpperBounds,
                        allowZeroLowerBounds);
                }

                if (matchUntilNode.SingleBound == null && !tightlyBound && matchUntilNode.ChildNodes.Count < 2) {
                    throw new ExprValidationException("Variable bounds repeat operator requires an until-expression");
                }

                var convertor = new MatchedEventConvertorForge(
                    untilMatchEventSpec.TaggedEventTypes,
                    untilMatchEventSpec.ArrayEventTypes,
                    allTagNamesOrdered);

                matchUntilNode.Convertor = convertor;

                // compile new tag lists
                ISet<string> arrayTags = null;
                var matchUntilAnalysisResult = EvalNodeUtil.RecursiveAnalyzeChildNodes(matchUntilNode.ChildNodes[0]);
                foreach (var filterNode in matchUntilAnalysisResult.FilterNodes) {
                    var optionalTag = filterNode.EventAsName;
                    if (optionalTag != null) {
                        if (arrayTags == null) {
                            arrayTags = new HashSet<string>();
                        }

                        arrayTags.Add(optionalTag);
                    }
                }

                if (arrayTags != null) {
                    foreach (var arrayTag in arrayTags) {
                        if (!tags.ArrayEventTypes.ContainsKey(arrayTag)) {
                            tags.ArrayEventTypes.Put(arrayTag, tags.TaggedEventTypes.Get(arrayTag));
                            tags.TaggedEventTypes.Remove(arrayTag);
                        }
                    }
                }

                matchUntilNode.TagsArrayedSet = GetIndexesForTags(allTagNamesOrdered, arrayTags);
            }
            else if (evalNode is EvalFollowedByForgeNode) {
                var followedByNode = (EvalFollowedByForgeNode) evalNode;
                StreamTypeService streamTypeService = new StreamTypeServiceImpl(false);
                var validationContext =
                    new ExprValidationContextBuilder(streamTypeService, statementRawInfo, services).Build();

                if (followedByNode.OptionalMaxExpressions != null) {
                    IList<ExprNode> validated = new List<ExprNode>();
                    foreach (var maxExpr in followedByNode.OptionalMaxExpressions) {
                        if (maxExpr == null) {
                            validated.Add(null);
                        }
                        else {
                            var visitor = new ExprNodeSummaryVisitor();
                            maxExpr.Accept(visitor);
                            if (!visitor.IsPlain) {
                                var errorMessage = "Invalid maximum expression in followed-by, " +
                                                   visitor.Message +
                                                   " are not allowed within the expression";
                                Log.Error(errorMessage);
                                throw new ExprValidationException(errorMessage);
                            }

                            var validatedExpr = ExprNodeUtilityValidate.GetValidatedSubtree(
                                ExprNodeOrigin.FOLLOWEDBYMAX,
                                maxExpr,
                                validationContext);
                            validated.Add(validatedExpr);
                            var returnType = validatedExpr.Forge.EvaluationType;
                            if (returnType == null || !returnType.IsNumeric()) {
                                var message =
                                    "Invalid maximum expression in followed-by, the expression must return an integer value";
                                throw new ExprValidationException(message);
                            }
                        }
                    }

                    followedByNode.OptionalMaxExpressions = validated;
                }
            }

            if (newTaggedEventTypes != null) {
                tags.TaggedEventTypes.PutAll(newTaggedEventTypes);
            }

            if (newArrayEventTypes != null) {
                tags.ArrayEventTypes.PutAll(newArrayEventTypes);
            }
        }
Пример #30
0
        public void FaultyOverflowPagesHandling_CannotModifyReadOnlyPages(int initialNumberOfDocs, int numberOfModifications, int seed)
        {
            const string documents = "documents";
            const string keyByEtag = "documents_key_by_etag";
            const string metadata = "documents_metadata";

            var inMemoryKeysByEtag = new Dictionary<Guid, string>();
            var inMemoryKeys = new HashSet<string>();
            var r = new Random(seed);
            var uuidGenerator = new UuidGenerator();

            using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
            {
                var docsTree = Env.CreateTree(tx, documents);
                var metadataTree = Env.CreateTree(tx, metadata);
                var indexTree = Env.CreateTree(tx, keyByEtag);

                for (int i = 0; i < initialNumberOfDocs; i++)
                {
                    var etag = uuidGenerator.CreateSequentialUuid();
                    var docKey = get_id(etag, r);

                    put_doc(r, etag, inMemoryKeysByEtag, inMemoryKeys, docKey, docsTree, metadataTree, indexTree);
                }

                tx.Commit();
            }

            for (int i = 0; i < numberOfModifications; i++)
            {
                using (var tx = Env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    var docsTree = tx.ReadTree(documents);
                    var metadataTree = tx.ReadTree(metadata);
                    var indexTree = tx.ReadTree(keyByEtag);

                    if (r.Next(3) == 0)
                    {
                        // insert new
                        var etag = uuidGenerator.CreateSequentialUuid();
                        var docKey = get_id(etag, r);

                        put_doc(r, etag, inMemoryKeysByEtag, inMemoryKeys, docKey, docsTree, metadataTree, indexTree);
                    }
                    else
                    {
                        // update existing
                        var docCount = inMemoryKeysByEtag.Values.Count;

                        var docKeyToUpdate = inMemoryKeysByEtag.Values.Skip(r.Next(0, docCount - 1)).First();
                        var etag = uuidGenerator.CreateSequentialUuid();

                        put_doc(r, etag, inMemoryKeysByEtag, inMemoryKeys, docKeyToUpdate, docsTree, metadataTree, indexTree);
                    }

                    tx.Commit();
                }
            }

            using (var tx = Env.NewTransaction(TransactionFlags.Read))
            {
                var docsTree = tx.ReadTree(documents);
                var metadataTree = tx.ReadTree(metadata);

                var reader = new SnapshotReader(tx);
                var count = 0;
                using (var iterator = reader.Iterate(keyByEtag))
                {
                    iterator.Seek(Slice.BeforeAllKeys);
                    do
                    {
                        var etag = Guid.Parse(iterator.CurrentKey.ToString());

                        string key;
                        using (var currentDataStream = iterator.CreateReaderForCurrent().AsStream())
                        {
                            var keyBytes = currentDataStream.ReadData();
                            key = Encoding.UTF8.GetString(keyBytes);
                        }

                        var inMemoryKey = inMemoryKeysByEtag[etag];

                        Assert.Equal(inMemoryKey, key);

                        var docReadResult = docsTree.Read(key);

                        Assert.NotNull(docReadResult);

                        var metadataReader = metadataTree.Read(key).Reader;

                        Assert.NotNull(metadataReader);

                        var etagFromMetadata = new byte[16];
                        metadataReader.Read(etagFromMetadata, 0, 16);

                        var readEtag = new Guid(etagFromMetadata);
                        if (etag != readEtag)
                        {
                            string existingDocKey;
                            if (inMemoryKeysByEtag.TryGetValue(readEtag, out existingDocKey))
                            {
                                Console.WriteLine("Etag " + readEtag + " belongs to " + existingDocKey + " document");
                            }
                            else
                            {
                                Console.WriteLine("There is no document with etag " + readEtag);
                            }
                        }

                        Assert.Equal(etag, readEtag);

                        count++;
                    }
                    while (iterator.MoveNext());
                }

                Assert.Equal(inMemoryKeysByEtag.Count, count);
            }
        }
Пример #31
0
        /// <summary>
        /// Makes the property evaluator.
        /// </summary>
        /// <param name="spec">is the property specification</param>
        /// <param name="sourceEventType">the event type</param>
        /// <param name="optionalSourceStreamName">the source stream name</param>
        /// <param name="eventAdapterService">for event instances</param>
        /// <param name="engineImportService">The engine import service.</param>
        /// <param name="timeProvider">provides time</param>
        /// <param name="variableService">for resolving variables</param>
        /// <param name="scriptingService">The scripting service.</param>
        /// <param name="tableService">The table service.</param>
        /// <param name="engineURI">engine URI</param>
        /// <param name="statementId">The statement identifier.</param>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="annotations">The annotations.</param>
        /// <param name="assignedTypeNumberStack">The assigned type number stack.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="namedWindowMgmtService">The named window service.</param>
        /// <param name="statementExtensionSvcContext">The statement extension SVC context.</param>
        /// <returns>
        /// propert evaluator
        /// </returns>
        /// <exception cref="ExprValidationException">Missing @type(name) declaration providing the event type name of the return type for expression ' +
        /// ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(atom.SplitterExpression) + '
        /// or
        /// Event type by name ' + atom.OptionalResultEventType + ' could not be found
        /// or
        /// Event type ' + streamEventType.Name + ' underlying type  + streamEventType.UnderlyingType.Name +
        /// cannot be assigned a value of type  + returnType.GetTypeNameFullyQualPretty()
        /// or
        /// Return type of expression ' + ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(atom.SplitterExpression) + ' is ' + returnType.Name + ', expected an Iterable or array result
        /// or
        /// Property rename ' + rawStreamSpec.MaskTypeName + ' not found in path
        /// or
        /// Expression in a property-selection may not utilize  + isMinimal</exception>
        /// <exception cref="IllegalStateException">Unknown select clause item: + raw</exception>
        /// <throws>ExprValidationException if any expressions could not be verified</throws>
        public static PropertyEvaluator MakeEvaluator(
            PropertyEvalSpec spec,
            EventType sourceEventType,
            string optionalSourceStreamName,
            EventAdapterService eventAdapterService,
            EngineImportService engineImportService,
            TimeProvider timeProvider,
            VariableService variableService,
            ScriptingService scriptingService,
            TableService tableService,
            string engineURI,
            int statementId,
            string statementName,
            Attribute[] annotations,
            ICollection <int> assignedTypeNumberStack,
            ConfigurationInformation configuration,
            NamedWindowMgmtService namedWindowMgmtService,
            StatementExtensionSvcContext statementExtensionSvcContext)
        {
            var length = spec.Atoms.Count;
            var containedEventEvals = new ContainedEventEval[length];
            var fragmentEventTypes  = new FragmentEventType[length];
            var currentEventType    = sourceEventType;
            var whereClauses        = new ExprEvaluator[length];

            var streamEventTypes    = new List <EventType>();
            var streamNames         = new List <string>();
            var streamNameAndNumber = new Dictionary <string, int>().WithNullSupport();
            var expressionTexts     = new List <string>();
            var validateContext     = new ExprEvaluatorContextTimeOnly(timeProvider);

            streamEventTypes.Add(sourceEventType);
            streamNames.Add(optionalSourceStreamName);
            streamNameAndNumber.Put(optionalSourceStreamName, 0);
            expressionTexts.Add(sourceEventType.Name);

            IList <SelectClauseElementCompiled> cumulativeSelectClause = new List <SelectClauseElementCompiled>();

            for (var i = 0; i < length; i++)
            {
                var atom = spec.Atoms[i];
                ContainedEventEval containedEventEval = null;
                string             expressionText     = null;
                EventType          streamEventType    = null;
                FragmentEventType  fragmentEventType  = null;

                // Resolve directly as fragment event type if possible
                if (atom.SplitterExpression is ExprIdentNode)
                {
                    var propertyName = ((ExprIdentNode)atom.SplitterExpression).FullUnresolvedName;
                    fragmentEventType = currentEventType.GetFragmentType(propertyName);
                    if (fragmentEventType != null)
                    {
                        var getter = currentEventType.GetGetter(propertyName);
                        if (getter != null)
                        {
                            containedEventEval = new ContainedEventEvalGetter(getter);
                            expressionText     = propertyName;
                            streamEventType    = fragmentEventType.FragmentType;
                        }
                    }
                }

                // evaluate splitter expression
                if (containedEventEval == null)
                {
                    ExprNodeUtility.ValidatePlainExpression(
                        ExprNodeOrigin.CONTAINEDEVENT,
                        ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(atom.SplitterExpression),
                        atom.SplitterExpression);

                    var availableTypes       = streamEventTypes.ToArray();
                    var availableStreamNames = streamNames.ToArray();
                    var isIStreamOnly        = new bool[streamNames.Count];
                    isIStreamOnly.Fill(true);
                    StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                        availableTypes, availableStreamNames, isIStreamOnly, engineURI, false);
                    var validationContext = new ExprValidationContext(
                        streamTypeService, engineImportService, statementExtensionSvcContext, null, timeProvider, variableService, tableService,
                        validateContext, eventAdapterService, statementName, statementId, annotations, null, scriptingService,
                        false, false, true, false, null, false);
                    var validatedExprNode = ExprNodeUtility.GetValidatedSubtree(
                        ExprNodeOrigin.CONTAINEDEVENT, atom.SplitterExpression, validationContext);
                    var evaluator = validatedExprNode.ExprEvaluator;

                    // determine result type
                    if (atom.OptionalResultEventType == null)
                    {
                        throw new ExprValidationException(
                                  "Missing @type(name) declaration providing the event type name of the return type for expression '" +
                                  ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(atom.SplitterExpression) + "'");
                    }
                    streamEventType = eventAdapterService.GetEventTypeByName(atom.OptionalResultEventType);
                    if (streamEventType == null)
                    {
                        throw new ExprValidationException(
                                  "Event type by name '" + atom.OptionalResultEventType + "' could not be found");
                    }

                    var returnType = evaluator.ReturnType;

                    // when the expression returns an array, allow array values to become the column of the single-column event type
                    if (returnType.IsArray &&
                        streamEventType.PropertyNames.Length == 1 &&
                        TypeHelper.IsSubclassOrImplementsInterface(
                            TypeHelper.GetBoxedType(returnType.GetElementType()),
                            TypeHelper.GetBoxedType(streamEventType.GetPropertyType(streamEventType.PropertyNames[0]))))
                    {
                        var writables = eventAdapterService.GetWriteableProperties(streamEventType, false);
                        if (!writables.IsEmpty())
                        {
                            try
                            {
                                EventBeanManufacturer manufacturer = EventAdapterServiceHelper.GetManufacturer(
                                    eventAdapterService, streamEventType,
                                    new WriteablePropertyDescriptor[] { writables.First() },
                                    engineImportService, false,
                                    eventAdapterService.EventAdapterAvroHandler);
                                containedEventEval = new ContainedEventEvalArrayToEvent(evaluator, manufacturer);
                            }
                            catch (EventBeanManufactureException e)
                            {
                                throw new ExprValidationException(
                                          "Event type '" + streamEventType.Name + "' cannot be populated: " + e.Message, e);
                            }
                        }
                        else
                        {
                            throw new ExprValidationException("Event type '" + streamEventType.Name + "' cannot be written to");
                        }
                    }
                    else if (returnType.IsArray() && returnType.GetElementType() == typeof(EventBean))
                    {
                        containedEventEval = new ContainedEventEvalEventBeanArray(evaluator);
                    }
                    else
                    {
                        EventBeanFactory eventBeanFactory = EventAdapterServiceHelper.GetFactoryForType(
                            streamEventType, eventAdapterService);
                        // check expression result type against eventtype expected underlying type
                        if (returnType.IsArray())
                        {
                            if (!TypeHelper.IsSubclassOrImplementsInterface(returnType.GetElementType(), streamEventType.UnderlyingType))
                            {
                                throw new ExprValidationException(
                                          "Event type '" + streamEventType.Name + "' underlying type " +
                                          streamEventType.UnderlyingType.FullName +
                                          " cannot be assigned a value of type " + TypeHelper.GetTypeNameFullyQualPretty(returnType));
                            }
                        }
                        else if (GenericExtensions.IsGenericEnumerable(returnType) || returnType.IsImplementsInterface <IEnumerable>())
                        {
                            // fine, assumed to return the right type
                        }
                        else
                        {
                            throw new ExprValidationException(
                                      "Return type of expression '" +
                                      ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(atom.SplitterExpression) + "' is '" +
                                      returnType.FullName + "', expected an Iterable or array result");
                        }
                        containedEventEval = new ContainedEventEvalExprNode(evaluator, eventBeanFactory);
                    }
                    expressionText    = ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(validatedExprNode);
                    fragmentEventType = new FragmentEventType(streamEventType, true, false);
                }

                // validate where clause, if any
                streamEventTypes.Add(streamEventType);
                streamNames.Add(atom.OptionalAsName);
                streamNameAndNumber.Put(atom.OptionalAsName, i + 1);
                expressionTexts.Add(expressionText);

                if (atom.OptionalWhereClause != null)
                {
                    var whereTypes       = streamEventTypes.ToArray();
                    var whereStreamNames = streamNames.ToArray();
                    var isIStreamOnly    = new bool[streamNames.Count];
                    isIStreamOnly.Fill(true);
                    StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                        whereTypes, whereStreamNames, isIStreamOnly, engineURI, false);
                    var validationContext = new ExprValidationContext(
                        streamTypeService, engineImportService, statementExtensionSvcContext, null, timeProvider, variableService, tableService,
                        validateContext, eventAdapterService, statementName, statementId, annotations, null, scriptingService,
                        false, false, true, false, null, false);
                    whereClauses[i] =
                        ExprNodeUtility.GetValidatedSubtree(
                            ExprNodeOrigin.CONTAINEDEVENT, atom.OptionalWhereClause, validationContext).ExprEvaluator;
                }

                // validate select clause
                if (atom.OptionalSelectClause != null)
                {
                    var whereTypes       = streamEventTypes.ToArray();
                    var whereStreamNames = streamNames.ToArray();
                    var isIStreamOnly    = new bool[streamNames.Count];
                    isIStreamOnly.Fill(true);
                    StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                        whereTypes, whereStreamNames, isIStreamOnly, engineURI, false);
                    var validationContext = new ExprValidationContext(
                        streamTypeService, engineImportService, statementExtensionSvcContext, null, timeProvider, variableService, tableService,
                        validateContext, eventAdapterService, statementName, statementId, annotations, null, scriptingService,
                        false, false, true, false, null, false);

                    foreach (var raw in atom.OptionalSelectClause.SelectExprList)
                    {
                        if (raw is SelectClauseStreamRawSpec)
                        {
                            var rawStreamSpec = (SelectClauseStreamRawSpec)raw;
                            if (!streamNames.Contains(rawStreamSpec.StreamName))
                            {
                                throw new ExprValidationException(
                                          "Property rename '" + rawStreamSpec.StreamName + "' not found in path");
                            }
                            var streamSpec = new SelectClauseStreamCompiledSpec(
                                rawStreamSpec.StreamName, rawStreamSpec.OptionalAsName);
                            int streamNumber = streamNameAndNumber.Get(rawStreamSpec.StreamName);
                            streamSpec.StreamNumber = streamNumber;
                            cumulativeSelectClause.Add(streamSpec);
                        }
                        else if (raw is SelectClauseExprRawSpec)
                        {
                            var exprSpec     = (SelectClauseExprRawSpec)raw;
                            var exprCompiled = ExprNodeUtility.GetValidatedSubtree(
                                ExprNodeOrigin.CONTAINEDEVENT, exprSpec.SelectExpression, validationContext);
                            var resultName = exprSpec.OptionalAsName;
                            if (resultName == null)
                            {
                                resultName = ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(exprCompiled);
                            }
                            cumulativeSelectClause.Add(
                                new SelectClauseExprCompiledSpec(
                                    exprCompiled, resultName, exprSpec.OptionalAsName, exprSpec.IsEvents));

                            var isMinimal = ExprNodeUtility.IsMinimalExpression(exprCompiled);
                            if (isMinimal != null)
                            {
                                throw new ExprValidationException(
                                          "Expression in a property-selection may not utilize " + isMinimal);
                            }
                        }
                        else if (raw is SelectClauseElementWildcard)
                        {
                            // wildcards are stream selects: we assign a stream name (any) and add a stream wildcard select
                            var streamNameAtom = atom.OptionalAsName;
                            if (streamNameAtom == null)
                            {
                                streamNameAtom = UuidGenerator.Generate();
                            }

                            var streamSpec   = new SelectClauseStreamCompiledSpec(streamNameAtom, atom.OptionalAsName);
                            var streamNumber = i + 1;
                            streamSpec.StreamNumber = streamNumber;
                            cumulativeSelectClause.Add(streamSpec);
                        }
                        else
                        {
                            throw new IllegalStateException("Unknown select clause item:" + raw);
                        }
                    }
                }

                currentEventType       = fragmentEventType.FragmentType;
                fragmentEventTypes[i]  = fragmentEventType;
                containedEventEvals[i] = containedEventEval;
            }

            if (cumulativeSelectClause.IsEmpty())
            {
                if (length == 1)
                {
                    return(new PropertyEvaluatorSimple(
                               containedEventEvals[0], fragmentEventTypes[0], whereClauses[0], expressionTexts[0]));
                }
                else
                {
                    return(new PropertyEvaluatorNested(containedEventEvals, fragmentEventTypes, whereClauses, expressionTexts));
                }
            }
            else
            {
                var accumulative = new PropertyEvaluatorAccumulative(
                    containedEventEvals, fragmentEventTypes, whereClauses, expressionTexts);

                var whereTypes       = streamEventTypes.ToArray();
                var whereStreamNames = streamNames.ToArray();
                var isIStreamOnly    = new bool[streamNames.Count];
                isIStreamOnly.Fill(true);
                StreamTypeService streamTypeService = new StreamTypeServiceImpl(
                    whereTypes, whereStreamNames, isIStreamOnly, engineURI, false);

                var cumulativeSelectArr = cumulativeSelectClause.ToArray();
                var selectExpr          = SelectExprProcessorFactory.GetProcessor(
                    assignedTypeNumberStack, cumulativeSelectArr, false, null, null, null, streamTypeService,
                    eventAdapterService, null, null, null, engineImportService, validateContext, variableService,
                    scriptingService,
                    tableService, timeProvider, engineURI, statementId, statementName, annotations, null, configuration, null,
                    namedWindowMgmtService, null, null, statementExtensionSvcContext);
                return(new PropertyEvaluatorSelect(selectExpr, accumulative));
            }
        }