use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestStormSql method testFilterGroupbyHaving.
@Test
public void testFilterGroupbyHaving() 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, MIN(SALARY) FROM FOO where ID > 0 GROUP BY (ID) HAVING ID > 2 AND MAX(SALARY) > 5");
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(3, values.get(0).get(0));
Assert.assertEquals(9, values.get(0).get(1));
}
use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestStormSql method testExternalNestedInvalidAccessStringIndexOnArray.
@Test
public void testExternalNestedInvalidAccessStringIndexOnArray() throws Exception {
List<String> stmt = new ArrayList<>();
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(ARRAYFIELD['a'] AS INTEGER) = 200");
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 testjoinAndGroupby.
@Test
public void testjoinAndGroupby() throws Exception {
List<String> stmt = new ArrayList<>();
stmt.add("CREATE EXTERNAL TABLE EMP (EMPID INT PRIMARY KEY, EMPNAME VARCHAR, DEPTID INT) LOCATION 'mockemp:///foo'");
stmt.add("CREATE EXTERNAL TABLE DEPT (DEPTID INT PRIMARY KEY, DEPTNAME VARCHAR) LOCATION 'mockdept:///foo'");
stmt.add("SELECT STREAM d.DEPTID, count(EMPID) FROM EMP AS e JOIN DEPT AS d ON e.DEPTID = d.DEPTID WHERE e.empid > 0" + "GROUP BY d.DEPTID");
StormSql sql = StormSql.construct();
List<Values> values = new ArrayList<>();
ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
sql.execute(stmt, h);
Assert.assertEquals(2, values.size());
Assert.assertEquals(1, values.get(0).get(0));
Assert.assertEquals(2L, values.get(0).get(1));
Assert.assertEquals(2, values.get(1).get(0));
Assert.assertEquals(1L, values.get(1).get(1));
}
use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestStormSql method testGroupbyBuiltin.
@Test
public void testGroupbyBuiltin() 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(*), SUM(SALARY), AVG(SALARY) FROM FOO GROUP BY (ID)");
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(3, values.get(0).get(2));
Assert.assertEquals(12, values.get(1).get(2));
Assert.assertEquals(21, values.get(2).get(2));
Assert.assertEquals(9, values.get(3).get(2));
}
use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestStormSql method testExternalDataSource.
@Test
public void testExternalDataSource() throws Exception {
List<String> stmt = new ArrayList<>();
stmt.add("CREATE EXTERNAL TABLE FOO (ID INT) LOCATION 'mock:///foo'");
stmt.add("SELECT STREAM 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);
Assert.assertEquals(2, values.size());
Assert.assertEquals(4, values.get(0).get(0));
Assert.assertEquals(5, values.get(1).get(0));
}
Aggregations