io.siddhi.query.api.execution.query.input.stream.JoinInputStream Java Examples
The following examples show how to use
io.siddhi.query.api.execution.query.input.stream.JoinInputStream.
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 |
/** * {@inheritDoc} * <p>The default implementation returns the result of calling * {@link #visitChildren} on {@code ctx}.</p> * * @param ctx */ @Override public JoinInputStream.Type visitJoin(@NotNull SiddhiQLParser.JoinContext ctx) { if (ctx.OUTER() != null) { if (ctx.FULL() != null) { return JoinInputStream.Type.FULL_OUTER_JOIN; } else if (ctx.RIGHT() != null) { return JoinInputStream.Type.RIGHT_OUTER_JOIN; } else if (ctx.LEFT() != null) { return JoinInputStream.Type.LEFT_OUTER_JOIN; } else { throw newSiddhiParserException(ctx, "Found " + ctx.getText() + " but only FULL OUTER JOIN, RIGHT " + "OUTER JOIN, LEFT OUTER JOIN are supported!"); } } return JoinInputStream.Type.JOIN; }
Example #2
Source File: JoinQueryTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void testCreatingUnidirectionalJoinQuery() { Query.query(). from( InputStream.joinStream( InputStream.stream("t", "TickEvent"), JoinInputStream.Type.JOIN, InputStream.stream("n", "NewsEvent"). window("unique", Expression.variable("symbol")), Expression.compare( Expression.variable("symbol").ofStream("t"), Compare.Operator.EQUAL, Expression.variable("symbol").ofStream("t")), JoinInputStream.EventTrigger.LEFT ) ). insertInto("JoinInputStream"); }
Example #3
Source File: QueryRuntimeImpl.java From siddhi with Apache License 2.0 | 6 votes |
public boolean isFromLocalStream() { if (query.getInputStream() instanceof SingleInputStream) { return ((SingleInputStream) query.getInputStream()).isInnerStream(); } else if (query.getInputStream() instanceof JoinInputStream) { return ((SingleInputStream) ((JoinInputStream) query.getInputStream()).getLeftInputStream()) .isInnerStream() || ((SingleInputStream) ((JoinInputStream) query.getInputStream()) .getRightInputStream()).isInnerStream(); } else if (query.getInputStream() instanceof StateInputStream) { for (String streamId : query.getInputStream().getAllStreamIds()) { if (streamId.startsWith("#")) { return true; } } } return false; }
Example #4
Source File: StreamPartitioner.java From siddhi with Apache License 2.0 | 6 votes |
private void createExecutors(InputStream inputStream, Partition partition, MetaComplexEvent metaEvent, List<VariableExpressionExecutor> executors, SiddhiQueryContext siddhiQueryContext) { if (inputStream instanceof SingleInputStream) { if (metaEvent instanceof MetaStateEvent) { createSingleInputStreamExecutors((SingleInputStream) inputStream, partition, ((MetaStateEvent) metaEvent).getMetaStreamEvent(0), executors, null, siddhiQueryContext); } else { createSingleInputStreamExecutors((SingleInputStream) inputStream, partition, (MetaStreamEvent) metaEvent, executors, null, siddhiQueryContext); } } else if (inputStream instanceof JoinInputStream) { createJoinInputStreamExecutors((JoinInputStream) inputStream, partition, (MetaStateEvent) metaEvent, executors, siddhiQueryContext); } else if (inputStream instanceof StateInputStream) { createStateInputStreamExecutors(((StateInputStream) inputStream).getStateElement(), partition, (MetaStateEvent) metaEvent, executors, 0, siddhiQueryContext); } }
Example #5
Source File: StreamPartitioner.java From siddhi with Apache License 2.0 | 6 votes |
private void createJoinInputStreamExecutors(JoinInputStream inputStream, Partition partition, MetaStateEvent metaEvent, List<VariableExpressionExecutor> executors, SiddhiQueryContext siddhiQueryContext) { createExecutors(inputStream.getLeftInputStream(), partition, metaEvent.getMetaStreamEvent(0), executors, siddhiQueryContext); int size = executors.size(); for (VariableExpressionExecutor variableExpressionExecutor : executors) { variableExpressionExecutor.getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 0; } createExecutors(inputStream.getRightInputStream(), partition, metaEvent.getMetaStreamEvent(1), executors, siddhiQueryContext); for (int i = size; i < executors.size(); i++) { executors.get(i).getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 1; } }
Example #6
Source File: PartitionRuntimeImpl.java From siddhi with Apache License 2.0 | 6 votes |
public void addPartitionReceiver(QueryRuntimeImpl queryRuntime, List<VariableExpressionExecutor> executors, MetaStateEvent metaEvent) { Query query = queryRuntime.getQuery(); List<List<PartitionExecutor>> partitionExecutors = new StreamPartitioner(query.getInputStream(), partition, metaEvent, executors, queryRuntime.getSiddhiQueryContext()).getPartitionExecutorLists(); if (queryRuntime.getStreamRuntime() instanceof SingleStreamRuntime) { SingleInputStream singleInputStream = (SingleInputStream) query.getInputStream(); addPartitionReceiver(singleInputStream.getStreamId(), singleInputStream.isInnerStream(), metaEvent .getMetaStreamEvent(0), partitionExecutors.get(0)); } else if (queryRuntime.getStreamRuntime() instanceof JoinStreamRuntime) { SingleInputStream leftSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()) .getLeftInputStream(); addPartitionReceiver(leftSingleInputStream.getStreamId(), leftSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0)); SingleInputStream rightSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()) .getRightInputStream(); addPartitionReceiver(rightSingleInputStream.getStreamId(), rightSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(1), partitionExecutors.get(1)); } else if (queryRuntime.getStreamRuntime() instanceof StateStreamRuntime) { StateElement stateElement = ((StateInputStream) query.getInputStream()).getStateElement(); addPartitionReceiverForStateElement(stateElement, metaEvent, partitionExecutors, 0); } }
Example #7
Source File: DefineAggregationTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void test3() throws SiddhiParserException { Query query = SiddhiCompiler .parseQuery("from barStream as b join cseEventAggregation as a " + "on a.symbol == b.symbol " + "within \"2014-02-15T00:00:00Z\", \"2014-03-16T00:00:00Z\" " + "per \"day\" " + "select a.symbol, a.total, a.avgPrice " + "insert into fooBar;"); Query queryApi = Query.query(). from(InputStream.joinStream( InputStream.stream("b", "barStream"), JoinInputStream.Type.JOIN, InputStream.stream("a", "cseEventAggregation"), Expression.compare( Expression.variable("symbol").ofStream("a"), Compare.Operator.EQUAL, Expression.variable("symbol").ofStream("b")), Within.within(Expression.value("2014-02-15T00:00:00Z"), Expression.value("2014-03-16T00:00:00Z")), Expression.value("day") ) ). select( Selector.selector(). select(Expression.variable("symbol").ofStream("a")). select(Expression.variable("total").ofStream("a")). select(Expression.variable("avgPrice").ofStream("a")) ). insertInto("fooBar"); AssertJUnit.assertEquals(queryApi, query); }
Example #8
Source File: DefineAggregationTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testAggregationJoin1() { Query.query(). from( InputStream.joinStream( InputStream.stream("s1", "cseEventStream"). filter(Expression.and( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price").ofStream("cseEventStream")), Expression.compare(Expression.value(100), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("volume").ofStream("cseEventStream") ) ) ).window("lengthBatch", Expression.value(50)), JoinInputStream.Type.JOIN, InputStore.store("s2", "StockAggregation"), Within.within(Expression.value("2014-02-15T00:00:00Z"), Expression.value("2014-03-16T00:00:00Z")), Expression.value("day") ) ). select( Selector.selector(). select("symbol", Expression.variable("symbol").ofStream("cseEventStream")). select(null, Expression.variable("symbol").ofStream("cseEventStream")). groupBy(Expression.variable("symbol").ofStream("cseEventStream")). having( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")) ) ). insertInto("StockQuote", OutputStream.OutputEventType.EXPIRED_EVENTS); }
Example #9
Source File: DefineAggregationTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testAggregationJoin2() { Query.query(). from( InputStream.joinStream( InputStream.stream("s1", "cseEventStream"). filter(Expression.and( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price").ofStream("cseEventStream")), Expression.compare(Expression.value(100), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("volume").ofStream("cseEventStream") ) ) ).window("lengthBatch", Expression.value(50)), JoinInputStream.Type.JOIN, InputStore.store("s2", "StockAggregation"), JoinInputStream.EventTrigger.LEFT, Within.within(Expression.value("2014-02-15T00:00:00Z"), Expression.value("2014-03-16T00:00:00Z")), Expression.value("day") ) ). select( Selector.selector(). select("symbol", Expression.variable("symbol").ofStream("cseEventStream")). select(null, Expression.variable("symbol").ofStream("cseEventStream")). groupBy(Expression.variable("symbol").ofStream("cseEventStream")). having( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")) ) ). insertInto("StockQuote", OutputStream.OutputEventType.EXPIRED_EVENTS); }
Example #10
Source File: JoinQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testCreatingUnidirectionalJoinQuery2() { Query.query(). from( InputStream.joinStream( InputStream.stream("t", "TickEvent"), JoinInputStream.Type.JOIN, InputStream.stream("n", "NewsEvent"). window("unique", Expression.variable("symbol")) ) ). insertInto("JoinInputStream"); }
Example #11
Source File: JoinQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testCreatingUnidirectionalJoinQuery3() { Query.query(). from( InputStream.joinStream( InputStream.stream("t", "TickEvent"), JoinInputStream.Type.JOIN, InputStream.stream("n", "NewsEvent"). window("unique", Expression.variable("symbol")), JoinInputStream.EventTrigger.LEFT ) ). insertInto("JoinInputStream"); }
Example #12
Source File: InputStreamParser.java From siddhi with Apache License 2.0 | 5 votes |
/** * Parse an InputStream returning corresponding StreamRuntime * * @param inputStream input stream to be parsed * @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 outputExpectsExpiredEvents is expired events sent as output * @param siddhiQueryContext Siddhi query context. * @return StreamRuntime */ public static StreamRuntime parse(InputStream inputStream, Query query, 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, boolean outputExpectsExpiredEvents, SiddhiQueryContext siddhiQueryContext) { if (inputStream instanceof BasicSingleInputStream || inputStream instanceof SingleInputStream) { SingleInputStream singleInputStream = (SingleInputStream) inputStream; ProcessStreamReceiver processStreamReceiver = new ProcessStreamReceiver(singleInputStream.getStreamId(), siddhiQueryContext); return SingleInputStreamParser.parseInputStream((SingleInputStream) inputStream, executors, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, new MetaStreamEvent(), processStreamReceiver, true, outputExpectsExpiredEvents, false, false, siddhiQueryContext); } else if (inputStream instanceof JoinInputStream) { return JoinInputStreamParser.parseInputStream(((JoinInputStream) inputStream), query, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, windowMap, aggregationMap, executors, outputExpectsExpiredEvents, siddhiQueryContext); } else if (inputStream instanceof StateInputStream) { MetaStateEvent metaStateEvent = new MetaStateEvent(inputStream.getAllStreamIds().size()); return StateInputStreamParser.parseInputStream(((StateInputStream) inputStream), metaStateEvent, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, executors, siddhiQueryContext); } else { throw new OperationNotSupportedException(); } }
Example #13
Source File: DefineAggregationTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testAggregationJoin() { Query.query(). from( InputStream.joinStream( InputStream.stream("s1", "cseEventStream"). filter(Expression.and( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price").ofStream("cseEventStream")), Expression.compare(Expression.value(100), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("volume").ofStream("cseEventStream") ) ) ).window("lengthBatch", Expression.value(50)), JoinInputStream.Type.JOIN, InputStore.store("s2", "StockAggregation"), Expression.compare( Expression.variable("price").ofStream("s1"), Compare.Operator.EQUAL, Expression.variable("price").ofStream("s2")), Within.within(Expression.value("2014-02-15T00:00:00Z"), Expression.value("2014-03-16T00:00:00Z")), Expression.value("day") ) ). select( Selector.selector(). select("symbol", Expression.variable("symbol").ofStream("cseEventStream")). select(null, Expression.variable("symbol").ofStream("cseEventStream")). groupBy(Expression.variable("symbol").ofStream("cseEventStream")). having( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")) ) ). insertInto("StockQuote", OutputStream.OutputEventType.EXPIRED_EVENTS); }
Example #14
Source File: JoinQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testCreatingJoinQuery() { Query query = Query.query(). annotation(Annotation.annotation("foo").element("name", "Query1").element("summery", "Test Query") .element("Custom")). from( InputStream.joinStream( InputStream.stream("s1", "cseEventStream"). window("lengthBatch", Expression.value(50)), JoinInputStream.Type.JOIN, InputStream.stream("s2", "cseEventStream"). filter(Expression.and( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price").ofStream("cseEventStream")), Expression.compare(Expression.value(100), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("volume").ofStream("cseEventStream") ) ) ).window("lengthBatch", Expression.value(50)), Expression.compare( Expression.variable("price").ofStream("s1"), Compare.Operator.EQUAL, Expression.variable("price").ofStream("s2")) ) ). select( Selector.selector(). select("symbol", Expression.variable("symbol").ofStream("cseEventStream")). select(null, Expression.variable("symbol").ofStream("cseEventStream")). groupBy(Expression.variable("symbol").ofStream("cseEventStream")). having( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")) ) ). insertInto("StockQuote", OutputStream.OutputEventType.EXPIRED_EVENTS); List<String> streamIds = new ArrayList<>(); streamIds.add("cseEventStream"); Assert.assertEquals(query.getInputStream().getAllStreamIds(), streamIds); Assert.assertEquals(query.getInputStream().getUniqueStreamIds(), streamIds); }
Example #15
Source File: JoinQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testJoinQueryToString() { Query query = Query.query(). annotation(Annotation.annotation("foo").element("name", "Query1").element("summery", "Test Query") .element("Custom")). from( InputStream.joinStream( InputStream.stream("s1", "cseEventStream"). window("lengthBatch", Expression.value(50)), JoinInputStream.Type.JOIN, InputStream.stream("s2", "cseEventStream"). filter(Expression.and( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price").ofStream("cseEventStream")), Expression.compare(Expression.value(100), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("volume").ofStream("cseEventStream") ) ) ).window("lengthBatch", Expression.value(50)), Expression.compare( Expression.variable("price").ofStream("s1"), Compare.Operator.EQUAL, Expression.variable("price").ofStream("s2")) ) ). select( Selector.selector(). select("symbol", Expression.variable("symbol").ofStream("cseEventStream")). select(null, Expression.variable("symbol").ofStream("cseEventStream")). groupBy(Expression.variable("symbol").ofStream("cseEventStream")). having( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")) ) ). insertInto("StockQuote", OutputStream.OutputEventType.EXPIRED_EVENTS); String queryString = "Query{stream=JoinInputStream{" + "leftInputStream=SingleInputStream{isFaultStream=false, isInnerStream=false, id='cseEventStream', " + "streamReferenceId='s1', streamHandlers=[Window{namespace='', function='lengthBatch', " + "parameters=[IntConstant{value=50}]}], windowPosition=0}, type=JOIN, " + "rightInputStream=SingleInputStream{isFaultStream=false, isInnerStream=false, id='cseEventStream', " + "streamReferenceId='s2', streamHandlers=[Filter{" + "filterExpression=And{leftExpression=Compare{rightExpression=Variable{id='cseEventStream', " + "isInnerStream=false, streamIndex=null, functionId='null', functionIndex=null," + " attributeName='price'}, operator=GREATER_THAN, leftExpression=Add{leftValue=IntConstant{value=7}, " + "rightValue=DoubleConstant{value=9.5}}}, rightExpression=Compare{" + "rightExpression=Variable{id='cseEventStream', isInnerStream=false, streamIndex=null, " + "functionId='null', functionIndex=null, attributeName='volume'}, operator=GREATER_THAN_EQUAL, " + "leftExpression=IntConstant{value=100}}}}, Window{namespace='', function='lengthBatch', " + "parameters=[IntConstant{value=50}]}], windowPosition=1}, " + "onCompare=Compare{rightExpression=Variable{id='s2', isInnerStream=false, streamIndex=null, " + "functionId='null', functionIndex=null, attributeName='price'}, operator=EQUAL, " + "leftExpression=Variable{id='s1', isInnerStream=false, streamIndex=null, functionId='null', " + "functionIndex=null, attributeName='price'}}, trigger=ALL, within=null, per=null}, " + "selector=Selector{selectionList=[OutputAttribute{rename='symbol', " + "expression=Variable{id='cseEventStream', isInnerStream=false, streamIndex=null, functionId='null', " + "functionIndex=null, attributeName='symbol'}}, OutputAttribute{rename='null', " + "expression=Variable{id='cseEventStream', isInnerStream=false, streamIndex=null, functionId='null', " + "functionIndex=null, attributeName='symbol'}}], groupByList=[Variable{id='cseEventStream', " + "isInnerStream=false, streamIndex=null, functionId='null', functionIndex=null, " + "attributeName='symbol'}], havingExpression=Compare{rightExpression=Variable{id='null', " + "isInnerStream=false, streamIndex=null, functionId='null', functionIndex=null, " + "attributeName='price'}, operator=GREATER_THAN, leftExpression=Add{leftValue=IntConstant{value=7}, " + "rightValue=DoubleConstant{value=9.5}}}, orderByList=[], limit=null, offset=null}, " + "outputStream=InsertIntoStream{isFaultStream=false, isInnerStream=false}, outputRate=null, " + "annotations=[@foo( name = \"Query1\", summery = \"Test Query\", \"Custom\")]}"; Assert.assertEquals(query.toString(), queryString); }
Example #16
Source File: JoinQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testCreatingJoinQuery1() { Query query = Query.query(). annotation(Annotation.annotation("foo").element("name", "Query1").element("summery", "Test Query") .element("Custom")). from( InputStream.joinStream( InputStream.stream("s1", "cseEventStream"). window("lengthBatch", Expression.value(50)), JoinInputStream.Type.JOIN, InputStream.stream("s2", "cseEventStream"). filter(Expression.and( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price").ofStream("cseEventStream")), Expression.compare(Expression.value(100), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("volume").ofStream("cseEventStream") ) ) ).window("lengthBatch", Expression.value(50)), Expression.compare( Expression.variable("price").ofStream("s1"), Compare.Operator.EQUAL, Expression.variable("price").ofStream("s2")) ) ). select( Selector.selector(). select("symbol", Expression.variable("symbol").ofStream("cseEventStream")). select(null, Expression.variable("symbol").ofStream("cseEventStream")). groupBy(Expression.variable("symbol").ofStream("cseEventStream")). having( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")) ) ). insertInto("StockQuote", OutputStream.OutputEventType.EXPIRED_EVENTS); Query query1 = Query.query(). annotation(Annotation.annotation("foo").element("name", "Query1").element("summery", "Test Query") .element("Custom")). from( InputStream.joinStream( InputStream.stream("s1", "cseEventStream"). window("lengthBatch", Expression.value(50)), JoinInputStream.Type.JOIN, InputStream.stream("s2", "cseEventStream"). filter(Expression.and( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price").ofStream("cseEventStream")), Expression.compare(Expression.value(100), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("volume").ofStream("cseEventStream") ) ) ).window("lengthBatch", Expression.value(50)), Expression.compare( Expression.variable("price").ofStream("s1"), Compare.Operator.EQUAL, Expression.variable("price").ofStream("s2")) ) ). select( Selector.selector(). select("symbol", Expression.variable("symbol").ofStream("cseEventStream")). select(null, Expression.variable("symbol").ofStream("cseEventStream")). groupBy(Expression.variable("symbol").ofStream("cseEventStream")). having( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")) ) ). insertInto("StockQuote", OutputStream.OutputEventType.EXPIRED_EVENTS); Assert.assertTrue(query.equals(query1)); Assert.assertEquals(query.hashCode(), query1.hashCode()); }