Github user HeartSaVioR commented on a diff in the pull request:
https://github.com/apache/storm/pull/1714#discussion_r80442515
--- Diff:
external/sql/storm-sql-core/src/test/org/apache/storm/sql/TestStormSql.java ---
@@ -174,26 +173,42 @@ public void testExternalDataSource() throws Exception
{
public void testExternalDataSourceNested() 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 " +
+ stmt.add("SELECT STREAM ID, MAPFIELD['c'], NESTEDMAPFIELD, ARRAYFIELD
" +
"FROM FOO " +
- "WHERE NESTEDMAPFIELD['a']['b'] = 2 AND ARRAYFIELD[1]
= 200");
+ "WHERE CAST(MAPFIELD['b'] AS INTEGER) = 2 AND
CAST(ARRAYFIELD[1] AS INTEGER) = 200");
StormSql sql = StormSql.construct();
List<Values> values = new ArrayList<>();
ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
sql.execute(stmt, h);
System.out.println(values);
Map<String, Integer> map = ImmutableMap.of("b", 2, "c", 4);
Map<String, Map<String, Integer>> nestedMap = ImmutableMap.of("a",
map);
- Assert.assertEquals(new Values(2, map, nestedMap, Arrays.asList(100,
200, 300)), values.get(0));
+ Assert.assertEquals(new Values(2, 4, nestedMap, Arrays.asList(100,
200, 300)), values.get(0));
}
- @Test
+ @Test(expected = RuntimeException.class)
public void testExternalNestedInvalidAccess() 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 NESTEDMAPFIELD['a']['b'] = 2 AND
ARRAYFIELD['a'] = 200");
--- End diff --
MAPFIELD['a'] doesn't exist so this is a test for invalid access, map type.
Btw, I'll keep earlier test case but remove nested access from where since
it just makes test failing before testing invalid array access.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---