Github user arunmahadevan commented on a diff in the pull request:
https://github.com/apache/storm/pull/1714#discussion_r80425461
--- Diff:
external/sql/storm-sql-core/src/test/org/apache/storm/sql/compiler/backends/trident/TestPlanCompiler.java
---
@@ -255,6 +265,198 @@ public void testUdaf() throws Exception {
Assert.assertArrayEquals(new Values[] { new Values(0, 5L, 15L, 15L) },
getCollectedValues().toArray());
}
+ @Test
+ public void testLike() throws Exception {
+ int EXPECTED_VALUE_SIZE = 2;
+
+ // 'abcd', 'abcde' matched
+ String sql = "SELECT ID FROM FOO WHERE NAME LIKE '%c_%'";
+ TestCompilerUtils.CalciteState state =
TestCompilerUtils.sqlOverDummyTable(sql);
+
+ final Map<String, ISqlTridentDataSource> data = new HashMap<>();
+ data.put("FOO", new TestUtils.MockSqlTridentDataSource());
+ PlanCompiler compiler = new PlanCompiler(data, typeFactory,
dataContext);
+ final AbstractTridentProcessor proc =
compiler.compileForTest(state.tree());
+ final TridentTopology topo = proc.build(data);
+ Fields f = proc.outputStream().getOutputFields();
+ proc.outputStream().partitionPersist(new TestUtils.MockStateFactory(),
+ f, new TestUtils.MockStateUpdater(), new Fields());
+ runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
+
+ Assert.assertArrayEquals(new Values[] { new Values(3), new Values(4)
}, getCollectedValues().toArray());
+ }
+
+ @Test
+ public void testSimilar() throws Exception {
+ int EXPECTED_VALUE_SIZE = 2;
+
+ // 'abc' and 'abcd' matched
+ String sql = "SELECT ID FROM FOO WHERE NAME SIMILAR TO
'[a-zA-Z]+[cd]{1}'";
+ TestCompilerUtils.CalciteState state =
TestCompilerUtils.sqlOverDummyTable(sql);
+
+ final Map<String, ISqlTridentDataSource> data = new HashMap<>();
+ data.put("FOO", new TestUtils.MockSqlTridentDataSource());
+ PlanCompiler compiler = new PlanCompiler(data, typeFactory,
dataContext);
+ final AbstractTridentProcessor proc =
compiler.compileForTest(state.tree());
+ final TridentTopology topo = proc.build(data);
+ Fields f = proc.outputStream().getOutputFields();
+ proc.outputStream().partitionPersist(new TestUtils.MockStateFactory(),
+ f, new TestUtils.MockStateUpdater(), new Fields());
+ runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
+
+ Assert.assertArrayEquals(new Values[] { new Values(2), new Values(3)
}, getCollectedValues().toArray());
+ }
+
+ @Test
+ public void testNotLike() throws Exception {
+ int EXPECTED_VALUE_SIZE = 3;
+
+ // 'a', 'ab', 'abc' matched
+ String sql = "SELECT ID FROM FOO WHERE NAME NOT LIKE '%c_%'";
+ TestCompilerUtils.CalciteState state =
TestCompilerUtils.sqlOverDummyTable(sql);
+
+ final Map<String, ISqlTridentDataSource> data = new HashMap<>();
+ data.put("FOO", new TestUtils.MockSqlTridentDataSource());
+ PlanCompiler compiler = new PlanCompiler(data, typeFactory,
dataContext);
+ final AbstractTridentProcessor proc =
compiler.compileForTest(state.tree());
+ final TridentTopology topo = proc.build(data);
+ Fields f = proc.outputStream().getOutputFields();
+ proc.outputStream().partitionPersist(new TestUtils.MockStateFactory(),
+ f, new TestUtils.MockStateUpdater(), new Fields());
+ runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
+
+ Assert.assertArrayEquals(new Values[] { new Values(0), new Values(1),
new Values(2) }, getCollectedValues().toArray());
+ }
+
+ @Test
+ public void testNotSimilar() throws Exception {
+ int EXPECTED_VALUE_SIZE = 3;
+
+ // 'a', 'ab', 'abcde' matched
+ String sql = "SELECT ID FROM FOO WHERE NAME NOT SIMILAR TO
'[a-zA-Z]+[cd]{1}'";
+ TestCompilerUtils.CalciteState state =
TestCompilerUtils.sqlOverDummyTable(sql);
+
+ final Map<String, ISqlTridentDataSource> data = new HashMap<>();
+ data.put("FOO", new TestUtils.MockSqlTridentDataSource());
+ PlanCompiler compiler = new PlanCompiler(data, typeFactory,
dataContext);
+ final AbstractTridentProcessor proc =
compiler.compileForTest(state.tree());
+ final TridentTopology topo = proc.build(data);
+ Fields f = proc.outputStream().getOutputFields();
+ proc.outputStream().partitionPersist(new TestUtils.MockStateFactory(),
+ f, new TestUtils.MockStateUpdater(), new Fields());
+ runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
+
+ Assert.assertArrayEquals(new Values[] { new Values(0), new Values(1),
new Values(4) }, getCollectedValues().toArray());
+ }
+
+ @Test
+ public void testIn() throws Exception {
+ int EXPECTED_VALUE_SIZE = 4;
+ String sql = "SELECT ID FROM FOO WHERE NAME IN ('a', 'abc', 'ab',
'abcde')";
+ TestCompilerUtils.CalciteState state =
TestCompilerUtils.sqlOverDummyTable(sql);
+
+ final Map<String, ISqlTridentDataSource> data = new HashMap<>();
+ data.put("FOO", new TestUtils.MockSqlTridentDataSource());
+ PlanCompiler compiler = new PlanCompiler(data, typeFactory,
dataContext);
+ final AbstractTridentProcessor proc =
compiler.compileForTest(state.tree());
+ final TridentTopology topo = proc.build(data);
+ Fields f = proc.outputStream().getOutputFields();
+ proc.outputStream().partitionPersist(new TestUtils.MockStateFactory(),
f, new TestUtils.MockStateUpdater(), new Fields());
+ runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
+
+ Assert.assertArrayEquals(new Values[]{new Values(0), new Values(1),
new Values(2), new Values(4)}, getCollectedValues().toArray());
+ }
+
+ @Test
+ public void testNotIn() throws Exception {
+ int EXPECTED_VALUE_SIZE = 2;
+ String sql = "SELECT ID FROM FOO WHERE NAME NOT IN ('a', 'abc',
'abcde')";
+ TestCompilerUtils.CalciteState state =
TestCompilerUtils.sqlOverDummyTable(sql);
+
+ final Map<String, ISqlTridentDataSource> data = new HashMap<>();
+ data.put("FOO", new TestUtils.MockSqlTridentDataSource());
+ PlanCompiler compiler = new PlanCompiler(data, typeFactory,
dataContext);
+ final AbstractTridentProcessor proc =
compiler.compileForTest(state.tree());
+ final TridentTopology topo = proc.build(data);
+ Fields f = proc.outputStream().getOutputFields();
+ proc.outputStream().partitionPersist(new TestUtils.MockStateFactory(),
f, new TestUtils.MockStateUpdater(), new Fields());
+ runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
+
+ Assert.assertArrayEquals(new Values[]{new Values(1), new Values(3)},
getCollectedValues().toArray());
+ }
+
+ @Test
+ public void testCaseStatement() throws Exception {
+ int EXPECTED_VALUE_SIZE = 5;
+ String sql = "SELECT CASE WHEN NAME IN ('a', 'abc', 'abcde') THEN
UPPER('a') " +
+ "WHEN UPPER(NAME) = 'AB' THEN 'b' ELSE {fn CONCAT(NAME, '#')}
END FROM FOO";
+ TestCompilerUtils.CalciteState state =
TestCompilerUtils.sqlOverDummyTable(sql);
+
+ final Map<String, ISqlTridentDataSource> data = new HashMap<>();
+ data.put("FOO", new TestUtils.MockSqlTridentDataSource());
+ PlanCompiler compiler = new PlanCompiler(data, typeFactory,
dataContext);
+ final AbstractTridentProcessor proc =
compiler.compileForTest(state.tree());
+ final TridentTopology topo = proc.build(data);
+ Fields f = proc.outputStream().getOutputFields();
+ proc.outputStream().partitionPersist(new TestUtils.MockStateFactory(),
f, new TestUtils.MockStateUpdater(), new Fields());
+ runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
+
+ Assert.assertArrayEquals(new Values[]{new Values("A"), new
Values("b"), new Values("A"), new Values("abcd#"), new Values("A")},
getCollectedValues().toArray());
+ }
+
+ @Test
+ public void testNested() throws Exception {
+ int EXPECTED_VALUE_SIZE = 1;
+ String sql = "SELECT ID, MAPFIELD['c'], NESTEDMAPFIELD, ARRAYFIELD " +
+ "FROM FOO " +
+ "WHERE CAST(MAPFIELD['b'] AS INTEGER) = 2 AND
CAST(ARRAYFIELD[1] AS INTEGER) = 200";
+ TestCompilerUtils.CalciteState state =
TestCompilerUtils.sqlOverNestedTable(sql);
+
+ final Map<String, ISqlTridentDataSource> data = new HashMap<>();
+ data.put("FOO", new TestUtils.MockSqlTridentNestedDataSource());
+ PlanCompiler compiler = new PlanCompiler(data, typeFactory,
dataContext);
+ final AbstractTridentProcessor proc =
compiler.compileForTest(state.tree());
+ final TridentTopology topo = proc.build(data);
+ Fields f = proc.outputStream().getOutputFields();
+ proc.outputStream().partitionPersist(new TestUtils.MockStateFactory(),
f, new TestUtils.MockStateUpdater(), new Fields());
+ runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
+
+ Map<String, Integer> map = ImmutableMap.of("b", 2, "c", 4);
+ Map<String, Map<String, Integer>> nestedMap = ImmutableMap.of("a",
map);
+ Assert.assertArrayEquals(new Values[]{new Values(2, 4, nestedMap,
Arrays.asList(100, 200, 300))}, getCollectedValues().toArray());
+ }
+
+ @Test
+ public void testDateKeywords() throws Exception {
+ int EXPECTED_VALUE_SIZE = 1;
+ String sql = "SELECT " +
+ "LOCALTIME, CURRENT_TIME, LOCALTIMESTAMP, CURRENT_TIMESTAMP,
CURRENT_DATE " +
--- End diff --
Is there some way to output formatted current_date like '2016-09-26'
instead of an integer? May be we should also document what are the different
date time and other functions supported by storm-sql.
---
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.
---