use of org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream in project ballerina by ballerina-lang.
the class InputStreamParser method parse.
/**
* Parse an InputStream returning corresponding StreamRuntime.
*
* @param inputStream input stream to be parsed
* @param siddhiAppContext associated siddhi siddhiAppContext
* @param streamDefinitionMap map containing user given stream definitions
* @param tableDefinitionMap table definition map
* @param windowDefinitionMap window definition map
* @param aggregationDefinitionMap aggregation definition map
* @param tableMap Table Map
* @param windowMap event window map
* @param aggregationMap aggregator map
* @param executors List to hold VariableExpressionExecutors to update after query parsing
* @param latencyTracker latency tracker
* @param outputExpectsExpiredEvents is output expects ExpiredEvents
* @param queryName query name of input stream belongs to.
* @return StreamRuntime
*/
public static StreamRuntime parse(InputStream inputStream, SiddhiAppContext siddhiAppContext, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, Map<String, Window> windowMap, Map<String, AggregationRuntime> aggregationMap, List<VariableExpressionExecutor> executors, LatencyTracker latencyTracker, boolean outputExpectsExpiredEvents, String queryName) {
if (inputStream instanceof BasicSingleInputStream || inputStream instanceof SingleInputStream) {
SingleInputStream singleInputStream = (SingleInputStream) inputStream;
Window window = windowMap.get(singleInputStream.getStreamId());
// If stream is from window, allow batch
boolean batchProcessingAllowed = window != null;
// processing
ProcessStreamReceiver processStreamReceiver = new ProcessStreamReceiver(singleInputStream.getStreamId(), latencyTracker, queryName, siddhiAppContext);
processStreamReceiver.setBatchProcessingAllowed(batchProcessingAllowed);
return SingleInputStreamParser.parseInputStream((SingleInputStream) inputStream, siddhiAppContext, executors, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, new MetaStreamEvent(), processStreamReceiver, true, outputExpectsExpiredEvents, queryName);
} else if (inputStream instanceof JoinInputStream) {
return JoinInputStreamParser.parseInputStream(((JoinInputStream) inputStream), siddhiAppContext, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, windowMap, aggregationMap, executors, latencyTracker, outputExpectsExpiredEvents, queryName);
} else if (inputStream instanceof StateInputStream) {
MetaStateEvent metaStateEvent = new MetaStateEvent(inputStream.getAllStreamIds().size());
return StateInputStreamParser.parseInputStream(((StateInputStream) inputStream), siddhiAppContext, metaStateEvent, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, executors, latencyTracker, queryName);
} else {
throw new OperationNotSupportedException();
}
}
use of org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream in project ballerina by ballerina-lang.
the class SiddhiQLBaseVisitorImpl method visitLogical_absent_stateful_source.
@Override
public Object visitLogical_absent_stateful_source(SiddhiQLParser.Logical_absent_stateful_sourceContext ctx) {
// ;
if (ctx.logical_absent_stateful_source() != null) {
return visit(ctx.logical_absent_stateful_source());
} else if (ctx.AND() != null) {
if (ctx.basic_absent_pattern_source().size() == 2) {
StateElement stateElement = State.logicalNotAnd((AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(0)), (AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(1)));
populateQueryContext(stateElement, ctx);
return stateElement;
} else {
StreamStateElement presentStreamState = (StreamStateElement) visit(ctx.standard_stateful_source());
AbsentStreamStateElement absentStreamState;
if (!ctx.basic_absent_pattern_source().isEmpty()) {
absentStreamState = (AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(0));
} else {
absentStreamState = State.logicalNot(new StreamStateElement((BasicSingleInputStream) visit(ctx.basic_source())));
}
StateElement stateElement = State.logicalNotAnd(absentStreamState, presentStreamState);
populateQueryContext(stateElement, ctx);
return stateElement;
}
} else if (ctx.OR() != null) {
if (ctx.basic_absent_pattern_source().size() == 2) {
return State.logicalOr((AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(0)), (AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(1)));
} else {
StreamStateElement streamStateElement1 = (StreamStateElement) visit(ctx.standard_stateful_source());
AbsentStreamStateElement streamStateElement2 = (AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(0));
StateElement stateElement = State.logicalOr(streamStateElement2, streamStateElement1);
populateQueryContext(stateElement, ctx);
return stateElement;
}
} else {
throw newSiddhiParserException(ctx);
}
}
use of org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream in project ballerina by ballerina-lang.
the class SiddhiQLBaseVisitorImpl method visitStandard_stateful_source.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public StreamStateElement visitStandard_stateful_source(@NotNull SiddhiQLParser.Standard_stateful_sourceContext ctx) {
if (ctx.event() != null) {
activeStreams.add(visitEvent(ctx.event()));
}
BasicSingleInputStream basicSingleInputStream = (BasicSingleInputStream) visit(ctx.basic_source());
if (ctx.event() != null) {
if (basicSingleInputStream.isInnerStream()) {
activeStreams.remove("#" + basicSingleInputStream.getStreamId());
} else {
activeStreams.remove(basicSingleInputStream.getStreamId());
}
StreamStateElement streamStateElement = new StreamStateElement(basicSingleInputStream.as((String) visit(ctx.event())));
populateQueryContext(streamStateElement, ctx);
return streamStateElement;
} else {
StreamStateElement streamStateElement = new StreamStateElement(basicSingleInputStream);
populateQueryContext(streamStateElement, ctx);
return streamStateElement;
}
}
use of org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream in project ballerina by ballerina-lang.
the class SiddhiQLBaseVisitorImpl method visitDefinition_aggregation.
@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;
}
use of org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream in project ballerina by ballerina-lang.
the class SiddhiQLBaseVisitorImpl method visitStandard_stream.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public SingleInputStream visitStandard_stream(@NotNull SiddhiQLParser.Standard_streamContext ctx) {
// standard_stream
// : io (basic_source_stream_handler)* window? (basic_source_stream_handler)*
// ;
Source source = (Source) visit(ctx.source());
BasicSingleInputStream basicSingleInputStream = new BasicSingleInputStream(null, source.streamId, source.isInnerStream);
if (ctx.pre_window_handlers != null) {
basicSingleInputStream.addStreamHandlers((List<StreamHandler>) visit(ctx.pre_window_handlers));
}
if (ctx.window() == null && ctx.post_window_handlers == null) {
populateQueryContext(basicSingleInputStream, ctx);
return basicSingleInputStream;
} else if (ctx.window() != null) {
SingleInputStream singleInputStream = new SingleInputStream(basicSingleInputStream, (Window) visit(ctx.window()));
if (ctx.post_window_handlers != null) {
singleInputStream.addStreamHandlers((List<StreamHandler>) visit(ctx.post_window_handlers));
}
populateQueryContext(singleInputStream, ctx);
return singleInputStream;
} else {
throw newSiddhiParserException(ctx);
}
}
Aggregations