use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestStormSql method testGroupByMultipleFields.
@Test
public void testGroupByMultipleFields() throws Exception {
List<String> stmt = new ArrayList<>();
stmt.add("CREATE EXTERNAL TABLE FOO (DEPTID INT PRIMARY KEY, SALARY INT, PCT DOUBLE, NAME VARCHAR, EMPID INT) LOCATION 'mockgroup:///foo'");
stmt.add("SELECT STREAM DEPTID, EMPID, COUNT(*), MIN(SALARY), MAX(PCT) FROM FOO GROUP BY DEPTID, EMPID");
StormSql sql = StormSql.construct();
List<Values> values = new ArrayList<>();
ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
sql.execute(stmt, h);
Assert.assertEquals(7, values.size());
Assert.assertEquals(0, values.get(0).get(0));
Assert.assertEquals(0, values.get(0).get(1));
Assert.assertEquals(2L, values.get(0).get(2));
}
use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestStormSql method testGroupbyBuiltinAndUDF.
@Test
public void testGroupbyBuiltinAndUDF() 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 MYCONCAT AS 'org.apache.storm.sql.TestUtils$MyConcat'");
stmt.add("CREATE FUNCTION TOPN AS 'org.apache.storm.sql.TestUtils$TopN'");
stmt.add("SELECT STREAM ID, SUM(SALARY), MYCONCAT(NAME), TOPN(2, 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(1));
Assert.assertEquals("xxx", values.get(0).get(2));
Assert.assertEquals(Arrays.asList(2, 1), values.get(0).get(3));
Assert.assertEquals(12, values.get(1).get(1));
Assert.assertEquals("xxx", values.get(1).get(2));
Assert.assertEquals(Arrays.asList(5, 4), values.get(1).get(3));
Assert.assertEquals(21, values.get(2).get(1));
Assert.assertEquals("xxx", values.get(2).get(2));
Assert.assertEquals(Arrays.asList(8, 7), values.get(2).get(3));
Assert.assertEquals(9, values.get(3).get(1));
Assert.assertEquals("x", values.get(3).get(2));
Assert.assertEquals(Arrays.asList(9), values.get(3).get(3));
}
use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestStormSql method testGroupbyBuiltinWithFilter.
@Test
public void testGroupbyBuiltinWithFilter() 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(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(12, 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 testGroupbyBuiltinNotimplemented.
@Test(expected = UnsupportedOperationException.class)
public void testGroupbyBuiltinNotimplemented() 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(*), STDDEV_POP(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);
}
use of org.apache.storm.sql.runtime.ChannelHandler in project storm by apache.
the class TestStormSql method testMinMax.
@Test
public void testMinMax() 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(*), MIN(SALARY), MAX(PCT) 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(0, values.get(0).get(2));
Assert.assertEquals(3, values.get(1).get(2));
Assert.assertEquals(6, values.get(2).get(2));
Assert.assertEquals(9, values.get(3).get(2));
Assert.assertEquals(1.5, values.get(0).get(3));
Assert.assertEquals(3.0, values.get(1).get(3));
Assert.assertEquals(4.5, values.get(2).get(3));
Assert.assertEquals(5.0, values.get(3).get(3));
}
Aggregations