public override void Configure(Configuration configuration)
        {
            _schemaUri = SupportContainer.Instance.ResourceManager().ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();

            var sensorcfg = new ConfigurationEventTypeXMLDOM();

            sensorcfg.RootElementName = "Sensor";
            sensorcfg.AddXPathProperty("countTags", "count(/ss:Sensor/ss:Observation/ss:Tag)", XPathResultType.Number);
            sensorcfg.AddXPathProperty("countTagsInt", "count(/ss:Sensor/ss:Observation/ss:Tag)", XPathResultType.Number, "int");
            sensorcfg.AddNamespacePrefix("ss", "SensorSchema");
            sensorcfg.AddXPathProperty("idarray", "//ss:Tag/ss:ID", XPathResultType.NodeSet, "string[]");
            sensorcfg.AddXPathPropertyFragment("tagArray", "//ss:Tag", XPathResultType.NodeSet, "TagEvent");
            sensorcfg.AddXPathPropertyFragment("tagOne", "//ss:Tag[position() = 1]", XPathResultType.Any, "TagEvent");
            sensorcfg.SchemaResource = _schemaUri;
            configuration.EngineDefaults.ViewResources.IsIterableUnbound = true;
            configuration.AddEventType("SensorEvent", sensorcfg);
        }
Пример #2
0
        public void TestXPathConfigured()
        {
            var rootMeta = new ConfigurationEventTypeXMLDOM();

            rootMeta.RootElementName = "simpleEvent";
            rootMeta.SchemaResource  = _schemaURI;
            rootMeta.AddNamespacePrefix("ss", "samples:schemas:simpleSchema");
            rootMeta.AddXPathPropertyFragment("nested1simple", "/ss:simpleEvent/ss:nested1", XPathResultType.Any, "MyNestedEvent");
            rootMeta.AddXPathPropertyFragment("nested4array", "//ss:nested4", XPathResultType.NodeSet, "MyNestedArrayEvent");
            rootMeta.IsAutoFragment = false;
            _epService.EPAdministrator.Configuration.AddEventType("MyXMLEvent", rootMeta);

            var metaNested = new ConfigurationEventTypeXMLDOM();

            metaNested.RootElementName = "//nested1";
            metaNested.SchemaResource  = _schemaURI;
            metaNested.IsAutoFragment  = false;
            _epService.EPAdministrator.Configuration.AddEventType("MyNestedEvent", metaNested);

            var metaNestedArray = new ConfigurationEventTypeXMLDOM();

            metaNestedArray.RootElementName = "//nested4";
            metaNestedArray.SchemaResource  = _schemaURI;
            _epService.EPAdministrator.Configuration.AddEventType("MyNestedArrayEvent", metaNestedArray);

            var stmtInsert   = _epService.EPAdministrator.CreateEPL("insert into Nested3Stream select nested1simple, nested4array from MyXMLEvent#lastevent");
            var stmtWildcard = _epService.EPAdministrator.CreateEPL("select * from MyXMLEvent#lastevent");

            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtWildcard.EventType);
            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("nested1simple", typeof(XmlNode), null, false, false, false, false, true),
                new EventPropertyDescriptor("nested4array", typeof(XmlNode[]), typeof(XmlNode), false, false, true, false, true),
            }, stmtInsert.EventType.PropertyDescriptors);

            var fragmentTypeNested1 = stmtInsert.EventType.GetFragmentType("nested1simple");

            Assert.IsFalse(fragmentTypeNested1.IsIndexed);
            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("prop1", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("prop2", typeof(bool?), null, false, false, false, false, false),
                new EventPropertyDescriptor("attr1", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("nested2", typeof(XmlNode), null, false, false, false, false, false),
            }, fragmentTypeNested1.FragmentType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(fragmentTypeNested1.FragmentType);

            var fragmentTypeNested4 = stmtInsert.EventType.GetFragmentType("nested4array");

            Assert.IsTrue(fragmentTypeNested4.IsIndexed);
            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("prop5", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("prop6", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("prop7", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("prop8", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("id", typeof(string), typeof(char), false, false, true, false, false),
            }, fragmentTypeNested4.FragmentType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(fragmentTypeNested4.FragmentType);

            var fragmentTypeNested4Item = stmtInsert.EventType.GetFragmentType("nested4array[0]");

            Assert.IsFalse(fragmentTypeNested4Item.IsIndexed);
            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("prop5", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("prop6", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("prop7", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("prop8", typeof(string[]), typeof(string), false, false, true, false, false),
                new EventPropertyDescriptor("id", typeof(string), typeof(char), false, false, true, false, false),
            }, fragmentTypeNested4Item.FragmentType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(fragmentTypeNested4Item.FragmentType);

            SupportXML.SendDefaultEvent(_epService.EPRuntime, "ABC");

            var received = stmtInsert.First();

            EPAssertionUtil.AssertProps(received, "nested1simple.prop1,nested1simple.prop2,nested1simple.attr1,nested1simple.nested2.prop3[1]".SplitCsv(), new object[] { "SAMPLE_V1", true, "SAMPLE_ATTR1", 4 });
            EPAssertionUtil.AssertProps(received, "nested4array[0].id,nested4array[0].prop5[1],nested4array[1].id".SplitCsv(), new object[] { "a", "SAMPLE_V8", "b" });

            // assert event and fragments alone
            var wildcardStmtEvent = stmtWildcard.First();

            SupportEventTypeAssertionUtil.AssertConsistency(wildcardStmtEvent);

            var eventType = wildcardStmtEvent.EventType.GetFragmentType("nested1simple");

            Assert.IsFalse(eventType.IsIndexed);
            Assert.IsFalse(eventType.IsNative);
            Assert.AreEqual("MyNestedEvent", eventType.FragmentType.Name);
            Assert.IsTrue(wildcardStmtEvent.Get("nested1simple") is XmlNode);
            Assert.AreEqual("SAMPLE_V1", ((EventBean)wildcardStmtEvent.GetFragment("nested1simple")).Get("prop1"));

            eventType = wildcardStmtEvent.EventType.GetFragmentType("nested4array");
            Assert.IsTrue(eventType.IsIndexed);
            Assert.IsFalse(eventType.IsNative);
            Assert.AreEqual("MyNestedArrayEvent", eventType.FragmentType.Name);
            var eventsArray = (EventBean[])wildcardStmtEvent.GetFragment("nested4array");

            Assert.AreEqual(3, eventsArray.Length);
            Assert.AreEqual("SAMPLE_V8", eventsArray[0].Get("prop5[1]"));
            Assert.AreEqual("SAMPLE_V9", eventsArray[1].Get("prop5[0]"));
            Assert.AreEqual(typeof(XmlNodeList), wildcardStmtEvent.EventType.GetPropertyType("nested4array"));
            Assert.IsTrue(wildcardStmtEvent.Get("nested4array") is XmlNodeList);

            var nested4arrayItem = (EventBean)wildcardStmtEvent.GetFragment("nested4array[1]");

            Assert.AreEqual("b", nested4arrayItem.Get("id"));
        }
Пример #3
0
        public override void Run(EPServiceProvider epService)
        {
            var rootMeta = new ConfigurationEventTypeXMLDOM();

            rootMeta.RootElementName = "simpleEvent";
            rootMeta.AddNamespacePrefix("ss", "samples:schemas:simpleSchema");
            rootMeta.AddXPathPropertyFragment("nested1simple", "/ss:simpleEvent/ss:nested1", XPathResultType.Any, "MyNestedEvent");
            rootMeta.AddXPathPropertyFragment("nested4array", "//ss:nested4", XPathResultType.NodeSet, "MyNestedArrayEvent");
            epService.EPAdministrator.Configuration.AddEventType("MyXMLEvent", rootMeta);

            var metaNested = new ConfigurationEventTypeXMLDOM();

            metaNested.RootElementName = "nested1";
            epService.EPAdministrator.Configuration.AddEventType("MyNestedEvent", metaNested);

            var metaNestedArray = new ConfigurationEventTypeXMLDOM();

            metaNestedArray.RootElementName = "nested4";
            epService.EPAdministrator.Configuration.AddEventType("MyNestedArrayEvent", metaNestedArray);

            EPStatement stmtInsert   = epService.EPAdministrator.CreateEPL("insert into Nested3Stream select nested1simple, nested4array from MyXMLEvent");
            EPStatement stmtWildcard = epService.EPAdministrator.CreateEPL("select * from MyXMLEvent");

            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtWildcard.EventType);
            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("nested1simple", typeof(XmlNode), null, false, false, false, false, true),
                new EventPropertyDescriptor("nested4array", typeof(XmlNode[]), typeof(XmlNode), false, false, true, false, true),
            }, stmtInsert.EventType.PropertyDescriptors);

            FragmentEventType fragmentTypeNested1 = stmtInsert.EventType.GetFragmentType("nested1simple");

            Assert.IsFalse(fragmentTypeNested1.IsIndexed);
            Assert.AreEqual(0, fragmentTypeNested1.FragmentType.PropertyDescriptors.Count);
            SupportEventTypeAssertionUtil.AssertConsistency(fragmentTypeNested1.FragmentType);

            FragmentEventType fragmentTypeNested4 = stmtInsert.EventType.GetFragmentType("nested4array");

            Assert.IsTrue(fragmentTypeNested4.IsIndexed);
            Assert.AreEqual(0, fragmentTypeNested4.FragmentType.PropertyDescriptors.Count);
            SupportEventTypeAssertionUtil.AssertConsistency(fragmentTypeNested4.FragmentType);

            SupportXML.SendDefaultEvent(epService.EPRuntime, "ABC");

            EventBean received = stmtInsert.First();

            EPAssertionUtil.AssertProps(received, "nested1simple.prop1,nested1simple.prop2,nested1simple.attr1,nested1simple.nested2.prop3[1]".Split(','), new object[] { "SAMPLE_V1", "true", "SAMPLE_ATTR1", "4" });
            EPAssertionUtil.AssertProps(received, "nested4array[0].id,nested4array[0].prop5[1],nested4array[1].id".Split(','), new object[] { "a", "SAMPLE_V8", "b" });

            // assert event and fragments alone
            EventBean wildcardStmtEvent = stmtWildcard.First();

            SupportEventTypeAssertionUtil.AssertConsistency(wildcardStmtEvent);

            FragmentEventType eventType = wildcardStmtEvent.EventType.GetFragmentType("nested1simple");

            Assert.IsFalse(eventType.IsIndexed);
            Assert.IsFalse(eventType.IsNative);
            Assert.AreEqual("MyNestedEvent", eventType.FragmentType.Name);
            Assert.IsTrue(wildcardStmtEvent.Get("nested1simple") is XmlNode);
            Assert.AreEqual("SAMPLE_V1", ((EventBean)wildcardStmtEvent.GetFragment("nested1simple")).Get("prop1"));

            eventType = wildcardStmtEvent.EventType.GetFragmentType("nested4array");
            Assert.IsTrue(eventType.IsIndexed);
            Assert.IsFalse(eventType.IsNative);
            Assert.AreEqual("MyNestedArrayEvent", eventType.FragmentType.Name);
            EventBean[] eventsArray = (EventBean[])wildcardStmtEvent.GetFragment("nested4array");
            Assert.AreEqual(3, eventsArray.Length);
            Assert.AreEqual("SAMPLE_V8", eventsArray[0].Get("prop5[1]"));
            Assert.AreEqual("SAMPLE_V9", eventsArray[1].Get("prop5[0]"));
            Assert.AreEqual(typeof(XmlNodeList), wildcardStmtEvent.EventType.GetPropertyType("nested4array"));
            Assert.IsTrue(wildcardStmtEvent.Get("nested4array") is XmlNodeList);
        }
        public void TestObservationExampleXPathExpr()
        {
            var schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();

            var sensorcfg = new ConfigurationEventTypeXMLDOM();

            sensorcfg.RootElementName = "Sensor";
            sensorcfg.AddXPathProperty("countTags", "count(/ss:Sensor/ss:Observation/ss:Tag)", XPathResultType.Number);
            sensorcfg.AddXPathProperty("countTagsInt", "count(/ss:Sensor/ss:Observation/ss:Tag)", XPathResultType.Number, "int");
            sensorcfg.AddNamespacePrefix("ss", "SensorSchema");
            sensorcfg.AddXPathProperty("idarray", "//ss:Tag/ss:ID", XPathResultType.NodeSet, "String[]");
            sensorcfg.AddXPathPropertyFragment("tagArray", "//ss:Tag", XPathResultType.NodeSet, "TagEvent");
            sensorcfg.AddXPathPropertyFragment("tagOne", "//ss:Tag[position() = 1]", XPathResultType.Any, "TagEvent");
            sensorcfg.SchemaResource = schemaUri;

            var configuration = SupportConfigFactory.GetConfiguration();

            configuration.EngineDefaults.ViewResources.IsIterableUnbound = true;
            configuration.AddEventType("SensorEvent", sensorcfg);

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, this.GetType(), this.GetType().FullName);
            }

            var tagcfg = new ConfigurationEventTypeXMLDOM();

            tagcfg.RootElementName = "//Tag";
            tagcfg.SchemaResource  = schemaUri;
            _epService.EPAdministrator.Configuration.AddEventType("TagEvent", tagcfg);

            var stmtExampleOne   = _epService.EPAdministrator.CreateEPL("select countTags, countTagsInt, idarray, tagArray, tagOne from SensorEvent");
            var stmtExampleTwo_0 = _epService.EPAdministrator.CreateEPL("insert into TagOneStream select tagOne.* from SensorEvent");
            var stmtExampleTwo_1 = _epService.EPAdministrator.CreateEPL("select ID from TagOneStream");
            var stmtExampleTwo_2 = _epService.EPAdministrator.CreateEPL("insert into TagArrayStream select tagArray as mytags from SensorEvent");
            var stmtExampleTwo_3 = _epService.EPAdministrator.CreateEPL("select mytags[1].ID from TagArrayStream");

            var doc = SupportXML.GetDocument(XML);

            _epService.EPRuntime.SendEvent(doc);

            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleOne.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_0.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_1.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_2.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_3.First());

            var resultArray = stmtExampleOne.First().Get("idarray");

            EPAssertionUtil.AssertEqualsExactOrder((object[])resultArray, new string[] { "urn:epc:1:2.24.400", "urn:epc:1:2.24.401" });
            EPAssertionUtil.AssertProps(stmtExampleOne.First(), "countTags,countTagsInt".SplitCsv(), new object[] { 2d, 2 });
            Assert.AreEqual("urn:epc:1:2.24.400", stmtExampleTwo_1.First().Get("ID"));
            Assert.AreEqual("urn:epc:1:2.24.401", stmtExampleTwo_3.First().Get("mytags[1].ID"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }