Search in sources :

Example 66 with Values

use of org.apache.storm.tuple.Values in project storm by apache.

the class TestExprSemantic method testDateFunctions.

@Test
public void testDateFunctions() throws Exception {
    Values v = testExpr(Lists.newArrayList("LOCALTIME = CURRENT_TIME, LOCALTIMESTAMP = CURRENT_TIMESTAMP, CURRENT_DATE", "EXTRACT(MONTH FROM TIMESTAMP '2010-01-23 12:34:56')", "FLOOR(DATE '2016-01-23' TO MONTH)", "CEIL(TIME '12:34:56' TO MINUTE)"));
    assertEquals(6, v.size());
    assertTrue((boolean) v.get(0));
    assertTrue((boolean) v.get(1));
    // skip checking CURRENT_DATE since we don't inject dataContext so don't know about current timestamp
    // we can do it from trident test
    assertEquals(1L, v.get(3));
    assertEquals(0L, v.get(4));
    assertEquals(45300000, v.get(5));
}
Also used : Values(org.apache.storm.tuple.Values) Test(org.junit.Test)

Example 67 with Values

use of org.apache.storm.tuple.Values in project storm by apache.

the class TestExprSemantic method testLogicalExpr.

@Test
public void testLogicalExpr() throws Exception {
    Values v = testExpr(Lists.newArrayList("ID > 0 OR ID < 1", "ID > 0 AND ID < 1", "NOT (ID > 0 AND ID < 1)"));
    assertEquals(new Values(true, false, true), v);
}
Also used : Values(org.apache.storm.tuple.Values) Test(org.junit.Test)

Example 68 with Values

use of org.apache.storm.tuple.Values in project storm by apache.

the class TestExprSemantic method testNullIfAndCoalesce.

@Test
public void testNullIfAndCoalesce() throws Exception {
    Values v = testExpr(Lists.newArrayList("NULLIF(5, 5)", "NULLIF(5, 0)", "COALESCE(NULL, NULL, 5, 4, NULL)", "COALESCE(1, 5)"));
    assertEquals(new Values(null, 5, 5, 1), v);
}
Also used : Values(org.apache.storm.tuple.Values) Test(org.junit.Test)

Example 69 with Values

use of org.apache.storm.tuple.Values in project storm by apache.

the class TestExprSemantic method testCaseStatement.

@Test
public void testCaseStatement() throws Exception {
    Values v = testExpr(Lists.newArrayList("CASE WHEN 'abcd' IN ('a', 'abc', 'abcde') THEN UPPER('a') " + "WHEN UPPER('abcd') = 'AB' THEN 'b' ELSE {fn CONCAT('abcd', '#')} END", "CASE WHEN 'ab' IN ('a', 'abc', 'abcde') THEN UPPER('a') " + "WHEN UPPER('ab') = 'AB' THEN 'b' ELSE {fn CONCAT('ab', '#')} END", "CASE WHEN 'abc' IN ('a', 'abc', 'abcde') THEN UPPER('a') " + "WHEN UPPER('abc') = 'AB' THEN 'b' ELSE {fn CONCAT('abc', '#')} END"));
    // TODO: The data type of literal Calcite assigns seems to be out of expectation. Please see below logical plan.
    // LogicalProject(EXPR$0=[CASE(OR(=('abcd', 'a'), =('abcd', 'abc'), =('abcd', 'abcde')), CAST(UPPER('a')):VARCHAR(5) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL, =(UPPER('abcd'), CAST('AB'):CHAR(4) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL), 'b', CAST(||('abcd', '#')):VARCHAR(5) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL)], EXPR$1=[CASE(OR(=('ab', 'a'), =('ab', 'abc'), =('ab', 'abcde')), CAST(UPPER('a')):CHAR(3) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL, =(UPPER('ab'), 'AB'), CAST('b'):CHAR(3) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL, ||('ab', '#'))], EXPR$2=[CASE(OR(=('abc', 'a'), =('abc', 'abc'), =('abc', 'abcde')), CAST(UPPER('a')):CHAR(4) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL, =(UPPER('abc'), CAST('AB'):CHAR(3) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL), CAST('b'):CHAR(4) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL, ||('abc', '#'))]): rowcount = 1.0, cumulative cost = {2.0 rows, 5.0 cpu, 0.0 io}, id = 5
    //   LogicalFilter(condition=[AND(>($0, 0), <($0, 2))]): rowcount = 1.0, cumulative cost = {1.0 rows, 2.0 cpu, 0.0 io}, id = 4
    //     EnumerableTableScan(table=[[FOO]]): rowcount = 1.0, cumulative cost = {0.0 rows, 1.0 cpu, 0.0 io}, id = 3
    // in result, both 'b' and UPPER('a') hence 'A' are having some spaces which is not expected.
    // When we use CASE with actual column (Java String type hence VARCHAR), it seems to work as expected.
    // Please refer trident/TestPlanCompiler#testCaseStatement(), and see below logical plan.
    // LogicalProject(EXPR$0=[CASE(OR(=($1, 'a'), =($1, 'abc'), =($1, 'abcde')), CAST(UPPER('a')):VARCHAR(1) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary", =(CAST(UPPER($1)):VARCHAR(2) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary", 'AB'), 'b', CAST(||($1, '#')):VARCHAR(1) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary")]): rowcount = 1.0, cumulative cost = {1.0 rows, 2.0 cpu, 0.0 io}, id = 3
    List<Object> v2 = Lists.transform(v, new Function<Object, Object>() {

        @Nullable
        @Override
        public String apply(@Nullable Object o) {
            return ((String) o).trim();
        }
    });
    assertArrayEquals(new Values("abcd#", "b", "A").toArray(), v2.toArray());
}
Also used : Values(org.apache.storm.tuple.Values) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 70 with Values

use of org.apache.storm.tuple.Values in project storm by apache.

the class TestExprSemantic method testOrWithNullable.

@Test
public void testOrWithNullable() throws Exception {
    Values v = testExpr(Lists.newArrayList("ADDR = 'a'  OR NAME = 'a'", "NAME = 'a' OR ADDR = 'a' ", "NAME = 'x' OR ADDR = 'a' ", "ADDR = 'a'  OR NAME = 'x'"));
    assertEquals(new Values(null, null, true, true), v);
}
Also used : Values(org.apache.storm.tuple.Values) 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