Java Code Examples for io.siddhi.query.api.definition.StreamDefinition#getAttributeList()

The following examples show how to use io.siddhi.query.api.definition.StreamDefinition#getAttributeList() . 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: SiddhiStreamSchema.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
public String getStreamDefinitionExpression(StreamDefinition streamDefinition) {
    List<String> columns = new ArrayList<>();
    Preconditions.checkNotNull(streamDefinition, "StreamDefinition is null");
    for (Attribute attribute : streamDefinition.getAttributeList()) {
        columns.add(String.format("%s %s", attribute.getName(), attribute.getType().toString().toLowerCase()));
    }
    return String.format(DEFINE_STREAM_TEMPLATE, streamDefinition.getId(), StringUtils.join(columns, ","));
}
 
Example 2
Source File: SiddhiStreamSchema.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
public String getStreamDefinitionExpression(String streamId) {
    StreamDefinition streamDefinition = getStreamDefinition(streamId);
    List<String> columns = new ArrayList<>();
    Preconditions.checkNotNull(streamDefinition, "StreamDefinition is null");
    for (Attribute attribute : streamDefinition.getAttributeList()) {
        columns.add(String.format("%s %s", attribute.getName(), attribute.getType().toString().toLowerCase()));
    }
    return String.format(DEFINE_STREAM_TEMPLATE, streamDefinition.getId(), StringUtils.join(columns, ","));
}
 
Example 3
Source File: AggregationParser.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static HashMap<TimePeriod.Duration, Table> initDefaultTables(
        String aggregatorName, List<TimePeriod.Duration> durations,
        StreamDefinition streamDefinition, SiddhiAppRuntimeBuilder siddhiAppRuntimeBuilder,
        List<Annotation> annotations, List<Variable> groupByVariableList, boolean isProcessingOnExternalTime,
        boolean enablePartioning) {

    HashMap<TimePeriod.Duration, Table> aggregationTableMap = new HashMap<>();

    // Create annotations for primary key
    Annotation primaryKeyAnnotation = new Annotation(SiddhiConstants.ANNOTATION_PRIMARY_KEY);
    primaryKeyAnnotation.element(null, AGG_START_TIMESTAMP_COL);

    if (enablePartioning) {
        primaryKeyAnnotation.element(null, AGG_SHARD_ID_COL);
    }
    if (isProcessingOnExternalTime) {
        primaryKeyAnnotation.element(null, AGG_EXTERNAL_TIMESTAMP_COL);
    }
    for (Variable groupByVariable : groupByVariableList) {
        primaryKeyAnnotation.element(null, groupByVariable.getAttributeName());
    }
    annotations.add(primaryKeyAnnotation);
    for (TimePeriod.Duration duration : durations) {
        String tableId = aggregatorName + "_" + duration.toString();
        TableDefinition tableDefinition = TableDefinition.id(tableId);
        for (Attribute attribute : streamDefinition.getAttributeList()) {
            tableDefinition.attribute(attribute.getName(), attribute.getType());
        }
        annotations.forEach(tableDefinition::annotation);
        siddhiAppRuntimeBuilder.defineTable(tableDefinition);
        aggregationTableMap.put(duration, siddhiAppRuntimeBuilder.getTableMap().get(tableId));
    }
    return aggregationTableMap;
}
 
Example 4
Source File: SiddhiAppParser.java    From siddhi with Apache License 2.0 5 votes vote down vote up
private static StreamDefinition createFaultStreamDefinition(StreamDefinition streamDefinition) {

        List<Attribute> attributeList = streamDefinition.getAttributeList();
        StreamDefinition faultStreamDefinition = new StreamDefinition();
        faultStreamDefinition.setId(SiddhiConstants.FAULT_STREAM_PREFIX.concat(streamDefinition.getId()));
        for (Attribute attribute : attributeList) {
            faultStreamDefinition.attribute(attribute.getName(), attribute.getType());
        }
        faultStreamDefinition.attribute("_error", Attribute.Type.OBJECT);

        faultStreamDefinition.setQueryContextStartIndex(streamDefinition.getQueryContextStartIndex());
        faultStreamDefinition.setQueryContextEndIndex(streamDefinition.getQueryContextEndIndex());
        return faultStreamDefinition;
    }
 
Example 5
Source File: AggregationParser.java    From siddhi with Apache License 2.0 4 votes vote down vote up
private static List<ExpressionExecutor> constructProcessExpressionExecutors(
        SiddhiQueryContext siddhiQueryContext, Map<String, Table> tableMap, int baseAggregatorBeginIndex,
        List<Expression> finalBaseExpressions, StreamDefinition incomingOutputStreamDefinition,
        MetaStreamEvent processedMetaStreamEvent,
        List<VariableExpressionExecutor> processVariableExpressionExecutors, boolean isProcessingOnExternalTime,
        TimePeriod.Duration duration, boolean isDistributed, String shardId, boolean isLatestEventColAdded) {

    List<ExpressionExecutor> processExpressionExecutors = new ArrayList<>();
    List<Attribute> attributeList = incomingOutputStreamDefinition.getAttributeList();

    int i = 1;
    //Add timestamp executor
    Attribute attribute = attributeList.get(0);
    VariableExpressionExecutor variableExpressionExecutor = (VariableExpressionExecutor) ExpressionParser
            .parseExpression(new Variable(attribute.getName()), processedMetaStreamEvent, 0, tableMap,
                    processVariableExpressionExecutors, true, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
    processExpressionExecutors.add(variableExpressionExecutor);

    if (isDistributed) {
        Expression shardIdExpression = Expression.value(shardId);
        ExpressionExecutor shardIdExpressionExecutor = ExpressionParser.parseExpression(shardIdExpression,
                processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors, true, 0,
                ProcessingMode.BATCH, false, siddhiQueryContext);
        processExpressionExecutors.add(shardIdExpressionExecutor);
        i++;
    }

    if (isProcessingOnExternalTime) {
        Expression externalTimestampExpression =
                AttributeFunction.function("incrementalAggregator", "getAggregationStartTime",
                        new Variable(AGG_EXTERNAL_TIMESTAMP_COL), new StringConstant(duration.name()));
        ExpressionExecutor externalTimestampExecutor = ExpressionParser.parseExpression(
                externalTimestampExpression, processedMetaStreamEvent, 0, tableMap,
                processVariableExpressionExecutors, true, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
        processExpressionExecutors.add(externalTimestampExecutor);
        i++;
    }

    if (isLatestEventColAdded) {
        baseAggregatorBeginIndex = baseAggregatorBeginIndex - 1;
    }

    for (; i < baseAggregatorBeginIndex; i++) {
        attribute = attributeList.get(i);
        variableExpressionExecutor = (VariableExpressionExecutor) ExpressionParser.parseExpression(
                new Variable(attribute.getName()), processedMetaStreamEvent, 0, tableMap,
                processVariableExpressionExecutors, true, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
        processExpressionExecutors.add(variableExpressionExecutor);
    }

    if (isLatestEventColAdded) {
        Expression lastTimestampExpression =
                AttributeFunction.function("max", new Variable(AGG_LAST_TIMESTAMP_COL));
        ExpressionExecutor latestTimestampExecutor = ExpressionParser.parseExpression(lastTimestampExpression,
                processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors, true, 0,
                ProcessingMode.BATCH, false, siddhiQueryContext);
        processExpressionExecutors.add(latestTimestampExecutor);
    }

    for (Expression expression : finalBaseExpressions) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression,
                processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors,
                true, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
        processExpressionExecutors.add(expressionExecutor);
    }
    return processExpressionExecutors;
}