io.siddhi.query.api.execution.query.selection.OutputAttribute Java Examples

The following examples show how to use io.siddhi.query.api.execution.query.selection.OutputAttribute. 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: SiddhiQLBaseVisitorImpl.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Override
public BasicSelector visitGroup_by_query_selection(@NotNull SiddhiQLParser.Group_by_query_selectionContext ctx) {

    BasicSelector selector = new BasicSelector();

    List<OutputAttribute> attributeList = new ArrayList<OutputAttribute>(ctx.output_attribute().size());
    for (SiddhiQLParser.Output_attributeContext output_attributeContext : ctx.output_attribute()) {
        attributeList.add((OutputAttribute) visit(output_attributeContext));
    }
    selector.addSelectionList(attributeList);

    if (ctx.group_by() != null) {
        selector.addGroupByList((List<Variable>) visit(ctx.group_by()));
    }
    populateQueryContext(selector, ctx);
    return selector;
}
 
Example #2
Source File: AggregationParser.java    From siddhi with Apache License 2.0 6 votes vote down vote up
private static void processAggregationSelectors(AggregationDefinition aggregationDefinition,
                                                SiddhiQueryContext siddhiQueryContext, Map<String, Table> tableMap,
                                                List<VariableExpressionExecutor> incomingVariableExpressionExecutors,
                                                MetaStreamEvent incomingMetaStreamEvent,
                                                List<ExpressionExecutor> incomingExpressionExecutors,
                                                List<Expression> outputExpressions, OutputAttribute outputAttribute,
                                                Expression expression) {

    ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, incomingMetaStreamEvent,
            0, tableMap, incomingVariableExpressionExecutors, false, 0, ProcessingMode.BATCH, false,
            siddhiQueryContext);
    incomingExpressionExecutors.add(expressionExecutor);
    incomingMetaStreamEvent.addOutputData(
            new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
    aggregationDefinition.getAttributeList().add(
            new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
    outputExpressions.add(Expression.variable(outputAttribute.getRename()));
}
 
Example #3
Source File: PolicyExecutionPlannerImpl.java    From eagle with Apache License 2.0 5 votes vote down vote up
private static List<StreamColumn> convertOutputStreamColumns(List<OutputAttribute> outputAttributeList) {
    return outputAttributeList.stream().map(outputAttribute -> {
        StreamColumn streamColumn = new StreamColumn();
        streamColumn.setName(outputAttribute.getRename());
        streamColumn.setDescription(outputAttribute.getExpression().toString());
        return streamColumn;
    }).collect(Collectors.toList());
}
 
Example #4
Source File: SiddhiQLBaseVisitorImpl.java    From siddhi with Apache License 2.0 5 votes vote down vote up
/**
     * {@inheritDoc}
     * <p>The default implementation returns the result of calling
     * {@link #visitChildren} on {@code ctx}.</p>
     *
     * @param ctx
     */
    @Override
    public Selector visitQuery_section(@NotNull SiddhiQLParser.Query_sectionContext ctx) {

//        query_section
//        :(SELECT ('*'| (output_attribute (',' output_attribute)* ))) group_by? having?
//        ;

        Selector selector = new Selector();

        List<OutputAttribute> attributeList = new ArrayList<OutputAttribute>(ctx.output_attribute().size());
        for (SiddhiQLParser.Output_attributeContext output_attributeContext : ctx.output_attribute()) {
            attributeList.add((OutputAttribute) visit(output_attributeContext));
        }
        selector.addSelectionList(attributeList);

        if (ctx.group_by() != null) {
            selector.addGroupByList((List<Variable>) visit(ctx.group_by()));
        }
        if (ctx.having() != null) {
            selector.having((Expression) visit(ctx.having()));
        }
        if (ctx.order_by() != null) {
            selector.addOrderByList((List<OrderByAttribute>) visit(ctx.order_by()));
        }
        if (ctx.limit() != null) {
            selector.limit((Constant) visit(ctx.limit()));
        }
        if (ctx.offset() != null) {
            selector.offset((Constant) visit(ctx.offset()));
        }
        populateQueryContext(selector, ctx);
        return selector;
    }
 
Example #5
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void test4() {
    Selector selector = new Selector();

    List<OutputAttribute> list = new ArrayList<>();
    list.add(new OutputAttribute(Expression.variable("volume")));

    selector.select("symbol", Expression.variable("symbol")).
            orderBy(Expression.variable("symbol"), OrderByAttribute.Order.DESC).
            limit(Expression.value(5)).offset(Expression.value(2)).addSelectionList(list);

    AssertJUnit.assertEquals(IntConstant.value(5), selector.getLimit());
    AssertJUnit.assertEquals(IntConstant.value(2), selector.getOffset());
}
 
Example #6
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = DuplicateAttributeException.class)
public void selectortest2() {
    Selector selector = new Selector();

    List<OutputAttribute> list = new ArrayList<>();
    list.add(new OutputAttribute(Expression.variable("symbol")));

    selector.select("symbol", Expression.variable("symbol")).
            orderBy(Expression.variable("avgPrice"), OrderByAttribute.Order.DESC).
            limit(Expression.value(5)).offset(Expression.value(2)).addSelectionList(list);
}
 
Example #7
Source File: AggregationRuntime.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public AggregationRuntime(AggregationDefinition aggregationDefinition, boolean isProcessingOnExternalTime,
                          boolean isDistributed, List<TimePeriod.Duration> incrementalDurations,
                          Map<TimePeriod.Duration, IncrementalExecutor> incrementalExecutorMap,
                          Map<TimePeriod.Duration, Table> aggregationTables,
                          List<ExpressionExecutor> outputExpressionExecutors,
                          Map<TimePeriod.Duration, List<ExpressionExecutor>> aggregateProcessingExecutorsMap,
                          ExpressionExecutor shouldUpdateTimestamp,
                          Map<TimePeriod.Duration, GroupByKeyGenerator> groupByKeyGeneratorMap,
                          boolean isOptimisedLookup, List<OutputAttribute> defaultSelectorList,
                          List<String> groupByVariablesList,
                          boolean isLatestEventColAdded, int baseAggregatorBeginIndex,
                          List<Expression> finalBaseExpressionList, IncrementalDataPurger incrementalDataPurger,
                          IncrementalExecutorsInitialiser incrementalExecutorInitialiser,
                          SingleStreamRuntime singleStreamRuntime, MetaStreamEvent tableMetaStreamEvent,
                          LatencyTracker latencyTrackerFind, ThroughputTracker throughputTrackerFind,
                          String timeZone) {
    this.timeZone = timeZone;
    this.aggregationDefinition = aggregationDefinition;
    this.isProcessingOnExternalTime = isProcessingOnExternalTime;
    this.isDistributed = isDistributed;
    this.incrementalDurations = incrementalDurations;
    this.incrementalExecutorMap = incrementalExecutorMap;
    this.aggregationTables = aggregationTables;
    this.tableAttributesNameList = tableMetaStreamEvent.getInputDefinitions().get(0).getAttributeList()
            .stream().map(Attribute::getName).collect(Collectors.toList());
    this.outputExpressionExecutors = outputExpressionExecutors;
    this.aggregateProcessingExecutorsMap = aggregateProcessingExecutorsMap;
    this.shouldUpdateTimestamp = shouldUpdateTimestamp;
    this.groupByKeyGeneratorMap = groupByKeyGeneratorMap;
    this.isOptimisedLookup = isOptimisedLookup;
    this.defaultSelectorList = defaultSelectorList;
    this.groupByVariablesList = groupByVariablesList;
    this.isLatestEventColAdded = isLatestEventColAdded;
    this.baseAggregatorBeginIndex = baseAggregatorBeginIndex;
    this.finalBaseExpressionsList = finalBaseExpressionList;

    this.incrementalDataPurger = incrementalDataPurger;
    this.incrementalExecutorsInitialiser = incrementalExecutorInitialiser;

    this.singleStreamRuntime = singleStreamRuntime;
    this.aggregateMetaSteamEvent = new MetaStreamEvent();
    aggregationDefinition.getAttributeList().forEach(this.aggregateMetaSteamEvent::addOutputData);

    this.latencyTrackerFind = latencyTrackerFind;
    this.throughputTrackerFind = throughputTrackerFind;

}