public void TestHashSegmentedMulti()
        {
            var ctx    = "HashSegmentedContext";
            var eplCtx = "@Name('context') create context " + ctx + " as " +
                         "coalesce " +
                         " Consistent_hash_crc32(TheString) from SupportBean, " +
                         " Consistent_hash_crc32(p00) from SupportBean_S0 " +
                         "granularity 4 " +
                         "preallocate";

            _epService.EPAdministrator.CreateEPL(eplCtx);
            var codeFunc = new SupportHashCodeFuncGranularCRC32(4);

            var eplStmt = "context " + ctx + " " +
                          "select context.name as c0, IntPrimitive as c1, id as c2 from SupportBean.win:keepall() as t1, SupportBean_S0.win:keepall() as t2 where t1.TheString = t2.p00";
            var statement = (EPStatementSPI)_epService.EPAdministrator.CreateEPL(eplStmt);

            statement.Events += _listener.Update;

            var fields = "c0,c1,c2".Split(',');

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 10));
            _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E2"));
            _epService.EPRuntime.SendEvent(new SupportBean("E3", 11));
            _epService.EPRuntime.SendEvent(new SupportBean_S0(2, "E4"));
            Assert.IsFalse(_listener.IsInvoked);

            _epService.EPRuntime.SendEvent(new SupportBean_S0(3, "E1"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { ctx, 10, 3 });
            AssertIterator(statement, fields, new Object[][] { new Object[] { ctx, 10, 3 } });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(4, "E4"));
            _epService.EPRuntime.SendEvent(new SupportBean_S0(5, "E5"));
            Assert.IsFalse(_listener.IsInvoked);

            _epService.EPRuntime.SendEvent(new SupportBean("E2", 12));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { ctx, 12, 1 });
            AssertIterator(statement, fields, new Object[][] { new Object[] { ctx, 10, 3 }, new Object[] { ctx, 12, 1 } });
        }
Exemple #2
0
        private void RunAssertionHashSegmented(EPServiceProvider epService)
        {
            // Comment-in to see CRC32 code.
            for (int i = 0; i < 10; i++)
            {
                string key      = "E" + i;
                long   code     = SupportHashCodeFuncGranularCRC32.ComputeCrc32(key) % 4;
                int    hashCode = i.GetHashCode() % 4;
                //Log.Info(key + " code " + code + " hashCode " + hashCode);
            }

            // test CRC32 Hash
            FilterServiceSPI filterSPI = (FilterServiceSPI)((EPServiceProviderSPI)epService).FilterService;
            string           ctx       = "HashSegmentedContext";
            string           eplCtx    = "@Name('context') create context " + ctx + " as " +
                                         "coalesce consistent_hash_crc32(TheString) from SupportBean " +
                                         "granularity 4 " +
                                         "preallocate";

            epService.EPAdministrator.CreateEPL(eplCtx);

            string eplStmt = "context " + ctx + " " +
                             "select context.name as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString";
            EPStatementSPI statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL(eplStmt);
            var            listener  = new SupportUpdateListener();

            statement.Events += listener.Update;
            Assert.AreEqual(4, filterSPI.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 4, 0, 0, 0);

            TryAssertionHash(epService, listener, ctx, statement, new SupportHashCodeFuncGranularCRC32(4).CodeFor);
            Assert.AreEqual(0, filterSPI.FilterCountApprox);

            // test same with SODA
            EPStatementObjectModel modelCtx = epService.EPAdministrator.CompileEPL(eplCtx);

            Assert.AreEqual(eplCtx, modelCtx.ToEPL());
            EPStatement stmtCtx = epService.EPAdministrator.Create(modelCtx);

            Assert.AreEqual(eplCtx, stmtCtx.Text);

            statement         = (EPStatementSPI)epService.EPAdministrator.CreateEPL(eplStmt);
            statement.Events += listener.Update;
            TryAssertionHash(epService, listener, ctx, statement, new SupportHashCodeFuncGranularCRC32(4).CodeFor);

            // test with Java-hashCode string hash
            epService.EPAdministrator.CreateEPL("@Name('context') create context " + ctx + " " +
                                                "coalesce hash_code(TheString) from SupportBean " +
                                                "granularity 6 " +
                                                "preallocate");

            statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL("context " + ctx + " " +
                                                                            "select context.name as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString");
            statement.Events += listener.Update;
            Assert.AreEqual(6, filterSPI.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 6, 0, 0, 0);

            TryAssertionHash(epService, listener, ctx, statement, HashCodeFuncGranularInternalHash(6));
            Assert.AreEqual(0, filterSPI.FilterCountApprox);

            // test no pre-allocate
            epService.EPAdministrator.CreateEPL("@Name('context') create context " + ctx + " " +
                                                "coalesce hash_code(TheString) from SupportBean " +
                                                "granularity 16 ");

            statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL("context " + ctx + " " +
                                                                            "select context.name as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString");
            statement.Events += listener.Update;
            Assert.AreEqual(1, filterSPI.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 0, 0, 0, 0);

            TryAssertionHash(epService, listener, ctx, statement, HashCodeFuncGranularInternalHash(16));
            Assert.AreEqual(0, filterSPI.FilterCountApprox);
        }
        public void TestHashSegmented()
        {
            // Comment-in to see CRC32 code.
            for (var i = 0; i < 10; i++)
            {
                var key      = "E" + i;
                var code     = SupportHashCodeFuncGranularCRC32.ComputeCRC32(key) % 4;
                var hashCode = i.GetHashCode() % 4;
                //Console.WriteLine(key + " code " + code + " hashCode " + hashCode);
            }

            // test CRC32 Hash
            var filterSPI = (FilterServiceSPI)_spi.FilterService;
            var ctx       = "HashSegmentedContext";
            var eplCtx    = "@Name('context') create context " + ctx + " as " +
                            "coalesce Consistent_hash_crc32(TheString) from SupportBean " +
                            "granularity 4 " +
                            "preallocate";

            _epService.EPAdministrator.CreateEPL(eplCtx);

            var eplStmt = "context " + ctx + " " +
                          "select context.name as c0, TheString as c1, Sum(IntPrimitive) as c2 from SupportBean.win:keepall() group by TheString";
            var statement = (EPStatementSPI)_epService.EPAdministrator.CreateEPL(eplStmt);

            statement.Events += _listener.Update;
            Assert.AreEqual(4, filterSPI.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 4, 0, 0, 0);

            RunAssertionHash(ctx, statement, new SupportHashCodeFuncGranularCRC32(4));
            Assert.AreEqual(0, filterSPI.FilterCountApprox);

            // test same with SODA
            var modelCtx = _epService.EPAdministrator.CompileEPL(eplCtx);

            Assert.AreEqual(eplCtx, modelCtx.ToEPL());
            var stmtCtx = _epService.EPAdministrator.Create(modelCtx);

            Assert.AreEqual(eplCtx, stmtCtx.Text);

            statement         = (EPStatementSPI)_epService.EPAdministrator.CreateEPL(eplStmt);
            statement.Events += _listener.Update;
            RunAssertionHash(ctx, statement, new SupportHashCodeFuncGranularCRC32(4));

            // test with GetHashCode String hash
            _epService.EPAdministrator.CreateEPL("@Name('context') create context " + ctx + " " +
                                                 "coalesce Hash_code(TheString) from SupportBean " +
                                                 "granularity 6 " +
                                                 "preallocate");

            statement = (EPStatementSPI)_epService.EPAdministrator.CreateEPL("context " + ctx + " " +
                                                                             "select context.name as c0, TheString as c1, Sum(IntPrimitive) as c2 from SupportBean.win:keepall() group by TheString");
            statement.Events += _listener.Update;
            Assert.AreEqual(6, filterSPI.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 6, 0, 0, 0);

            RunAssertionHash(ctx, statement, new HashCodeFuncGranularInternalHash(6));
            Assert.AreEqual(0, filterSPI.FilterCountApprox);

            // test no pre-allocate
            _epService.EPAdministrator.CreateEPL("@Name('context') create context " + ctx + " " +
                                                 "coalesce Hash_code(TheString) from SupportBean " +
                                                 "granularity 16 ");

            statement = (EPStatementSPI)_epService.EPAdministrator.CreateEPL("context " + ctx + " " +
                                                                             "select context.name as c0, TheString as c1, Sum(IntPrimitive) as c2 from SupportBean.win:keepall() group by TheString");
            statement.Events += _listener.Update;
            Assert.AreEqual(1, filterSPI.FilterCountApprox);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 0, 0, 0, 0);

            RunAssertionHash(ctx, statement, new HashCodeFuncGranularInternalHash(16));
            Assert.AreEqual(0, filterSPI.FilterCountApprox);
        }