Search in sources :

Example 1 with SamzaSqlApplicationRunner

use of org.apache.samza.sql.runner.SamzaSqlApplicationRunner in project samza by apache.

the class SamzaSqlConsole method executeSql.

public static void executeSql(List<String> sqlStmts) {
    Map<String, String> staticConfigs = fetchSamzaSqlConfig();
    staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, JsonUtil.toJson(sqlStmts));
    SamzaSqlApplicationRunner runner = new SamzaSqlApplicationRunner(true, new MapConfig(staticConfigs));
    runner.runAndWaitForFinish();
}
Also used : SamzaSqlApplicationRunner(org.apache.samza.sql.runner.SamzaSqlApplicationRunner) MapConfig(org.apache.samza.config.MapConfig)

Example 2 with SamzaSqlApplicationRunner

use of org.apache.samza.sql.runner.SamzaSqlApplicationRunner in project samza by apache.

the class SamzaExecutor method executeNonQuery.

@Override
public NonQueryResult executeNonQuery(ExecutionContext context, List<String> statement) throws ExecutorException {
    int execId = execIdSeq.incrementAndGet();
    Map<String, String> staticConfigs = fetchSamzaSqlConfig(execId);
    staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, JsonUtil.toJson(formatSqlStmts(statement)));
    SamzaSqlApplicationRunner runner;
    try {
        runner = new SamzaSqlApplicationRunner(true, new MapConfig(staticConfigs));
        runner.run(null);
    } catch (SamzaException ex) {
        throw new ExecutorException(ex);
    }
    executions.put(execId, runner);
    LOG.debug("Executing sql. Id ", execId);
    return new NonQueryResult(execId);
}
Also used : ExecutorException(org.apache.samza.sql.client.exceptions.ExecutorException) SamzaSqlApplicationRunner(org.apache.samza.sql.runner.SamzaSqlApplicationRunner) SamzaException(org.apache.samza.SamzaException)

Example 3 with SamzaSqlApplicationRunner

use of org.apache.samza.sql.runner.SamzaSqlApplicationRunner in project samza by apache.

the class SamzaSqlIntegrationTestHarness method runApplication.

protected void runApplication(Config config) {
    // Use MockSystemFactory for the coordinator system
    MockSystemFactory.MSG_QUEUES.put(new SystemStreamPartition(MOCK_METADATA_SYSTEM, CoordinatorStreamUtil.getCoordinatorStreamName(SamzaSqlTestConfig.SQL_JOB, SamzaSqlTestConfig.SQL_JOB_PROCESSOR_ID), new Partition(0)), new ArrayList<>());
    HashMap<String, String> mapConfig = new HashMap<>();
    mapConfig.put(JobConfig.JOB_COORDINATOR_SYSTEM, MOCK_METADATA_SYSTEM);
    mapConfig.put(String.format(SystemConfig.SYSTEM_FACTORY_FORMAT, MOCK_METADATA_SYSTEM), MockSystemFactory.class.getName());
    // configs for using in-memory system as the default system
    mapConfig.putAll(baseInMemorySystemConfigs());
    mapConfig.putAll(config);
    SamzaSqlApplicationRunner runner = new SamzaSqlApplicationRunner(true, new MapConfig(mapConfig));
    executeRun(runner, config);
    runner.waitForFinish();
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) SamzaSqlApplicationRunner(org.apache.samza.sql.runner.SamzaSqlApplicationRunner) HashMap(java.util.HashMap) MapConfig(org.apache.samza.config.MapConfig) MockSystemFactory(org.apache.samza.system.MockSystemFactory) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition)

Example 4 with SamzaSqlApplicationRunner

use of org.apache.samza.sql.runner.SamzaSqlApplicationRunner in project samza by apache.

the class SamzaExecutor method executeQuery.

@Override
public QueryResult executeQuery(ExecutionContext context, String statement) throws ExecutorException {
    outputData.clear();
    int execId = execIdSeq.incrementAndGet();
    Map<String, String> staticConfigs = fetchSamzaSqlConfig(execId);
    List<String> sqlStmts = formatSqlStmts(Collections.singletonList(statement));
    staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, JsonUtil.toJson(sqlStmts));
    SamzaSqlApplicationRunner runner;
    try {
        runner = new SamzaSqlApplicationRunner(true, new MapConfig(staticConfigs));
        runner.run(null);
    } catch (SamzaException ex) {
        throw new ExecutorException(ex);
    }
    executions.put(execId, runner);
    LOG.debug("Executing sql. Id ", execId);
    SqlSchema resultSchema = null;
    // resultSchema = generateResultSchema(new MapConfig(staticConfigs));
    return new QueryResult(execId, resultSchema);
}
Also used : ExecutorException(org.apache.samza.sql.client.exceptions.ExecutorException) SamzaSqlApplicationRunner(org.apache.samza.sql.runner.SamzaSqlApplicationRunner) SqlSchema(org.apache.samza.sql.schema.SqlSchema) SamzaException(org.apache.samza.SamzaException)

Aggregations

SamzaSqlApplicationRunner (org.apache.samza.sql.runner.SamzaSqlApplicationRunner)4 SamzaException (org.apache.samza.SamzaException)2 MapConfig (org.apache.samza.config.MapConfig)2 ExecutorException (org.apache.samza.sql.client.exceptions.ExecutorException)2 HashMap (java.util.HashMap)1 Partition (org.apache.samza.Partition)1 SqlSchema (org.apache.samza.sql.schema.SqlSchema)1 MockSystemFactory (org.apache.samza.system.MockSystemFactory)1 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)1