Search in sources :

Example 1 with QueryPlanner

use of org.apache.samza.sql.planner.QueryPlanner in project samza by apache.

the class QueryTranslator method translate.

/**
 * For unit testing only
 */
@VisibleForTesting
void translate(SamzaSqlQueryParser.QueryInfo queryInfo, StreamApplicationDescriptor appDesc, int queryId) {
    QueryPlanner planner = new QueryPlanner(sqlConfig.getRelSchemaProviders(), sqlConfig.getInputSystemStreamConfigBySource(), sqlConfig.getUdfMetadata(), sqlConfig.isQueryPlanOptimizerEnabled());
    final RelRoot relRoot = planner.plan(queryInfo.getSelectQuery());
    SamzaSqlExecutionContext executionContext = new SamzaSqlExecutionContext(sqlConfig);
    TranslatorContext translatorContext = new TranslatorContext(appDesc, relRoot, executionContext);
    translate(relRoot, sqlConfig.getOutputSystemStreams().get(queryId), translatorContext, queryId);
    Map<Integer, TranslatorContext> translatorContexts = new HashMap<>();
    translatorContexts.put(queryId, translatorContext.clone());
    appDesc.withApplicationTaskContextFactory(new ApplicationTaskContextFactory<SamzaSqlApplicationContext>() {

        @Override
        public SamzaSqlApplicationContext create(ExternalContext externalContext, JobContext jobContext, ContainerContext containerContext, TaskContext taskContext, ApplicationContainerContext applicationContainerContext) {
            return new SamzaSqlApplicationContext(translatorContexts);
        }
    });
}
Also used : TaskContext(org.apache.samza.context.TaskContext) HashMap(java.util.HashMap) RelRoot(org.apache.calcite.rel.RelRoot) QueryPlanner(org.apache.samza.sql.planner.QueryPlanner) ApplicationContainerContext(org.apache.samza.context.ApplicationContainerContext) ContainerContext(org.apache.samza.context.ContainerContext) ApplicationContainerContext(org.apache.samza.context.ApplicationContainerContext) SamzaSqlApplicationContext(org.apache.samza.sql.runner.SamzaSqlApplicationContext) ExternalContext(org.apache.samza.context.ExternalContext) SamzaSqlExecutionContext(org.apache.samza.sql.data.SamzaSqlExecutionContext) JobContext(org.apache.samza.context.JobContext) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with QueryPlanner

use of org.apache.samza.sql.planner.QueryPlanner in project samza by apache.

the class SamzaSqlDslConverter method convertDsl.

@Override
public Collection<RelRoot> convertDsl(String dsl) {
    // TODO: Introduce an API to parse a dsl string and return one or more sql statements
    List<String> sqlStmts = fetchSqlFromConfig(config);
    List<RelRoot> relRoots = new LinkedList<>();
    for (String sql : sqlStmts) {
        QueryPlanner planner = getQueryPlanner(getSqlConfig(Collections.singletonList(sql), config));
        // we always pass only select query to the planner for samza sql. The reason is that samza sql supports
        // schema evolution where source and destination could up to an extent have independent schema evolution while
        // calcite expects strict comformance of the destination schema with that of the fields in the select query.
        SamzaSqlQueryParser.QueryInfo qinfo = SamzaSqlQueryParser.parseQuery(sql);
        RelRoot relRoot = planner.plan(qinfo.getSelectQuery());
        relRoots.add(relRoot);
    }
    return relRoots;
}
Also used : RelRoot(org.apache.calcite.rel.RelRoot) SamzaSqlQueryParser(org.apache.samza.sql.util.SamzaSqlQueryParser) LinkedList(java.util.LinkedList) QueryPlanner(org.apache.samza.sql.planner.QueryPlanner)

Aggregations

RelRoot (org.apache.calcite.rel.RelRoot)2 QueryPlanner (org.apache.samza.sql.planner.QueryPlanner)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 ApplicationContainerContext (org.apache.samza.context.ApplicationContainerContext)1 ContainerContext (org.apache.samza.context.ContainerContext)1 ExternalContext (org.apache.samza.context.ExternalContext)1 JobContext (org.apache.samza.context.JobContext)1 TaskContext (org.apache.samza.context.TaskContext)1 SamzaSqlExecutionContext (org.apache.samza.sql.data.SamzaSqlExecutionContext)1 SamzaSqlApplicationContext (org.apache.samza.sql.runner.SamzaSqlApplicationContext)1 SamzaSqlQueryParser (org.apache.samza.sql.util.SamzaSqlQueryParser)1