Java Code Examples for io.siddhi.query.api.definition.Attribute#getType()

The following examples show how to use io.siddhi.query.api.definition.Attribute#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AggregationParser.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public static StreamEvent createRestEvent(MetaStreamEvent metaStreamEvent, StreamEvent streamEvent) {
    streamEvent.setTimestamp(0);
    streamEvent.setType(ComplexEvent.Type.RESET);
    List<Attribute> outputData = metaStreamEvent.getOutputData();
    for (int i = 0, outputDataSize = outputData.size(); i < outputDataSize; i++) {
        Attribute attribute = outputData.get(i);
        switch (attribute.getType()) {

            case STRING:
                streamEvent.setOutputData("", i);
                break;
            case INT:
                streamEvent.setOutputData(0, i);
                break;
            case LONG:
                streamEvent.setOutputData(0L, i);
                break;
            case FLOAT:
                streamEvent.setOutputData(0f, i);
                break;
            case DOUBLE:
                streamEvent.setOutputData(0.0, i);
                break;
            case BOOL:
                streamEvent.setOutputData(false, i);
                break;
            case OBJECT:
                streamEvent.setOutputData(null, i);
                break;
        }
    }
    return streamEvent;
}
 
Example 2
Source File: JsonSourceMapper.java    From siddhi-map-json with Apache License 2.0 4 votes vote down vote up
private Event[] convertToEventArrayForDefaultMapping(Object eventObject) {
    Gson gson = new Gson();
    JsonObject[] eventObjects = gson.fromJson(eventObject.toString(), JsonObject[].class);
    Event[] events = new Event[eventObjects.length];
    int index = 0;
    JsonObject eventObj;
    for (JsonObject jsonEvent : eventObjects) {
        if (jsonEvent.has(DEFAULT_JSON_EVENT_IDENTIFIER)) {
            eventObj = jsonEvent.get(DEFAULT_JSON_EVENT_IDENTIFIER).getAsJsonObject();
            if (failOnMissingAttribute && eventObj.size() < streamAttributes.size()) {
                log.error("Json message " + eventObj.toString() + " contains missing attributes. " +
                        "Hence dropping the message.");
                continue;
            }
        } else {
            eventObj = jsonEvent;
            if (eventObj.size() < streamAttributes.size()) {
                log.error("Json message " + eventObj.toString() + " is not in an accepted format for default " +
                        "mapping. Hence dropping the message.");
                continue;
            }
        }
        Event event = new Event(streamAttributes.size());
        Object[] data = event.getData();


        int position = 0;
        for (Attribute attribute : streamAttributes) {
            String attributeName = attribute.getName();
            Attribute.Type type = attribute.getType();
            JsonElement attributeElement = eventObj.get(attributeName);
            if (attributeElement == null) {
                data[position++] = null;
            } else {
                data[position++] = attributeConverter.getPropertyValue(
                        attributeElement.getAsString(), type);
            }
        }
        events[index++] = event;
    }
    return Arrays.copyOfRange(events, 0, index);
}