use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestPlanCompiler method testUdf.
@Test
public void testUdf() throws Exception {
String sql = "SELECT MYPLUS(ID, 3)" + "FROM FOO " + "WHERE ID = 2";
TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverNestedTable(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(5), values.get(0));
}
use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestPlanCompiler method testNested.
@Test
public void testNested() throws Exception {
String sql = "SELECT ID, MAPFIELD['c'], NESTEDMAPFIELD, ARRAYFIELD " + "FROM FOO " + "WHERE NESTEDMAPFIELD['a']['b'] = 2 AND ARRAYFIELD[2] = 200";
TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverNestedTable(sql);
PlanCompiler compiler = new PlanCompiler(typeFactory);
AbstractValuesProcessor proc = compiler.compile(state.tree());
Map<String, DataSource> data = new HashMap<>();
data.put("FOO", new TestUtils.MockNestedDataSource());
List<Values> values = new ArrayList<>();
ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
proc.initialize(data, h);
Map<String, Integer> map = ImmutableMap.of("b", 2, "c", 4);
Map<String, Map<String, Integer>> nestedMap = ImmutableMap.of("a", map);
Assert.assertEquals(new Values(2, 4, nestedMap, Arrays.asList(100, 200, 300)), values.get(0));
}
use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestStormSql method testAggFnNonSqlReturnType.
@Test
public void testAggFnNonSqlReturnType() throws Exception {
List<String> stmt = new ArrayList<>();
stmt.add("CREATE EXTERNAL TABLE FOO (ID INT PRIMARY KEY, SALARY INT, PCT DOUBLE, NAME VARCHAR) LOCATION 'mockgroup:///foo'");
stmt.add("CREATE FUNCTION TOPN AS 'org.apache.storm.sql.TestUtils$TopN'");
stmt.add("SELECT STREAM ID, SUM(SALARY), TOPN(1, SALARY) FROM FOO WHERE ID >= 0 GROUP BY (ID) HAVING MAX(SALARY) > 0");
StormSql sql = StormSql.construct();
List<Values> values = new ArrayList<>();
ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
sql.execute(stmt, h);
Assert.assertEquals(4, values.size());
Assert.assertEquals(Collections.singletonList(2), values.get(0).get(2));
Assert.assertEquals(Collections.singletonList(5), values.get(1).get(2));
Assert.assertEquals(Collections.singletonList(8), values.get(2).get(2));
Assert.assertEquals(Collections.singletonList(9), values.get(3).get(2));
}
use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestStormSql method testGroupbySameAggregateOnDifferentColumns.
@Test
public void testGroupbySameAggregateOnDifferentColumns() throws Exception {
List<String> stmt = new ArrayList<>();
stmt.add("CREATE EXTERNAL TABLE FOO (ID INT PRIMARY KEY, SALARY INT, PCT DOUBLE, NAME VARCHAR) LOCATION 'mockgroup:///foo'");
stmt.add("SELECT STREAM ID, COUNT(*), AVG(SALARY), AVG(PCT) FROM FOO WHERE ID = 1 GROUP BY (ID)");
StormSql sql = StormSql.construct();
List<Values> values = new ArrayList<>();
ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
sql.execute(stmt, h);
Assert.assertEquals(1, values.size());
Assert.assertEquals(1, values.get(0).get(0));
Assert.assertEquals(3L, values.get(0).get(1));
Assert.assertEquals(4, values.get(0).get(2));
Assert.assertEquals(2.5, values.get(0).get(3));
}
use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestStormSql method testExternalNestedNonExistKeyAccess2.
@Test
public void testExternalNestedNonExistKeyAccess2() 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(NESTEDMAPFIELD['b']['c'] AS INTEGER) = 4");
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