Search in sources :

Example 16 with ChannelHandler

use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.

the class TestStormSql method testExternalUdfUsingJar.

@Test(expected = UnsupportedOperationException.class)
public void testExternalUdfUsingJar() throws Exception {
    List<String> stmt = new ArrayList<>();
    stmt.add("CREATE EXTERNAL TABLE FOO (ID INT) LOCATION 'mock:///foo'");
    stmt.add("CREATE FUNCTION MYPLUS AS 'org.apache.storm.sql.TestUtils$MyPlus' USING JAR 'foo'");
    stmt.add("SELECT STREAM MYPLUS(ID, 1) FROM FOO WHERE ID > 2");
    StormSql sql = StormSql.construct();
    List<Values> values = new ArrayList<>();
    ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
    sql.execute(stmt, h);
}
Also used : ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) ChannelHandler(org.apache.storm.sql.runtime.ChannelHandler) Test(org.junit.Test)

Example 17 with ChannelHandler

use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.

the class TestPlanCompiler method testLogicalExpr.

@Test
public void testLogicalExpr() throws Exception {
    String sql = "SELECT ID > 0 OR ID < 1, ID > 0 AND ID < 1, NOT (ID > 0 AND ID < 1) FROM FOO WHERE ID > 0 AND ID < 2";
    TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
    PlanCompiler compiler = new PlanCompiler(typeFactory);
    AbstractValuesProcessor proc = compiler.compile(state.tree());
    Map<String, DataSource> data = new HashMap<>();
    data.put("FOO", new TestUtils.MockDataSource());
    List<Values> values = new ArrayList<>();
    ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
    proc.initialize(data, h);
    Assert.assertEquals(new Values(true, false, true), values.get(0));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) AbstractValuesProcessor(org.apache.storm.sql.runtime.AbstractValuesProcessor) ChannelHandler(org.apache.storm.sql.runtime.ChannelHandler) DataSource(org.apache.storm.sql.runtime.DataSource) TestUtils(org.apache.storm.sql.TestUtils) Test(org.junit.Test)

Example 18 with ChannelHandler

use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.

the class TestPlanCompiler method testCompile.

@Test
public void testCompile() throws Exception {
    String sql = "SELECT ID + 1 FROM FOO WHERE ID > 2";
    TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
    PlanCompiler compiler = new PlanCompiler(typeFactory);
    AbstractValuesProcessor proc = compiler.compile(state.tree());
    Map<String, DataSource> data = new HashMap<>();
    data.put("FOO", new TestUtils.MockDataSource());
    List<Values> values = new ArrayList<>();
    ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
    proc.initialize(data, h);
    Assert.assertArrayEquals(new Values[] { new Values(4), new Values(5) }, values.toArray());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) AbstractValuesProcessor(org.apache.storm.sql.runtime.AbstractValuesProcessor) ChannelHandler(org.apache.storm.sql.runtime.ChannelHandler) DataSource(org.apache.storm.sql.runtime.DataSource) TestUtils(org.apache.storm.sql.TestUtils) Test(org.junit.Test)

Example 19 with ChannelHandler

use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.

the class TestStormSql method testExternalUdfType2.

@Test(expected = CompilingClassLoader.CompilerException.class)
public void testExternalUdfType2() throws Exception {
    List<String> stmt = new ArrayList<>();
    // generated code will be not compilable since return type of MYPLUS and type of 'x' are different
    stmt.add("CREATE EXTERNAL TABLE FOO (ID INT, NAME VARCHAR) LOCATION 'mock:///foo'");
    stmt.add("CREATE FUNCTION MYPLUS AS 'org.apache.storm.sql.TestUtils$MyPlus'");
    stmt.add("SELECT STREAM ID FROM FOO WHERE MYPLUS(ID, 1) = 'x'");
    StormSql sql = StormSql.construct();
    List<Values> values = new ArrayList<>();
    ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
    sql.execute(stmt, h);
    Assert.assertEquals(0, values.size());
}
Also used : ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) ChannelHandler(org.apache.storm.sql.runtime.ChannelHandler) Test(org.junit.Test)

Example 20 with ChannelHandler

use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.

the class TestStormSql method testExternalNestedNonExistKeyAccess.

@Test
public void testExternalNestedNonExistKeyAccess() throws Exception {
    List<String> stmt = new ArrayList<>();
    // this triggers java.lang.RuntimeException: Cannot convert null to int
    stmt.add("CREATE EXTERNAL TABLE FOO (ID INT, MAPFIELD ANY, NESTEDMAPFIELD ANY, ARRAYFIELD ANY) LOCATION 'mocknested:///foo'");
    stmt.add("SELECT STREAM ID, MAPFIELD, NESTEDMAPFIELD, ARRAYFIELD " + "FROM FOO " + "WHERE CAST(MAPFIELD['a'] AS INTEGER) = 2");
    StormSql sql = StormSql.construct();
    List<Values> values = new ArrayList<>();
    ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
    sql.execute(stmt, h);
    Assert.assertEquals(0, values.size());
}
Also used : ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) ChannelHandler(org.apache.storm.sql.runtime.ChannelHandler) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)26 ChannelHandler (org.apache.storm.sql.runtime.ChannelHandler)26 Values (org.apache.storm.tuple.Values)26 Test (org.junit.Test)25 HashMap (java.util.HashMap)5 TestUtils (org.apache.storm.sql.TestUtils)5 AbstractValuesProcessor (org.apache.storm.sql.runtime.AbstractValuesProcessor)5 DataSource (org.apache.storm.sql.runtime.DataSource)5 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 PlanCompiler (org.apache.storm.sql.compiler.backends.standalone.PlanCompiler)1 TestCompilerUtils (org.apache.storm.sql.compiler.backends.standalone.TestCompilerUtils)1