Ejemplo n.º 1
0
 /// <summary>Ctor. </summary>
 /// <param name="functionName">provides the aggregation multi-function name</param>
 /// <param name="distinct">flag whether the "distinct" keyword was provided.</param>
 /// <param name="engineURI">the engine URI</param>
 /// <param name="configuration">the configuration provided when the aggregation multi-functions where registered</param>
 public PlugInAggregationMultiFunctionDeclarationContext(String functionName, bool distinct, String engineURI, ConfigurationPlugInAggregationMultiFunction configuration)
 {
     FunctionName  = functionName;
     IsDistinct    = distinct;
     EngineURI     = engineURI;
     Configuration = configuration;
 }
        public override void Configure(Configuration configuration)
        {
            var config = new ConfigurationPlugInAggregationMultiFunction(SupportAggMFFuncExtensions.GetFunctionNames(), typeof(SupportAggMFFactory));

            configuration.AddPlugInAggregationMultiFunction(config);
            configuration.AddEventType <SupportBean>();
        }
Ejemplo n.º 3
0
        public void TestInvalidAggMatchMultiFunc()
        {
            // Window and related
            //

            // window vs agg method
            TryInvalidAggMatch("var1", "window(*) @type(SupportBean)", true, "avg(IntPrimitive)",
                               "Error starting statement: Incompatible aggregation function for table 'var1' column 'value', expecting 'window(*)' and received 'avg(IntPrimitive)': Not a 'window' aggregation [");
            // window vs sorted
            TryInvalidAggMatch("var1", "window(*) @type(SupportBean)", true, "sorted(IntPrimitive)",
                               "Error starting statement: Failed to validate select-clause expression 'sorted(IntPrimitive)': When specifying into-table a sort expression cannot be provided [");
            // wrong type
            TryInvalidAggMatch("var1", "window(*) @type(SupportBean_S0)", true, "window(*)",
                               "Error starting statement: Incompatible aggregation function for table 'var1' column 'value', expecting 'window(*)' and received 'window(*)': The required event type is 'SupportBean_S0' and provided is 'SupportBean' [");

            // sorted
            //
            TryInvalidAggMatch("var1", "sorted(IntPrimitive) @type(SupportBean)", true, "window(*)",
                               "Error starting statement: Incompatible aggregation function for table 'var1' column 'value', expecting 'sorted(IntPrimitive)' and received 'window(*)': Not a 'sorted' aggregation [");
            TryInvalidAggMatch("var1", "sorted(id) @type(SupportBean_S0)", true, "sorted(IntPrimitive)",
                               "Error starting statement: Failed to validate select-clause expression 'sorted(IntPrimitive)': When specifying into-table a sort expression cannot be provided [");

            // plug-in
            //
            ConfigurationPlugInAggregationMultiFunction config = new ConfigurationPlugInAggregationMultiFunction(SupportAggMFFuncExtensions.GetFunctionNames(), typeof(SupportAggMFFactory).FullName);

            _epService.EPAdministrator.Configuration.AddPlugInAggregationMultiFunction(config);
            TryInvalidAggMatch("var1", "se1() @type(SupportBean)", true, "window(*)",
                               "Error starting statement: Incompatible aggregation function for table 'var1' column 'value', expecting 'se1(*)' and received 'window(*)': Not a 'se1' aggregation [");
        }
Ejemplo n.º 4
0
        // Word counting using a reference-counting-map (similar: count-min-sketch approximation, this one is more limited)
        //
        // Use aggregation access multi-value when the aggregation must be asked a specific question to return a useful value.
        private void RunAssertionPlugInAccess_RefCountedMap(EPServiceProvider epService)
        {
            var config = new ConfigurationPlugInAggregationMultiFunction(
                "referenceCountedMap,referenceCountLookup".Split(','), typeof(ReferenceCountedMapMultiValueFactory));

            epService.EPAdministrator.Configuration.AddPlugInAggregationMultiFunction(config);

            epService.EPAdministrator
            .CreateEPL("create table varaggRCM (wordCount referenceCountedMap(string))");
            epService.EPAdministrator
            .CreateEPL("into table varaggRCM select referenceCountedMap(TheString) as wordCount from SupportBean#length(3)");
            var listener = new SupportUpdateListener();

            epService.EPAdministrator
            .CreateEPL("select varaggRCM.wordCount.referenceCountLookup(p00) as c0 from SupportBean_S0")
            .Events += listener.Update;

            string words = "the,house,is,green";

            SendWordAssert(epService, listener, "the", words, new int?[] { 1, null, null, null });
            SendWordAssert(epService, listener, "house", words, new int?[] { 1, 1, null, null });
            SendWordAssert(epService, listener, "the", words, new int?[] { 2, 1, null, null });
            SendWordAssert(epService, listener, "green", words, new int?[] { 1, 1, null, 1 });
            SendWordAssert(epService, listener, "is", words, new int?[] { 1, null, 1, 1 });
        }
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="distinct">flag indicating unique or non-unique value aggregation</param>
 /// <param name="config">The configuration.</param>
 /// <param name="pluginAggregationMultiFunctionFactory">the factory</param>
 /// <param name="functionName">is the aggregation function name</param>
 public ExprPlugInAggMultiFunctionNode(bool distinct, ConfigurationPlugInAggregationMultiFunction config, PlugInAggregationMultiFunctionFactory pluginAggregationMultiFunctionFactory, string functionName)
     : base(distinct)
 {
     _pluginAggregationMultiFunctionFactory = pluginAggregationMultiFunctionFactory;
     _functionName = functionName;
     _config       = config;
 }
Ejemplo n.º 6
0
 public void AddPlugInAggregationMultiFunction(ConfigurationPlugInAggregationMultiFunction config)
 {
     try {
         _engineImportService.AddAggregationMultiFunction(config);
     } catch (EngineImportException e) {
         throw new ConfigurationException(e.Message, e);
     }
 }
Ejemplo n.º 7
0
        private void RunAssertionUngroupedAggAdditionalAndPlugin()
        {
            _epService.EPAdministrator.Configuration.AddPlugInAggregationFunctionFactory("concatstring", typeof(MyConcatAggregationFunctionFactory).FullName);
            var mfAggConfig = new ConfigurationPlugInAggregationMultiFunction(SupportAggMFFuncExtensions.GetFunctionNames(), typeof(SupportAggMFFactory).FullName);

            _epService.EPAdministrator.Configuration.AddPlugInAggregationMultiFunction(mfAggConfig);

            var cols = "c0,c1,c2,c3,c4,c5,c8,c9,c10,c11,c12,c13".Split(',');
            var epl  = "select IntPrimitive, " +
                       " countever(*, IntPrimitive>0, group_by:(TheString)) as c0," +
                       " countever(*, IntPrimitive>0, group_by:()) as c1," +
                       " countever(*, group_by:(TheString)) as c2," +
                       " countever(*, group_by:()) as c3," +
                       " concatstring(Convert.ToString(IntPrimitive), group_by:(TheString)) as c4," +
                       " concatstring(Convert.ToString(IntPrimitive), group_by:()) as c5," +
                       " sc(IntPrimitive, group_by:(TheString)) as c6," +
                       " sc(IntPrimitive, group_by:()) as c7," +
                       " leaving(group_by:(TheString)) as c8," +
                       " leaving(group_by:()) as c9," +
                       " rate(3, group_by:(TheString)) as c10," +
                       " rate(3, group_by:()) as c11," +
                       " nth(IntPrimitive, 1, group_by:(TheString)) as c12," +
                       " nth(IntPrimitive, 1, group_by:()) as c13" +
                       " from SupportBean as sb";

            _epService.EPAdministrator.CreateEPL(epl).AddListener(_listener);

            MakeSendEvent("E1", 10);
            AssertScalarColl(_listener.LastNewData[0], new int?[] { 10 }, new int?[] { 10 });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), cols, new object[] { 1L, 1L, 1L, 1L, "10", "10", false, false,
                                                                                                  null, null, null, null });

            MakeSendEvent("E2", 20);
            AssertScalarColl(_listener.LastNewData[0], new int?[] { 20 }, new int?[] { 10, 20 });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), cols, new object[] { 1L, 2L, 1L, 2L, "20", "10 20", false, false,
                                                                                                  null, null, null, 10 });

            MakeSendEvent("E1", -1);
            AssertScalarColl(_listener.LastNewData[0], new int?[] { 10, -1 }, new int?[] { 10, 20, -1 });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), cols, new object[] { 1L, 2L, 2L, 3L, "10 -1", "10 20 -1", false, false,
                                                                                                  null, null, 10, 20 });

            MakeSendEvent("E2", 30);
            AssertScalarColl(_listener.LastNewData[0], new int?[] { 20, 30 }, new int?[] { 10, 20, -1, 30 });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), cols, new object[] { 2L, 3L, 2L, 4L, "20 30", "10 20 -1 30", false, false,
                                                                                                  null, null, 20, -1 });

            // plug-in aggregation function can also take other parameters
            _epService.EPAdministrator.CreateEPL("select sc(IntPrimitive, dummy:1)," +
                                                 "concatstring(Convert.ToString(IntPrimitive), dummy2:(1,2,3)) from SupportBean");

            _epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 8
0
        public void AddAggregationMultiFunction(ConfigurationPlugInAggregationMultiFunction desc)
        {
            var orderedImmutableFunctionNames = new LinkedHashSet <string>();

            foreach (var functionName in desc.FunctionNames)
            {
                orderedImmutableFunctionNames.Add(functionName.ToLowerInvariant());
                ValidateFunctionName("aggregation multi-function", functionName.ToLowerInvariant());
            }
            if (!IsTypeName(desc.MultiFunctionFactoryClassName))
            {
                throw new EngineImportException("Invalid class name for aggregation multi-function factory '" + desc.MultiFunctionFactoryClassName + "'");
            }
            _aggregationAccess.Add(new Pair <ISet <string>, ConfigurationPlugInAggregationMultiFunction>(orderedImmutableFunctionNames, desc));
        }
Ejemplo n.º 9
0
        public void SetUp()
        {
            var configuration = SupportConfigFactory.GetConfiguration();
            var config        = new ConfigurationPlugInAggregationMultiFunction(SupportAggMFFuncExtensions.GetFunctionNames(), typeof(SupportAggMFFactory).FullName);

            configuration.AddPlugInAggregationMultiFunction(config);

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            _listener = new SupportUpdateListener();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }
        }
Ejemplo n.º 10
0
        public void TestInvalid()
        {
            // add overlapping config with regular agg function
            try {
                _epService.EPAdministrator.Configuration.AddPlugInAggregationFunctionFactory(SupportAggMFFunc.SCALAR.GetName(), "somefactory");
                Assert.Fail();
            }
            catch (ConfigurationException ex) {
                Assert.AreEqual("Aggregation multi-function by name 'ss' is already defined", ex.Message);
            }

            // add overlapping config with regular agg function
            try {
                _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction(SupportAggMFFunc.SCALAR.GetName(), "somefactory", "somename");
                Assert.Fail();
            }
            catch (ConfigurationException ex) {
                Assert.AreEqual("Aggregation multi-function by name 'ss' is already defined", ex.Message);
            }

            // test over lapping with another multi-function
            var config = new ConfigurationPlugInAggregationMultiFunction("thefunction".Split(','), typeof(SupportAggMFFactory).FullName);

            _epService.EPAdministrator.Configuration.AddPlugInAggregationMultiFunction(config);
            try {
                var configTwo = new ConfigurationPlugInAggregationMultiFunction("xyz,gmbh,thefunction".Split(','), typeof(TestAggregationFunctionPlugIn).FullName);
                _epService.EPAdministrator.Configuration.AddPlugInAggregationMultiFunction(configTwo);
                Assert.Fail();
            }
            catch (ConfigurationException ex) {
                Assert.AreEqual("Aggregation multi-function by name 'thefunction' is already defined", ex.Message);
            }

            // test invalid class name
            try {
                var configTwo = new ConfigurationPlugInAggregationMultiFunction("thefunction2".Split(','), "x y z");
                _epService.EPAdministrator.Configuration.AddPlugInAggregationMultiFunction(configTwo);
                Assert.Fail();
            }
            catch (ConfigurationException ex) {
                Assert.AreEqual("Invalid class name for aggregation multi-function factory 'x y z'", ex.Message);
            }
        }
Ejemplo n.º 11
0
        public static ExprNode TryResolveAsAggregation(
            EngineImportService engineImportService,
            bool distinct,
            String functionName,
            LazyAllocatedMap <ConfigurationPlugInAggregationMultiFunction, PlugInAggregationMultiFunctionFactory> plugInAggregations,
            String engineURI)
        {
            try
            {
                AggregationFunctionFactory aggregationFactory = engineImportService.ResolveAggregationFactory(functionName);
                return(new ExprPlugInAggNode(distinct, aggregationFactory, functionName));
            }
            catch (EngineImportUndefinedException)
            {
                // Not an aggregation function
            }
            catch (EngineImportException e)
            {
                throw new IllegalStateException("Error resolving aggregation: " + e.Message, e);
            }

            // try plug-in aggregation multi-function
            ConfigurationPlugInAggregationMultiFunction config =
                engineImportService.ResolveAggregationMultiFunction(functionName);

            if (config != null)
            {
                PlugInAggregationMultiFunctionFactory factory = plugInAggregations.Map.Get(config);
                if (factory == null)
                {
                    factory = TypeHelper.Instantiate <PlugInAggregationMultiFunctionFactory>(
                        config.MultiFunctionFactoryClassName);
                    plugInAggregations.Map.Put(config, factory);
                }
                factory.AddAggregationFunction(
                    new PlugInAggregationMultiFunctionDeclarationContext(
                        functionName.ToLower(), distinct, engineURI, config));
                return(new ExprPlugInAggMultiFunctionNode(distinct, config, factory, functionName));
            }

            // try built-in expanded set of aggregation functions
            return(engineImportService.ResolveAggExtendedBuiltin(functionName, distinct));
        }
Ejemplo n.º 12
0
        public void TestPlugInAccess_RefCountedMap()
        {
            var config = new ConfigurationPlugInAggregationMultiFunction(
                "referenceCountedMap,referenceCountLookup".Split(','), typeof(ReferenceCountedMapMultiValueFactory).FullName);

            _epService.EPAdministrator.Configuration.AddPlugInAggregationMultiFunction(config);

            _epService.EPAdministrator.CreateEPL("create table varagg (wordCount referenceCountedMap(string))");
            _epService.EPAdministrator.CreateEPL("into table varagg select referenceCountedMap(TheString) as wordCount from SupportBean#length(3)");
            _epService.EPAdministrator.CreateEPL("select varagg.wordCount.referenceCountLookup(p00) as c0 from SupportBean_S0").AddListener(_listener);

            var words = "the,house,is,green";

            SendWordAssert("the", words, new int?[] { 1, null, null, null });
            SendWordAssert("house", words, new int?[] { 1, 1, null, null });
            SendWordAssert("the", words, new int?[] { 2, 1, null, null });
            SendWordAssert("green", words, new int?[] { 1, 1, null, 1 });
            SendWordAssert("is", words, new int?[] { 1, null, 1, 1 });
        }
        private void RunAssertionAccessAggPlugIn(EPServiceProvider epService)
        {
            var config = new ConfigurationPlugInAggregationMultiFunction();
            config.FunctionNames = "concatAccessAgg".Split(',');
            config.MultiFunctionFactoryClassName = typeof(MyAccessAggFactory).FullName;
            epService.EPAdministrator.Configuration.AddPlugInAggregationMultiFunction(config);

            var fields = "c0".Split(',');
            var epl = "select ConcatAccessAgg(TheString, filter:TheString like 'A%') as c0 from SupportBean";
            var stmt = epService.EPAdministrator.CreateEPL(epl);
            var listener = new SupportUpdateListener();
            stmt.Events += listener.Update;

            SendEventAssert(epService, listener, "X1", 0, fields, new object[] {""});
            SendEventAssert(epService, listener, "A1", 0, fields, new object[] {"A1"});
            SendEventAssert(epService, listener, "A2", 0, fields, new object[] {"A1A2"});
            SendEventAssert(epService, listener, "X2", 0, fields, new object[] {"A1A2"});

            stmt.Dispose();
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="functionName">the aggregation function name</param>
 /// <param name="eventTypes">the event types of all events in the select clause</param>
 /// <param name="parameterExpressions">the parameter expressions</param>
 /// <param name="engineURI">the engine URI</param>
 /// <param name="statementName">the statement name</param>
 /// <param name="validationContext">additional validation contextual services</param>
 /// <param name="config">the original configuration object for the aggregation multi-function</param>
 /// <param name="optionalTableColumnAccessed">The optional table column accessed.</param>
 /// <param name="allParameterExpressions">All parameter expressions.</param>
 public PlugInAggregationMultiFunctionValidationContext(
     string functionName,
     EventType[] eventTypes,
     ExprNode[] parameterExpressions,
     string engineURI,
     string statementName,
     ExprValidationContext validationContext,
     ConfigurationPlugInAggregationMultiFunction config,
     TableMetadataColumnAggregation optionalTableColumnAccessed,
     ExprNode[] allParameterExpressions)
 {
     FunctionName         = functionName;
     EventTypes           = eventTypes;
     ParameterExpressions = parameterExpressions;
     EngineURI            = engineURI;
     StatementName        = statementName;
     ValidationContext    = validationContext;
     Config = config;
     OptionalTableColumnAccessed = optionalTableColumnAccessed;
     AllParameterExpressions     = allParameterExpressions;
 }
 public PlugInAggregationMultiFunctionValidationContext(
     string functionName,
     EventType[] eventTypes,
     ExprNode[] parameterExpressions,
     string engineURI,
     string statementName,
     ExprValidationContext validationContext,
     ConfigurationPlugInAggregationMultiFunction config,
     TableMetadataColumnAggregation optionalTableColumnAccessed,
     IList <ExprNode> allParameterExpressions)
 {
     _functionName         = functionName;
     _eventTypes           = eventTypes;
     _parameterExpressions = parameterExpressions;
     _engineURI            = engineURI;
     _statementName        = statementName;
     _validationContext    = validationContext;
     _config = config;
     _optionalTableColumnAccessed = optionalTableColumnAccessed;
     _allParameterExpressions     = allParameterExpressions;
 }