Search in sources :

Example 6 with AbstractStreamsProcessor

use of org.apache.storm.sql.AbstractStreamsProcessor in project storm by apache.

the class TestPlanCompiler method testUdf.

@Test
public void testUdf() throws Exception {
    int EXPECTED_VALUE_SIZE = 1;
    String sql = "SELECT MYPLUS(ID, 3)" + "FROM FOO " + "WHERE ID = 2";
    TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
    Map<String, ISqlStreamsDataSource> data = new HashMap<>();
    data.put("FOO", new TestUtils.MockSqlStreamsDataSource());
    QueryPlanner planner = new QueryPlanner(state.schema());
    AbstractStreamsProcessor proc = planner.compile(data, sql);
    // inject output bolt
    proc.outputStream().to(new TestUtils.MockBolt());
    final StormTopology topo = proc.build();
    SqlTestUtil.runStormTopology(cluster, TestUtils.MockBolt.getCollectedValues(), EXPECTED_VALUE_SIZE, proc, topo);
    Assert.assertArrayEquals(new Values[] { new Values(5) }, TestUtils.MockBolt.getCollectedValues().toArray());
}
Also used : HashMap(java.util.HashMap) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) QueryPlanner(org.apache.storm.sql.planner.streams.QueryPlanner) TestUtils(org.apache.storm.sql.TestUtils) AbstractStreamsProcessor(org.apache.storm.sql.AbstractStreamsProcessor) ISqlStreamsDataSource(org.apache.storm.sql.runtime.ISqlStreamsDataSource) Test(org.junit.jupiter.api.Test)

Example 7 with AbstractStreamsProcessor

use of org.apache.storm.sql.AbstractStreamsProcessor in project storm by apache.

the class TestPlanCompiler method testInsert.

@Test
public void testInsert() throws Exception {
    final int EXPECTED_VALUE_SIZE = 1;
    String sql = "INSERT INTO BAR SELECT ID, NAME, ADDR FROM FOO WHERE ID > 3";
    TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
    final Map<String, ISqlStreamsDataSource> data = new HashMap<>();
    data.put("FOO", new TestUtils.MockSqlStreamsDataSource());
    data.put("BAR", new TestUtils.MockSqlStreamsOutputDataSource());
    QueryPlanner planner = new QueryPlanner(state.schema());
    AbstractStreamsProcessor proc = planner.compile(data, sql);
    final StormTopology topo = proc.build();
    SqlTestUtil.runStormTopology(cluster, TestUtils.MockInsertBolt.getCollectedValues(), EXPECTED_VALUE_SIZE, proc, topo);
    Assert.assertArrayEquals(new Pair[] { Pair.of(4, new Values(4, "abcde", "y")) }, TestUtils.MockInsertBolt.getCollectedValues().toArray());
}
Also used : HashMap(java.util.HashMap) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) QueryPlanner(org.apache.storm.sql.planner.streams.QueryPlanner) TestUtils(org.apache.storm.sql.TestUtils) AbstractStreamsProcessor(org.apache.storm.sql.AbstractStreamsProcessor) ISqlStreamsDataSource(org.apache.storm.sql.runtime.ISqlStreamsDataSource) Test(org.junit.jupiter.api.Test)

Aggregations

AbstractStreamsProcessor (org.apache.storm.sql.AbstractStreamsProcessor)7 Values (org.apache.storm.tuple.Values)7 HashMap (java.util.HashMap)6 StormTopology (org.apache.storm.generated.StormTopology)6 TestUtils (org.apache.storm.sql.TestUtils)6 QueryPlanner (org.apache.storm.sql.planner.streams.QueryPlanner)6 ISqlStreamsDataSource (org.apache.storm.sql.runtime.ISqlStreamsDataSource)6 Test (org.junit.jupiter.api.Test)6 DataContext (org.apache.calcite.DataContext)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1 CompilingClassLoader (org.apache.storm.sql.javac.CompilingClassLoader)1 StreamsRel (org.apache.storm.sql.planner.streams.rel.StreamsRel)1 StreamBuilder (org.apache.storm.streams.StreamBuilder)1