Search in sources :

Example 1 with PlanCompiler

use of com.hortonworks.streamline.streams.sql.compiler.PlanCompiler in project streamline by hortonworks.

the class TestPlanCompiler method testNested.

@Test
public void testNested() throws Exception {
    String sql = "SELECT ID, MAPFIELD['c'], NESTEDMAPFIELD, ARRAYFIELD " + "FROM FOO " + "WHERE NESTEDMAPFIELD['a']['b'] = 2 AND ARRAYFIELD[2] = 200";
    TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverNestedTable(sql);
    PlanCompiler compiler = new PlanCompiler(typeFactory);
    AbstractValuesProcessor proc = compiler.compile(state.tree());
    Map<String, DataSource> data = new HashMap<>();
    data.put("FOO", new TestUtils.MockNestedDataSource());
    List<CorrelatedValues> values = new ArrayList<>();
    ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
    proc.initialize(data, h);
    Map<String, Integer> map = ImmutableMap.of("b", 2, "c", 4);
    Map<String, Map<String, Integer>> nestedMap = ImmutableMap.of("a", map);
    Assert.assertEquals(1, values.size());
    Assert.assertEquals(4, values.get(0).size());
    Assert.assertEquals(2, values.get(0).get(0));
    Assert.assertEquals(4, values.get(0).get(1));
    Assert.assertEquals(nestedMap, values.get(0).get(2));
    Assert.assertEquals(Arrays.asList(100, 200, 300), values.get(0).get(3));
}
Also used : CorrelatedValues(com.hortonworks.streamline.streams.sql.runtime.CorrelatedValues) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AbstractValuesProcessor(com.hortonworks.streamline.streams.sql.runtime.AbstractValuesProcessor) ChannelHandler(com.hortonworks.streamline.streams.sql.runtime.ChannelHandler) DataSource(com.hortonworks.streamline.streams.sql.runtime.DataSource) PlanCompiler(com.hortonworks.streamline.streams.sql.compiler.PlanCompiler) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with PlanCompiler

use of com.hortonworks.streamline.streams.sql.compiler.PlanCompiler in project streamline by hortonworks.

the class TestExprSemantic method testExpr.

private Values testExpr(List<String> exprs) throws Exception {
    String sql = "SELECT " + Joiner.on(',').join(exprs) + " FROM FOO" + " WHERE ID > 0 AND ID < 2";
    TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
    PlanCompiler compiler = new PlanCompiler(typeFactory);
    AbstractValuesProcessor proc = compiler.compile(state.tree());
    Map<String, DataSource> data = new HashMap<>();
    data.put("FOO", new TestUtils.MockDataSource());
    List<CorrelatedValues> values = new ArrayList<>();
    ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
    proc.initialize(data, h);
    return values.get(0);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PlanCompiler(com.hortonworks.streamline.streams.sql.compiler.PlanCompiler)

Example 3 with PlanCompiler

use of com.hortonworks.streamline.streams.sql.compiler.PlanCompiler in project streamline by hortonworks.

the class TestPlanCompiler method testUdf.

@Test
public void testUdf() throws Exception {
    String sql = "SELECT MYPLUS(ID, 3)" + "FROM FOO " + "WHERE ID = 2";
    TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverNestedTable(sql);
    PlanCompiler compiler = new PlanCompiler(typeFactory);
    AbstractValuesProcessor proc = compiler.compile(state.tree());
    Map<String, DataSource> data = new HashMap<>();
    data.put("FOO", new TestUtils.MockDataSource());
    List<CorrelatedValues> values = new ArrayList<>();
    ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
    proc.initialize(data, h);
    Assert.assertEquals(1, values.size());
    Assert.assertEquals(1, values.get(0).size());
    Assert.assertEquals(5, values.get(0).get(0));
}
Also used : CorrelatedValues(com.hortonworks.streamline.streams.sql.runtime.CorrelatedValues) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AbstractValuesProcessor(com.hortonworks.streamline.streams.sql.runtime.AbstractValuesProcessor) ChannelHandler(com.hortonworks.streamline.streams.sql.runtime.ChannelHandler) DataSource(com.hortonworks.streamline.streams.sql.runtime.DataSource) PlanCompiler(com.hortonworks.streamline.streams.sql.compiler.PlanCompiler) Test(org.junit.Test)

Example 4 with PlanCompiler

use of com.hortonworks.streamline.streams.sql.compiler.PlanCompiler in project streamline by hortonworks.

the class TestPlanCompiler method testCompile.

@Test
public void testCompile() throws Exception {
    String sql = "SELECT ID + 1 FROM FOO WHERE ID > 2";
    TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
    PlanCompiler compiler = new PlanCompiler(typeFactory);
    AbstractValuesProcessor proc = compiler.compile(state.tree());
    Map<String, DataSource> data = new HashMap<>();
    data.put("FOO", new TestUtils.MockDataSource());
    List<CorrelatedValues> values = new ArrayList<>();
    ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
    proc.initialize(data, h);
    Assert.assertEquals(2, values.size());
    Assert.assertEquals(1, values.get(0).size());
    Assert.assertEquals(4, values.get(0).get(0));
    Assert.assertEquals(1, values.get(1).size());
    Assert.assertEquals(5, values.get(1).get(0));
}
Also used : CorrelatedValues(com.hortonworks.streamline.streams.sql.runtime.CorrelatedValues) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AbstractValuesProcessor(com.hortonworks.streamline.streams.sql.runtime.AbstractValuesProcessor) ChannelHandler(com.hortonworks.streamline.streams.sql.runtime.ChannelHandler) DataSource(com.hortonworks.streamline.streams.sql.runtime.DataSource) PlanCompiler(com.hortonworks.streamline.streams.sql.compiler.PlanCompiler) Test(org.junit.Test)

Example 5 with PlanCompiler

use of com.hortonworks.streamline.streams.sql.compiler.PlanCompiler in project streamline by hortonworks.

the class TestPlanCompiler method testLogicalExpr.

@Test
public void testLogicalExpr() throws Exception {
    String sql = "SELECT ID > 0 OR ID < 1, ID > 0 AND ID < 1, NOT (ID > 0 AND ID < 1) FROM FOO WHERE ID > 0 AND ID < 2";
    TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
    PlanCompiler compiler = new PlanCompiler(typeFactory);
    AbstractValuesProcessor proc = compiler.compile(state.tree());
    Map<String, DataSource> data = new HashMap<>();
    data.put("FOO", new TestUtils.MockDataSource());
    List<CorrelatedValues> values = new ArrayList<>();
    ChannelHandler h = new TestUtils.CollectDataChannelHandler(values);
    proc.initialize(data, h);
    Assert.assertEquals(1, values.size());
    Assert.assertEquals(3, values.get(0).size());
    Assert.assertEquals(true, values.get(0).get(0));
    Assert.assertEquals(false, values.get(0).get(1));
    Assert.assertEquals(true, values.get(0).get(2));
}
Also used : CorrelatedValues(com.hortonworks.streamline.streams.sql.runtime.CorrelatedValues) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AbstractValuesProcessor(com.hortonworks.streamline.streams.sql.runtime.AbstractValuesProcessor) ChannelHandler(com.hortonworks.streamline.streams.sql.runtime.ChannelHandler) DataSource(com.hortonworks.streamline.streams.sql.runtime.DataSource) PlanCompiler(com.hortonworks.streamline.streams.sql.compiler.PlanCompiler) Test(org.junit.Test)

Aggregations

PlanCompiler (com.hortonworks.streamline.streams.sql.compiler.PlanCompiler)6 HashMap (java.util.HashMap)6 AbstractValuesProcessor (com.hortonworks.streamline.streams.sql.runtime.AbstractValuesProcessor)5 DataSource (com.hortonworks.streamline.streams.sql.runtime.DataSource)5 ArrayList (java.util.ArrayList)5 ChannelHandler (com.hortonworks.streamline.streams.sql.runtime.ChannelHandler)4 CorrelatedValues (com.hortonworks.streamline.streams.sql.runtime.CorrelatedValues)4 Test (org.junit.Test)4 ImmutableMap (com.google.common.collect.ImmutableMap)1 SqlCreateFunction (com.hortonworks.streamline.streams.sql.parser.SqlCreateFunction)1 SqlCreateTable (com.hortonworks.streamline.streams.sql.parser.SqlCreateTable)1 StreamlineParser (com.hortonworks.streamline.streams.sql.parser.StreamlineParser)1 Map (java.util.Map)1 RelNode (org.apache.calcite.rel.RelNode)1 SqlNode (org.apache.calcite.sql.SqlNode)1 FrameworkConfig (org.apache.calcite.tools.FrameworkConfig)1 Planner (org.apache.calcite.tools.Planner)1