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;
}
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);
}
Aggregations