Search in sources :

Example 1 with DslConverterFactory

use of org.apache.samza.sql.interfaces.DslConverterFactory in project samza by apache.

the class SamzaSqlApplicationConfig method populateSystemStreamsAndGetRelRoots.

public static Collection<RelRoot> populateSystemStreamsAndGetRelRoots(List<String> dslStmts, Config config, List<String> inputSystemStreams, List<String> outputSystemStreams) {
    // TODO: Get the converter factory based on the file type. Create abstraction around this.
    DslConverterFactory dslConverterFactory = new SamzaSqlDslConverterFactory();
    DslConverter dslConverter = dslConverterFactory.create(config);
    Collection<RelRoot> relRoots = dslConverter.convertDsl(String.join("\n", dslStmts));
    // RelRoot does not have sink node for Samza SQL dsl, so we can not traverse the relRoot tree to get
    // "outputSystemStreams"
    // FIXME: the snippet below does not work for Samza SQL dsl but is required for other dsls. Future fix could be
    // for samza sql to build TableModify for sink and stick it to the relRoot, so we could get output stream out of it.
    // for (RelRoot relRoot : relRoots) {
    // SamzaSqlApplicationConfig.populateSystemStreams(relRoot.project(), inputSystemStreams, outputSystemStreams);
    // }
    // The below code is specific to Samza SQL dsl and should be removed once Samza SQL includes sink as part of
    // relRoot and the above code in uncommented.
    List<String> sqlStmts = SamzaSqlDslConverter.fetchSqlFromConfig(config);
    List<SamzaSqlQueryParser.QueryInfo> queryInfo = SamzaSqlDslConverter.fetchQueryInfo(sqlStmts);
    inputSystemStreams.addAll(queryInfo.stream().map(SamzaSqlQueryParser.QueryInfo::getSources).flatMap(Collection::stream).collect(Collectors.toList()));
    outputSystemStreams.addAll(queryInfo.stream().map(SamzaSqlQueryParser.QueryInfo::getSink).collect(Collectors.toList()));
    return relRoots;
}
Also used : SamzaSqlDslConverter(org.apache.samza.sql.dsl.SamzaSqlDslConverter) DslConverter(org.apache.samza.sql.interfaces.DslConverter) SamzaSqlDslConverterFactory(org.apache.samza.sql.dsl.SamzaSqlDslConverterFactory) DslConverterFactory(org.apache.samza.sql.interfaces.DslConverterFactory) Collection(java.util.Collection) SamzaSqlDslConverterFactory(org.apache.samza.sql.dsl.SamzaSqlDslConverterFactory) RelRoot(org.apache.calcite.rel.RelRoot) SamzaSqlQueryParser(org.apache.samza.sql.util.SamzaSqlQueryParser)

Aggregations

Collection (java.util.Collection)1 RelRoot (org.apache.calcite.rel.RelRoot)1 SamzaSqlDslConverter (org.apache.samza.sql.dsl.SamzaSqlDslConverter)1 SamzaSqlDslConverterFactory (org.apache.samza.sql.dsl.SamzaSqlDslConverterFactory)1 DslConverter (org.apache.samza.sql.interfaces.DslConverter)1 DslConverterFactory (org.apache.samza.sql.interfaces.DslConverterFactory)1 SamzaSqlQueryParser (org.apache.samza.sql.util.SamzaSqlQueryParser)1