public static Object[] getOrderedValues(StreamDefinition streamMetaData, List<ColumnNameTypeValue> columns) throws AttributeNotExistException { Object[] orderedValues = new Object[streamMetaData.getAttributeList().size()]; for (ColumnNameTypeValue column : columns) { // if attribute does not exist, a AttributeNotExistException // exception will be thrown // XXX change this. create a conversor engine to treat data types. if (column.getValue() instanceof String) { orderedValues[streamMetaData.getAttributePosition(column.getColumn())] = decodeSiddhiValue( (String) column.getValue(), streamMetaData.getAttributeType(column.getColumn())); } else if (column.getValue() instanceof Double) { orderedValues[streamMetaData.getAttributePosition(column.getColumn())] = decodeSiddhiValue( (Double) column.getValue(), streamMetaData.getAttributeType(column.getColumn())); } else { orderedValues[streamMetaData.getAttributePosition(column.getColumn())] = column.getValue(); } } return orderedValues; }
@Test public void testStreamSchemaWithPojo() { TypeInformation<Event> typeInfo = TypeExtractor.createTypeInfo(Event.class); assertTrue("Type information should be PojoTypeInfo", typeInfo instanceof PojoTypeInfo); SiddhiStreamSchema<Event> schema = new SiddhiStreamSchema<>(typeInfo, "id", "timestamp", "name", "price"); assertEquals(4, schema.getFieldIndexes().length); StreamDefinition streamDefinition = schema.getStreamDefinition("test_stream"); assertArrayEquals(new String[]{"id", "timestamp", "name", "price"}, streamDefinition.getAttributeNameArray()); assertEquals(Attribute.Type.INT, streamDefinition.getAttributeType("id")); assertEquals(Attribute.Type.LONG, streamDefinition.getAttributeType("timestamp")); assertEquals(Attribute.Type.STRING, streamDefinition.getAttributeType("name")); assertEquals(Attribute.Type.DOUBLE, streamDefinition.getAttributeType("price")); assertEquals("define stream test_stream (id int,timestamp long,name string,price double);", schema.getStreamDefinitionExpression("test_stream")); } }
for (Attribute attribute : streamDefinition.getMetaData()) { siddhiAttributeName = EventProcessorConstants.META_PREFIX + attribute.getName(); org.wso2.siddhi.query.api.definition.Attribute.Type type = siddhiStreamDefinition.getAttributeType( siddhiAttributeName); for (Attribute attribute : streamDefinition.getCorrelationData()) { siddhiAttributeName = EventProcessorConstants.CORRELATION_PREFIX + attribute.getName(); org.wso2.siddhi.query.api.definition.Attribute.Type type = siddhiStreamDefinition.getAttributeType( siddhiAttributeName); for (Attribute attribute : streamDefinition.getPayloadData()) { siddhiAttributeName = attribute.getName(); org.wso2.siddhi.query.api.definition.Attribute.Type type = siddhiStreamDefinition.getAttributeType( siddhiAttributeName);