Search in sources :

Example 56 with Values

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

the class TestStormSql method testExternalNestedNonExistKeyAccess2.

@Test
public void testExternalNestedNonExistKeyAccess2() throws Exception {
    List<String> stmt = new ArrayList<>();
    // this triggers java.lang.RuntimeException: Cannot convert null to int
    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(NESTEDMAPFIELD['b']['c'] AS INTEGER) = 4");
    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 57 with Values

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

the class TestStormSql method testjoin.

@Test
public void testjoin() 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 EMPID, EMPNAME, DEPTNAME FROM EMP AS e JOIN DEPT AS d ON e.DEPTID = d.DEPTID WHERE e.empid > 0");
    StormSql sql = StormSql.construct();
    List<Values> values = new ArrayList<>();
    ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
    sql.execute(stmt, h);
    System.out.println(values);
    Assert.assertEquals(3, values.size());
    Assert.assertEquals("emp1", values.get(0).get(1));
    Assert.assertEquals("dept1", values.get(0).get(2));
    Assert.assertEquals("emp2", values.get(1).get(1));
    Assert.assertEquals("dept1", values.get(1).get(2));
    Assert.assertEquals("emp3", values.get(2).get(1));
    Assert.assertEquals("dept2", values.get(2).get(2));
}
Also used : ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) ChannelHandler(org.apache.storm.sql.runtime.ChannelHandler) Test(org.junit.Test)

Example 58 with Values

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

the class TestStormSql method testExternalUdfType.

@Test(expected = ValidationException.class)
public void testExternalUdfType() throws Exception {
    List<String> stmt = new ArrayList<>();
    stmt.add("CREATE EXTERNAL TABLE FOO (ID INT, NAME VARCHAR) LOCATION 'mock:///foo'");
    stmt.add("CREATE FUNCTION MYPLUS AS 'org.apache.storm.sql.TestUtils$MyPlus'");
    stmt.add("SELECT STREAM MYPLUS(NAME, 1) FROM FOO WHERE ID = 0");
    StormSql sql = StormSql.construct();
    List<Values> values = new ArrayList<>();
    ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
    sql.execute(stmt, h);
    System.out.println(values);
}
Also used : ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) ChannelHandler(org.apache.storm.sql.runtime.ChannelHandler) Test(org.junit.Test)

Example 59 with Values

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

the class TestStormSql method testExternalNestedArrayOutOfBoundAccess.

@Test
public void testExternalNestedArrayOutOfBoundAccess() 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[10] 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 60 with Values

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

the class TestStormSql method testExternalUdf.

@Test
public void testExternalUdf() throws Exception {
    List<String> stmt = new ArrayList<>();
    stmt.add("CREATE EXTERNAL TABLE FOO (ID INT) LOCATION 'mock:///foo'");
    stmt.add("CREATE FUNCTION MYPLUS AS 'org.apache.storm.sql.TestUtils$MyPlus'");
    stmt.add("SELECT STREAM MYPLUS(ID, 1) FROM FOO WHERE ID > 2");
    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(4, values.get(0).get(0));
    Assert.assertEquals(5, values.get(1).get(0));
}
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