use of org.apache.samza.sql.client.exceptions.ExecutorException in project samza by apache.
the class SamzaExecutor method executeNonQuery.
@Override
public NonQueryResult executeNonQuery(ExecutionContext context, File sqlFile) throws ExecutorException {
LOG.info("Sql file path: " + sqlFile.getPath());
List<String> executedStmts;
try {
executedStmts = Files.lines(Paths.get(sqlFile.getPath())).collect(Collectors.toList());
} catch (IOException e) {
throw new ExecutorException(e);
}
LOG.info("Sql statements in Sql file: " + executedStmts.toString());
List<String> submittedStmts = new ArrayList<>();
List<String> nonSubmittedStmts = new ArrayList<>();
validateExecutedStmts(executedStmts, submittedStmts, nonSubmittedStmts);
if (submittedStmts.isEmpty()) {
throw new ExecutorException("Nothing to execute. Note: SELECT statements are ignored.");
}
NonQueryResult result = executeNonQuery(context, submittedStmts);
return new NonQueryResult(result.getExecutionId(), submittedStmts, nonSubmittedStmts);
}
use of org.apache.samza.sql.client.exceptions.ExecutorException 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.client.exceptions.ExecutorException 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);
}
use of org.apache.samza.sql.client.exceptions.ExecutorException in project samza by apache.
the class CliCommandHandler method commandLs.
private void commandLs(CliCommand command) {
List<Integer> execIds = new ArrayList<>();
String parameters = command.getParameters();
if (CliUtil.isNullOrEmpty(parameters)) {
execIds.addAll(executions.keySet());
} else {
execIds.addAll(splitExecutionIds(parameters));
}
if (execIds.size() == 0) {
return;
}
execIds.sort(Integer::compareTo);
final int terminalWidth = terminal.getWidth();
final int idWidth = 3;
final int statusWidth = 20;
final int cmdWidth = terminalWidth - idWidth - statusWidth - 4;
AttributedStyle oddLineStyle = AttributedStyle.DEFAULT.BOLD.foreground(AttributedStyle.BLUE);
AttributedStyle evenLineStyle = AttributedStyle.DEFAULT.BOLD.foreground(AttributedStyle.CYAN);
for (int i = 0; i < execIds.size(); ++i) {
Integer id = execIds.get(i);
String cmd = executions.get(id);
if (cmd == null)
continue;
String status = "UNKNOWN";
try {
ExecutionStatus execStatus = executor.queryExecutionStatus(id);
status = execStatus.name();
} catch (ExecutorException e) {
LOG.error("Error in commandLs: ", e);
}
int cmdStartIdx = 0;
int cmdLength = cmd.length();
StringBuilder line;
while (cmdStartIdx < cmdLength) {
line = new StringBuilder(terminalWidth);
if (cmdStartIdx == 0) {
line.append(CliConstants.SPACE);
line.append(id);
CliUtil.appendTo(line, 1 + idWidth + 1, CliConstants.SPACE);
line.append(status);
}
CliUtil.appendTo(line, 1 + idWidth + 1 + statusWidth + 1, CliConstants.SPACE);
int numToWrite = Math.min(cmdWidth, cmdLength - cmdStartIdx);
if (numToWrite > 0) {
line.append(cmd, cmdStartIdx, cmdStartIdx + numToWrite);
cmdStartIdx += numToWrite;
}
if (i % 2 == 0) {
AttributedStringBuilder attrBuilder = new AttributedStringBuilder().style(evenLineStyle);
attrBuilder.append(line.toString());
writer.println(attrBuilder.toAnsi());
} else {
AttributedStringBuilder attrBuilder = new AttributedStringBuilder().style(oddLineStyle);
attrBuilder.append(line.toString());
writer.println(attrBuilder.toAnsi());
}
}
}
writer.flush();
}
use of org.apache.samza.sql.client.exceptions.ExecutorException in project samza by apache.
the class CliCommandHandler method commandRm.
private void commandRm(CliCommand command) {
String parameters = command.getParameters();
List<Integer> execIds = new ArrayList<>();
execIds.addAll(splitExecutionIds(parameters));
for (Integer id : execIds) {
try {
ExecutionStatus status = executor.queryExecutionStatus(id);
if (status == ExecutionStatus.Running) {
writer.println(String.format("Execution %d is still running. Stop it first.", id));
continue;
}
executor.removeExecution(exeContext, id);
executions.remove(id);
} catch (ExecutorException e) {
writer.println("Error: " + e);
LOG.error("Error in commandRm: ", e);
}
}
writer.flush();
}
Aggregations