use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class CodeGenRunnerTest method analyzeQuery.
private Analysis analyzeQuery(String queryStr) {
List<Statement> statements = KSQL_PARSER.buildAst(queryStr, metaStore);
// Analyze the query to resolve the references and extract oeprations
Analysis analysis = new Analysis();
Analyzer analyzer = new Analyzer(queryStr, analysis, metaStore);
analyzer.process(statements.get(0), new AnalysisContext(null));
return analysis;
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class SqlToJavaVisitorTest method analyzeQuery.
private Analysis analyzeQuery(String queryStr) {
List<Statement> statements = KSQL_PARSER.buildAst(queryStr, metaStore);
// Analyze the query to resolve the references and extract oeprations
Analysis analysis = new Analysis();
Analyzer analyzer = new Analyzer("sqlExpression", analysis, metaStore);
analyzer.process(statements.get(0), new AnalysisContext(null));
return analysis;
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class StreamedQueryResource method streamQuery.
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response streamQuery(KsqlRequest request) throws Exception {
String ksql = Objects.requireNonNull(request.getKsql(), "\"ksql\" field must be given");
Map<String, Object> clientLocalProperties = Optional.ofNullable(request.getStreamsProperties()).orElse(Collections.emptyMap());
Statement statement = statementParser.parseSingleStatement(ksql);
if (statement instanceof Query) {
QueryStreamWriter queryStreamWriter = new QueryStreamWriter(ksqlEngine, disconnectCheckInterval, ksql, clientLocalProperties);
log.info("Streaming query '{}'", ksql);
return Response.ok().entity(queryStreamWriter).build();
} else if (statement instanceof PrintTopic) {
TopicStreamWriter topicStreamWriter = getTopicStreamWriter(clientLocalProperties, (PrintTopic) statement);
return Response.ok().entity(topicStreamWriter).build();
} else {
throw new Exception(String.format("Statement type `%s' not supported for this resource", statement.getClass().getName()));
}
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class StatementExecutor method handleStatementWithTerminatedQueries.
/**
* Attempt to execute a single statement.
*
* @param command The string containing the statement to be executed
* @param commandId The ID to be used to track the status of the command
* @param terminatedQueries An optional map from terminated query IDs to the commands that
* requested their termination
* @param wasDropped was this table/stream subsequently dropped
* @throws Exception TODO: Refine this.
*/
private void handleStatementWithTerminatedQueries(Command command, CommandId commandId, Map<QueryId, CommandId> terminatedQueries, boolean wasDropped) throws Exception {
try {
String statementString = command.getStatement();
statusStore.put(commandId, new CommandStatus(CommandStatus.Status.PARSING, "Parsing statement"));
Statement statement = statementParser.parseSingleStatement(statementString);
statusStore.put(commandId, new CommandStatus(CommandStatus.Status.EXECUTING, "Executing statement"));
executeStatement(statement, command, commandId, terminatedQueries, wasDropped);
} catch (WakeupException exception) {
throw exception;
} catch (Exception exception) {
log.error("Failed to handle: " + command, exception);
CommandStatus errorStatus = new CommandStatus(CommandStatus.Status.ERROR, ExceptionUtil.stackTraceToString(exception));
statusStore.put(commandId, errorStatus);
completeStatusFuture(commandId, errorStatus);
}
}
Aggregations