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);
}
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));
}
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());
}
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());
}
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());
}
Aggregations