use of org.apache.storm.tuple.Values in project storm by apache.
the class TestExprSemantic method testStringFunctions.
@Test
public void testStringFunctions() throws Exception {
Values v = testExpr(Lists.newArrayList("'ab' || 'cd'", "CHAR_LENGTH('foo')", "CHARACTER_LENGTH('foo')", "UPPER('a')", "LOWER('A')", "POSITION('bc' IN 'abcd')", "TRIM(BOTH ' ' FROM ' abcdeabcdeabc ')", "TRIM(LEADING ' ' FROM ' abcdeabcdeabc ')", "TRIM(TRAILING ' ' FROM ' abcdeabcdeabc ')", "OVERLAY('abcde' PLACING 'bc' FROM 3)", "SUBSTRING('abcde' FROM 3)", "SUBSTRING('abcdeabcde' FROM 3 FOR 4)", "INITCAP('foo')"));
assertEquals(new Values("abcd", 3, 3, "A", "a", 2, "abcdeabcdeabc", "abcdeabcdeabc ", " abcdeabcdeabc", "abbce", "cde", "cdea", "Foo"), v);
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class TestExprSemantic method testJDBCNumericFunctions.
@Test
public void testJDBCNumericFunctions() throws Exception {
Values v = testExpr(Lists.newArrayList("{fn POWER(3, 2)}", "{fn ABS(-10)}", "{fn MOD(10, 3)}", "{fn MOD(-10, 3)}"));
assertEquals(new Values(9.0d, 10, 1, -1), 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("{fn LOG(16)}", "{fn LOG10(10000)}", "{fn 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();
}
});
// 2.7725, 4.0, 22026.465794
assertEquals(new Values(2, 4, 22026), v2m);
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class TestExprSemantic method testArithmeticWithNull.
@Test
public void testArithmeticWithNull() throws Exception {
Values v = testExpr(Lists.newArrayList("1 + CAST(NULL AS INT)", "CAST(NULL AS INT) + 1", "CAST(NULL AS INT) + CAST(NULL AS INT)", "1 + 2"));
assertEquals(new Values(null, null, null, 3), v);
}
use of org.apache.storm.tuple.Values 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.tuple.Values 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));
}
Aggregations