@Override
    public AggregationDefinition visitDefinition_aggregation(
            @NotNull SiddhiQLParser.Definition_aggregationContext ctx) {
        // Read the name of the aggregation
        String aggregationName = (String) visitAggregation_name(ctx.aggregation_name());

        // Create the aggregation using the extracted aggregation name
        AggregationDefinition aggregationDefinition = AggregationDefinition.id(aggregationName);

        // Get all annotation and populate the aggregation
        for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) {
            aggregationDefinition.annotation((Annotation) visit(annotationContext));
        }

        // Attach the input stream
        BasicSingleInputStream basicSingleInputStream = (BasicSingleInputStream) visit(ctx.standard_stream());
        aggregationDefinition.from(basicSingleInputStream);

        // Extract the selector and attach it to the new aggregation
        BasicSelector selector = (BasicSelector) visit(ctx.group_by_query_selection());
        aggregationDefinition.select(selector);

        // Get the variable (if available) and aggregate on that variable
        if (ctx.attribute_reference() != null) {
            Variable aggregatedBy = (Variable) visit(ctx.attribute_reference());
            aggregationDefinition.aggregateBy(aggregatedBy);
        }

        // Extract the specified time-durations and attache it to the aggregation definition
        TimePeriod timePeriod = (TimePeriod) visit(ctx.aggregation_time());
        aggregationDefinition.every(timePeriod);
        populateQueryContext(aggregationDefinition, ctx);
        return aggregationDefinition;
    }
{@inheritDoc}
<p>The default implementation returns the result of calling
{@link #visitChildren} on {@code ctx}.</p>

@param ctx
modules/siddhi-query-compiler/src/main/java/io/siddhi/query/compiler/internal/SiddhiQLBaseVisitorImpl.java