io.siddhi.query.api.execution.query.input.handler.Window Java Examples
The following examples show how to use
io.siddhi.query.api.execution.query.input.handler.Window.
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: SiddhiExecutionPlanner.java From flink-siddhi with Apache License 2.0 | 6 votes |
private StreamPartition findStreamPartition(SingleInputStream inputStream, Selector selector) { // Window Spec List<Window> windows = new ArrayList<>(); for (StreamHandler streamHandler : inputStream.getStreamHandlers()) { if (streamHandler instanceof Window) { windows.add((Window) streamHandler); } } // Group By Spec List<Variable> groupBy = selector.getGroupByList(); if (windows.size() > 0 || groupBy.size() > 0) { return generatePartition(inputStream.getStreamId(), windows, groupBy); } else { return null; } }
Example #2
Source File: SiddhiExecutionPlanner.java From flink-siddhi with Apache License 2.0 | 6 votes |
private StreamPartition generatePartition(String streamId, List<Window> windows, List<Variable> groupBy) { StreamPartition partition = new StreamPartition(streamId); if (windows != null && windows.size() > 0) { //TODO: sort spec } if (groupBy != null && groupBy.size() > 0) { partition.setGroupByList(groupBy.stream().map(Variable::getAttributeName).collect(Collectors.toList())); partition.setType(StreamPartition.Type.GROUPBY); } else { partition.setType(StreamPartition.Type.SHUFFLE); } return partition; }
Example #3
Source File: PolicyExecutionPlannerImpl.java From eagle with Apache License 2.0 | 6 votes |
private StreamPartition findStreamPartition(SingleInputStream inputStream, Selector selector) { // Window Spec List<Window> windows = new ArrayList<>(); for (StreamHandler streamHandler : inputStream.getStreamHandlers()) { if (streamHandler instanceof Window) { windows.add((Window) streamHandler); } } // Group By Spec List<Variable> groupBy = selector.getGroupByList(); if (windows.size() > 0 || groupBy.size() >= 0) { return generatePartition(inputStream.getStreamId(), windows, groupBy); } else { return null; } }
Example #4
Source File: PolicyExecutionPlannerImpl.java From eagle with Apache License 2.0 | 6 votes |
private StreamPartition generatePartition(String streamId, List<Window> windows, List<Variable> groupBy) { StreamPartition partition = new StreamPartition(); partition.setStreamId(streamId); StreamSortSpec sortSpec = null; if (windows != null && windows.size() > 0) { for (Window window : windows) { if (window.getName().equals(WINDOW_EXTERNAL_TIME)) { sortSpec = new StreamSortSpec(); sortSpec.setWindowPeriodMillis(getExternalTimeWindowSize(window)); sortSpec.setWindowMargin(sortSpec.getWindowPeriodMillis() / 5); } } } partition.setSortSpec(sortSpec); if (groupBy != null && groupBy.size() > 0) { partition.setColumns(groupBy.stream().map(Variable::getAttributeName).collect(Collectors.toList())); partition.setType(StreamPartition.Type.GROUPBY); } else { partition.setType(StreamPartition.Type.SHUFFLE); } return partition; }
Example #5
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void testCreatingReturnFilterQueryWithExtension2() { Query query = Query.query(); Window window1 = new Window("ext", "Foo"); query.from( InputStream.stream("StockStream"). filter(Expression.and(Expression.compare(Expression.function("ext", "FooBarCond", Expression .value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")), Expression.function("ext", "BarCond", Expression.value(100), Expression.variable("volume") ) ) ).function("ext", "Foo", Expression.value(67), Expression.value(89)). window(window1) ); query.select( Selector.selector(). select("symbol", Expression.variable("symbol")). select("avgPrice", Expression.function("ext", "avg", Expression.variable("price"))) ); }
Example #6
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void testCreatingReturnFilterQueryWithExtension3() { Query query = Query.query(); Window window1 = new Window("Foo"); AssertJUnit.assertFalse(window1.equals("falsewindow")); query.from( InputStream.stream("StockStream"). filter(Expression.and(Expression.compare(Expression.function("ext", "FooBarCond", Expression .value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")), Expression.function("ext", "BarCond", Expression.value(100), Expression.variable("volume") ) ) ).function("ext", "Foo", Expression.value(67), Expression.value(89)). window(window1) ); query.select( Selector.selector(). select("symbol", Expression.variable("symbol")). select("avgPrice", Expression.function("ext", "avg", Expression.variable("price"))) ); }
Example #7
Source File: PolicyExecutionPlannerImpl.java From eagle with Apache License 2.0 | 5 votes |
private static int getExternalTimeWindowSize(Window window) { Expression windowSize = window.getParameters()[1]; if (windowSize instanceof TimeConstant) { return ((TimeConstant) windowSize).getValue().intValue(); } else if (windowSize instanceof IntConstant) { return ((IntConstant) windowSize).getValue(); } else if (windowSize instanceof LongConstant) { return ((LongConstant) windowSize).getValue().intValue(); } else { throw new UnsupportedOperationException("Illegal type of window size expression:" + windowSize.toString()); } }
Example #8
Source File: SiddhiQLBaseVisitorImpl.java From siddhi with Apache License 2.0 | 5 votes |
@Override public Object visitDefinition_window(@NotNull SiddhiQLParser.Definition_windowContext ctx) { Source source = (Source) visit(ctx.source()); if (source.isInnerStream) { throw newSiddhiParserException(ctx, " '#' cannot be used, because Windows can't be defined " + "as InnerStream!"); } if (source.isFaultStream) { throw newSiddhiParserException(ctx, " '!' cannot be used, because Windows can't be defined " + "as FaultStream!"); } WindowDefinition windowDefinition = WindowDefinition.id(source.streamId); List<SiddhiQLParser.Attribute_nameContext> attribute_names = ctx.attribute_name(); List<SiddhiQLParser.Attribute_typeContext> attribute_types = ctx.attribute_type(); for (int i = 0; i < attribute_names.size(); i++) { SiddhiQLParser.Attribute_nameContext attributeNameContext = attribute_names.get(i); SiddhiQLParser.Attribute_typeContext attributeTypeContext = attribute_types.get(i); windowDefinition.attribute((String) visit(attributeNameContext), (Attribute.Type) visit (attributeTypeContext)); } for (SiddhiQLParser.AnnotationContext annotationContext : ctx.annotation()) { windowDefinition.annotation((Annotation) visit(annotationContext)); } AttributeFunction attributeFunction = (AttributeFunction) visit(ctx.function_operation()); Window window = new Window(attributeFunction.getNamespace(), attributeFunction.getName(), attributeFunction .getParameters()); windowDefinition.window(window); // Optional output event type if (ctx.output_event_type() != null) { windowDefinition.setOutputEventType((OutputStream.OutputEventType) visit(ctx.output_event_type())); } populateQueryContext(windowDefinition, ctx); return windowDefinition; }
Example #9
Source File: SiddhiQLBaseVisitorImpl.java From siddhi with Apache License 2.0 | 5 votes |
/** * {@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, source.isFaultStream); 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); } }
Example #10
Source File: SiddhiQLBaseVisitorImpl.java From siddhi with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * <p>The default implementation returns the result of calling * {@link #visitChildren} on {@code ctx}.</p> * * @param ctx */ @Override public Object visitJoin_source(@NotNull SiddhiQLParser.Join_sourceContext ctx) { // join_source // :io (basic_source_stream_handler)* window? (AS alias)? // ; Source source = (Source) visit(ctx.source()); String streamAlias = null; if (ctx.alias() != null) { streamAlias = (String) visit(ctx.alias()); activeStreams.remove(ctx.source().getText()); activeStreams.add(streamAlias); } BasicSingleInputStream basicSingleInputStream = new BasicSingleInputStream(streamAlias, source.streamId, source.isInnerStream, source.isFaultStream); if (ctx.basic_source_stream_handlers() != null) { basicSingleInputStream.addStreamHandlers((List<StreamHandler>) visit(ctx.basic_source_stream_handlers())); } if (ctx.window() != null) { SingleInputStream inputStream = new SingleInputStream(basicSingleInputStream, (Window) visit(ctx.window())); populateQueryContext(inputStream, ctx); return inputStream; } else { populateQueryContext(basicSingleInputStream, ctx); return basicSingleInputStream; } }
Example #11
Source File: SiddhiQLBaseVisitorImpl.java From siddhi with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * <p>The default implementation returns the result of calling * {@link #visitChildren} on {@code ctx}.</p> * * @param ctx */ @Override public Window visitWindow(@NotNull SiddhiQLParser.WindowContext ctx) { AttributeFunction attributeFunction = (AttributeFunction) visit(ctx.function_operation()); Window window = new Window(attributeFunction.getNamespace(), attributeFunction.getName(), attributeFunction.getParameters()); populateQueryContext(window, ctx); return window; }
Example #12
Source File: SingleInputStream.java From siddhi with Apache License 2.0 | 5 votes |
public SingleInputStream(BasicSingleInputStream basicSingleInputStream, Window window) { streamId = basicSingleInputStream.getStreamId(); isFaultStream = basicSingleInputStream.isFaultStream(); isInnerStream = basicSingleInputStream.isInnerStream(); streamReferenceId = basicSingleInputStream.getStreamReferenceId(); streamHandlers = basicSingleInputStream.getStreamHandlers(); windowPosition = basicSingleInputStream.getStreamHandlers().size(); streamHandlers.add(window); }
Example #13
Source File: BasicSingleInputStream.java From siddhi with Apache License 2.0 | 4 votes |
public SingleInputStream window(String name, Expression... parameters) { return new SingleInputStream(this, new Window(name, parameters)); }
Example #14
Source File: BasicSingleInputStream.java From siddhi with Apache License 2.0 | 4 votes |
public SingleInputStream window(String namespace, String function, Expression... parameters) { return new SingleInputStream(this, new Window(namespace, function, parameters)); }
Example #15
Source File: SingleInputStreamParser.java From siddhi with Apache License 2.0 | 4 votes |
public static Processor generateProcessor(StreamHandler streamHandler, MetaComplexEvent metaEvent, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, boolean supportsBatchProcessing, boolean outputExpectsExpiredEvents, boolean findToBeExecuted, SiddhiQueryContext siddhiQueryContext) { Expression[] parameters = streamHandler.getParameters(); MetaStreamEvent metaStreamEvent; int stateIndex = SiddhiConstants.UNKNOWN_STATE; if (metaEvent instanceof MetaStateEvent) { stateIndex = ((MetaStateEvent) metaEvent).getStreamEventCount() - 1; metaStreamEvent = ((MetaStateEvent) metaEvent).getMetaStreamEvent(stateIndex); } else { metaStreamEvent = (MetaStreamEvent) metaEvent; } if (streamHandler instanceof Window) { metaStreamEvent.initializeOnAfterWindowData(); } ExpressionExecutor[] attributeExpressionExecutors; if (parameters != null) { if (parameters.length > 0) { attributeExpressionExecutors = new ExpressionExecutor[parameters.length]; for (int i = 0, parametersLength = parameters.length; i < parametersLength; i++) { attributeExpressionExecutors[i] = ExpressionParser.parseExpression(parameters[i], metaEvent, stateIndex, tableMap, variableExpressionExecutors, false, SiddhiConstants.CURRENT, ProcessingMode.BATCH, false, siddhiQueryContext); } } else { List<Attribute> attributeList = metaStreamEvent.getLastInputDefinition().getAttributeList(); int parameterSize = attributeList.size(); attributeExpressionExecutors = new ExpressionExecutor[parameterSize]; for (int i = 0; i < parameterSize; i++) { attributeExpressionExecutors[i] = ExpressionParser.parseExpression(new Variable(attributeList.get (i).getName()), metaEvent, stateIndex, tableMap, variableExpressionExecutors, false, SiddhiConstants.CURRENT, ProcessingMode.BATCH, false, siddhiQueryContext); } } } else { attributeExpressionExecutors = new ExpressionExecutor[0]; } ConfigReader configReader; if (streamHandler instanceof Filter) { return new FilterProcessor(attributeExpressionExecutors[0]); } else if (streamHandler instanceof Window) { WindowProcessor windowProcessor = (WindowProcessor) SiddhiClassLoader.loadExtensionImplementation( (Extension) streamHandler, WindowProcessorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext())); configReader = siddhiQueryContext.getSiddhiContext().getConfigManager(). generateConfigReader(((Window) streamHandler).getNamespace(), ((Window) streamHandler).getName()); windowProcessor.initProcessor(metaStreamEvent, attributeExpressionExecutors, configReader, outputExpectsExpiredEvents, findToBeExecuted, false, streamHandler, siddhiQueryContext); return windowProcessor; } else if (streamHandler instanceof StreamFunction) { AbstractStreamProcessor abstractStreamProcessor; configReader = siddhiQueryContext.getSiddhiContext().getConfigManager(). generateConfigReader(((StreamFunction) streamHandler).getNamespace(), ((StreamFunction) streamHandler).getName()); if (supportsBatchProcessing) { try { abstractStreamProcessor = (StreamProcessor) SiddhiClassLoader.loadExtensionImplementation( (Extension) streamHandler, StreamProcessorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext())); abstractStreamProcessor.initProcessor(metaStreamEvent, attributeExpressionExecutors, configReader, outputExpectsExpiredEvents, false, false, streamHandler, siddhiQueryContext); return abstractStreamProcessor; } catch (SiddhiAppCreationException e) { if (!e.isClassLoadingIssue()) { ExceptionUtil.populateQueryContext(e, streamHandler, siddhiQueryContext.getSiddhiAppContext(), siddhiQueryContext); throw e; } } } abstractStreamProcessor = (StreamFunctionProcessor) SiddhiClassLoader.loadExtensionImplementation( (Extension) streamHandler, StreamFunctionProcessorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext())); abstractStreamProcessor.initProcessor(metaStreamEvent, attributeExpressionExecutors, configReader, outputExpectsExpiredEvents, false, false, streamHandler, siddhiQueryContext); return abstractStreamProcessor; } else { throw new SiddhiAppCreationException(streamHandler.getClass().getName() + " is not supported", streamHandler.getQueryContextStartIndex(), streamHandler.getQueryContextEndIndex()); } }
Example #16
Source File: WindowDefinition.java From siddhi with Apache License 2.0 | 2 votes |
/** * Return the internal window of the WindowDefinition. * * @return the internal window */ public Window getWindow() { return this.window; }