use of org.apache.storm.tuple.Values 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.tuple.Values in project storm by apache.
the class TestExprSemantic method testJDBCDateTimeFunctions.
@Test
public void testJDBCDateTimeFunctions() throws Exception {
Values v = testExpr(Lists.newArrayList("{fn CURDATE()} = CURRENT_DATE", "{fn CURTIME()} = LOCALTIME", "{fn NOW()} = LOCALTIMESTAMP", "{fn QUARTER(DATE '2016-10-07')}", "{fn TIMESTAMPADD(MINUTE, 15, TIMESTAMP '2016-10-07 00:00:00')}", "{fn TIMESTAMPDIFF(SECOND, TIMESTAMP '2016-10-06 00:00:00', TIMESTAMP '2016-10-07 00:00:00')}"));
assertEquals(new Values(true, true, true, 4L, 1475799300000L, 86400), v);
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class TestExprSemantic method testAndWithNullable.
@Test
public void testAndWithNullable() throws Exception {
Values v = testExpr(Lists.newArrayList("ADDR = 'a' AND NAME = 'a'", "NAME = 'a' AND ADDR = 'a'", "NAME = 'x' AND ADDR = 'a'", "ADDR = 'a' AND NAME = 'x'"));
assertEquals(new Values(false, false, null, null), v);
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class TestExprSemantic method testOrWithNull.
@Test
public void testOrWithNull() throws Exception {
Values v = testExpr(Lists.newArrayList("UNKNOWN OR TRUE", "UNKNOWN OR FALSE", "UNKNOWN OR UNKNOWN", "TRUE OR TRUE", "TRUE OR FALSE", "TRUE OR UNKNOWN", "FALSE OR TRUE", "FALSE OR FALSE", "FALSE OR UNKNOWN"));
assertEquals(new Values(true, null, null, true, true, true, true, false, null), v);
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class TestExprSemantic method testArithmeticFunctions.
@Test
public void testArithmeticFunctions() throws Exception {
Values v = testExpr(Lists.newArrayList("POWER(3, 2)", "ABS(-10)", "MOD(10, 3)", "MOD(-10, 3)", "CEIL(123.45)", "FLOOR(123.45)"));
assertEquals(new Values(9.0d, 10, 1, -1, new BigDecimal(124), new BigDecimal(123)), v);
// Belows are floating numbers so comparing this with literal is tend to be failing...
// Picking int value and compare
Values v2 = testExpr(Lists.newArrayList("SQRT(255)", "LN(16)", "LOG10(10000)", "EXP(10)"));
List<Object> v2m = Lists.transform(v2, new Function<Object, Object>() {
@Nullable
@Override
public Object apply(@Nullable Object o) {
// only takes int value
return ((Number) o).intValue();
}
});
// 15.9687, 2.7725, 4.0, 22026.465794
assertEquals(new Values(15, 2, 4, 22026), v2m);
}
Aggregations