Search in sources :

Example 1 with SqlIOResolver

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

the class SamzaExecutor method getTableSchema.

@Override
public SqlSchema getTableSchema(ExecutionContext context, String tableName) throws ExecutorException {
    /*
     *  currently Shell works only for systems that has Avro schemas
     */
    int execId = execIdSeq.incrementAndGet();
    Map<String, String> staticConfigs = fetchSamzaSqlConfig(execId);
    Config samzaSqlConfig = new MapConfig(staticConfigs);
    SqlSchema sqlSchema;
    try {
        SqlIOResolver ioResolver = SamzaSqlApplicationConfig.createIOResolver(samzaSqlConfig);
        SqlIOConfig sourceInfo = ioResolver.fetchSourceInfo(tableName);
        RelSchemaProvider schemaProvider = SamzaSqlApplicationConfig.initializePlugin("RelSchemaProvider", sourceInfo.getRelSchemaProviderName(), samzaSqlConfig, SamzaSqlApplicationConfig.CFG_FMT_REL_SCHEMA_PROVIDER_DOMAIN, (o, c) -> ((RelSchemaProviderFactory) o).create(sourceInfo.getSystemStream(), c));
        sqlSchema = schemaProvider.getSqlSchema();
    } catch (SamzaException ex) {
        throw new ExecutorException(ex);
    }
    return sqlSchema;
}
Also used : SqlIOConfig(org.apache.samza.sql.interfaces.SqlIOConfig) ExecutorException(org.apache.samza.sql.client.exceptions.ExecutorException) SqlSchema(org.apache.samza.sql.schema.SqlSchema) SamzaSqlApplicationConfig(org.apache.samza.sql.runner.SamzaSqlApplicationConfig) SqlIOConfig(org.apache.samza.sql.interfaces.SqlIOConfig) SqlIOResolver(org.apache.samza.sql.interfaces.SqlIOResolver) RelSchemaProvider(org.apache.samza.sql.interfaces.RelSchemaProvider) SamzaException(org.apache.samza.SamzaException)

Example 2 with SqlIOResolver

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

the class SamzaSqlApplicationRunner method computeSamzaConfigs.

public static Config computeSamzaConfigs(Boolean localRunner, Config config) {
    Map<String, String> newConfig = new HashMap<>();
    // TODO: Introduce an API to return a dsl string containing one or more sql statements
    List<String> dslStmts = SamzaSqlDslConverter.fetchSqlFromConfig(config);
    // This is needed because the SQL file may not be available in all the node managers.
    String sqlJson = SamzaSqlApplicationConfig.serializeSqlStmts(dslStmts);
    newConfig.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, sqlJson);
    List<String> inputSystemStreams = new LinkedList<>();
    List<String> outputSystemStreams = new LinkedList<>();
    SamzaSqlApplicationConfig.populateSystemStreamsAndGetRelRoots(dslStmts, config, inputSystemStreams, outputSystemStreams);
    SqlIOResolver ioResolver = SamzaSqlApplicationConfig.createIOResolver(config);
    // Populate stream to system mapping config for input and output system streams
    for (String source : inputSystemStreams) {
        SqlIOConfig inputSystemStreamConfig = ioResolver.fetchSourceInfo(source);
        newConfig.put(String.format(CFG_FMT_SAMZA_STREAM_SYSTEM, inputSystemStreamConfig.getStreamId()), inputSystemStreamConfig.getSystemName());
        newConfig.putAll(inputSystemStreamConfig.getConfig());
    }
    for (String sink : outputSystemStreams) {
        SqlIOConfig outputSystemStreamConfig = ioResolver.fetchSinkInfo(sink);
        newConfig.put(String.format(CFG_FMT_SAMZA_STREAM_SYSTEM, outputSystemStreamConfig.getStreamId()), outputSystemStreamConfig.getSystemName());
        newConfig.putAll(outputSystemStreamConfig.getConfig());
    }
    newConfig.putAll(config);
    if (localRunner) {
        newConfig.put(ApplicationConfig.APP_RUNNER_CLASS, LocalApplicationRunner.class.getName());
    } else {
        newConfig.put(ApplicationConfig.APP_RUNNER_CLASS, RemoteApplicationRunner.class.getName());
    }
    LOG.info("New Samza configs: " + newConfig);
    return new MapConfig(newConfig);
}
Also used : SqlIOConfig(org.apache.samza.sql.interfaces.SqlIOConfig) RemoteApplicationRunner(org.apache.samza.runtime.RemoteApplicationRunner) HashMap(java.util.HashMap) SqlIOResolver(org.apache.samza.sql.interfaces.SqlIOResolver) MapConfig(org.apache.samza.config.MapConfig) LinkedList(java.util.LinkedList) LocalApplicationRunner(org.apache.samza.runtime.LocalApplicationRunner)

Aggregations

SqlIOConfig (org.apache.samza.sql.interfaces.SqlIOConfig)2 SqlIOResolver (org.apache.samza.sql.interfaces.SqlIOResolver)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 SamzaException (org.apache.samza.SamzaException)1 MapConfig (org.apache.samza.config.MapConfig)1 LocalApplicationRunner (org.apache.samza.runtime.LocalApplicationRunner)1 RemoteApplicationRunner (org.apache.samza.runtime.RemoteApplicationRunner)1 ExecutorException (org.apache.samza.sql.client.exceptions.ExecutorException)1 RelSchemaProvider (org.apache.samza.sql.interfaces.RelSchemaProvider)1 SamzaSqlApplicationConfig (org.apache.samza.sql.runner.SamzaSqlApplicationConfig)1 SqlSchema (org.apache.samza.sql.schema.SqlSchema)1