Search in sources :

Example 1 with SqlCreateTable

use of com.hortonworks.streamline.streams.sql.parser.SqlCreateTable in project streamline by hortonworks.

the class StreamlineSqlImpl method execute.

@Override
public void execute(Iterable<String> statements, ChannelHandler result) throws Exception {
    Map<String, DataSource> dataSources = new HashMap<>();
    for (String sql : statements) {
        StreamlineParser parser = new StreamlineParser(sql);
        SqlNode node = parser.impl().parseSqlStmtEof();
        if (node instanceof SqlCreateTable) {
            handleCreateTable((SqlCreateTable) node, dataSources);
        } else if (node instanceof SqlCreateFunction) {
            handleCreateFunction((SqlCreateFunction) node);
        } else {
            FrameworkConfig config = buildFrameWorkConfig();
            Planner planner = Frameworks.getPlanner(config);
            SqlNode parse = planner.parse(sql);
            SqlNode validate = planner.validate(parse);
            RelNode tree = planner.convert(validate);
            PlanCompiler compiler = new PlanCompiler(typeFactory);
            AbstractValuesProcessor proc = compiler.compile(tree);
            proc.initialize(dataSources, result);
        }
    }
}
Also used : StreamlineParser(com.hortonworks.streamline.streams.sql.parser.StreamlineParser) HashMap(java.util.HashMap) AbstractValuesProcessor(com.hortonworks.streamline.streams.sql.runtime.AbstractValuesProcessor) SqlCreateTable(com.hortonworks.streamline.streams.sql.parser.SqlCreateTable) DataSource(com.hortonworks.streamline.streams.sql.runtime.DataSource) PlanCompiler(com.hortonworks.streamline.streams.sql.compiler.PlanCompiler) RelNode(org.apache.calcite.rel.RelNode) SqlCreateFunction(com.hortonworks.streamline.streams.sql.parser.SqlCreateFunction) Planner(org.apache.calcite.tools.Planner) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig) SqlNode(org.apache.calcite.sql.SqlNode)

Example 2 with SqlCreateTable

use of com.hortonworks.streamline.streams.sql.parser.SqlCreateTable in project streamline by hortonworks.

the class StreamlineSqlImpl method updateSchema.

private List<FieldInfo> updateSchema(SqlCreateTable n) {
    CompilerUtil.TableBuilderInfo builder = new CompilerUtil.TableBuilderInfo(typeFactory);
    List<FieldInfo> fields = new ArrayList<>();
    for (ColumnDefinition col : n.fieldList()) {
        builder.field(col.name(), col.type(), col.constraint());
        RelDataType dataType = col.type().deriveType(typeFactory);
        Class<?> javaType = (Class<?>) typeFactory.getJavaClass(dataType);
        ColumnConstraint constraint = col.constraint();
        boolean isPrimary = constraint != null && constraint instanceof ColumnConstraint.PrimaryKey;
        fields.add(new FieldInfo(col.name(), javaType, isPrimary));
    }
    if (n.parallelism() != null) {
        builder.parallelismHint(n.parallelism());
    }
    Table table = builder.build();
    schema.add(n.tableName(), table);
    return fields;
}
Also used : CompilerUtil(com.hortonworks.streamline.streams.sql.compiler.CompilerUtil) SqlCreateTable(com.hortonworks.streamline.streams.sql.parser.SqlCreateTable) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) Table(org.apache.calcite.schema.Table) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) ColumnDefinition(com.hortonworks.streamline.streams.sql.parser.ColumnDefinition) ColumnConstraint(com.hortonworks.streamline.streams.sql.parser.ColumnConstraint) FieldInfo(com.hortonworks.streamline.streams.sql.runtime.FieldInfo)

Aggregations

SqlCreateTable (com.hortonworks.streamline.streams.sql.parser.SqlCreateTable)2 CompilerUtil (com.hortonworks.streamline.streams.sql.compiler.CompilerUtil)1 PlanCompiler (com.hortonworks.streamline.streams.sql.compiler.PlanCompiler)1 ColumnConstraint (com.hortonworks.streamline.streams.sql.parser.ColumnConstraint)1 ColumnDefinition (com.hortonworks.streamline.streams.sql.parser.ColumnDefinition)1 SqlCreateFunction (com.hortonworks.streamline.streams.sql.parser.SqlCreateFunction)1 StreamlineParser (com.hortonworks.streamline.streams.sql.parser.StreamlineParser)1 AbstractValuesProcessor (com.hortonworks.streamline.streams.sql.runtime.AbstractValuesProcessor)1 DataSource (com.hortonworks.streamline.streams.sql.runtime.DataSource)1 FieldInfo (com.hortonworks.streamline.streams.sql.runtime.FieldInfo)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 RelNode (org.apache.calcite.rel.RelNode)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 Table (org.apache.calcite.schema.Table)1 SqlNode (org.apache.calcite.sql.SqlNode)1 SqlOperatorTable (org.apache.calcite.sql.SqlOperatorTable)1 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)1 ChainedSqlOperatorTable (org.apache.calcite.sql.util.ChainedSqlOperatorTable)1 FrameworkConfig (org.apache.calcite.tools.FrameworkConfig)1