Search in sources :

Example 61 with Values

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

Example 62 with Values

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

Example 63 with Values

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

Example 64 with Values

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

Example 65 with Values

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