Search in sources :

Example 71 with Values

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);
}
Also used : Values(org.apache.storm.tuple.Values) Test(org.junit.Test)

Example 72 with Values

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);
}
Also used : Values(org.apache.storm.tuple.Values) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 73 with Values

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);
}
Also used : Values(org.apache.storm.tuple.Values) Test(org.junit.Test)

Example 74 with Values

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());
}
Also used : ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) ChannelHandler(org.apache.storm.sql.runtime.ChannelHandler) Test(org.junit.Test)

Example 75 with Values

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));
}
Also used : ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) ChannelHandler(org.apache.storm.sql.runtime.ChannelHandler) Test(org.junit.Test)

Aggregations

Values (org.apache.storm.tuple.Values)206 Test (org.junit.Test)89 ArrayList (java.util.ArrayList)42 Fields (org.apache.storm.tuple.Fields)40 HashMap (java.util.HashMap)39 ChannelHandler (org.apache.storm.sql.runtime.ChannelHandler)26 TridentTopology (org.apache.storm.trident.TridentTopology)21 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)14 Stream (org.apache.storm.trident.Stream)12 TupleImpl (org.apache.storm.tuple.TupleImpl)12 List (java.util.List)11 TestUtils (org.apache.storm.sql.TestUtils)11 TridentState (org.apache.storm.trident.TridentState)11 Tuple (org.apache.storm.tuple.Tuple)11 JSONObject (org.json.simple.JSONObject)10 Map (java.util.Map)9 Config (org.apache.storm.Config)9 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)9 GeneralTopologyContext (org.apache.storm.task.GeneralTopologyContext)8 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)8