Search in sources :

Example 51 with Statement

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;
}
Also used : Statement(io.confluent.ksql.parser.tree.Statement) Analysis(io.confluent.ksql.analyzer.Analysis) AnalysisContext(io.confluent.ksql.analyzer.AnalysisContext) Analyzer(io.confluent.ksql.analyzer.Analyzer)

Example 52 with Statement

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;
}
Also used : Statement(io.confluent.ksql.parser.tree.Statement) Analysis(io.confluent.ksql.analyzer.Analysis) AnalysisContext(io.confluent.ksql.analyzer.AnalysisContext) Analyzer(io.confluent.ksql.analyzer.Analyzer)

Example 53 with Statement

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()));
    }
}
Also used : Query(io.confluent.ksql.parser.tree.Query) Statement(io.confluent.ksql.parser.tree.Statement) PrintTopic(io.confluent.ksql.parser.tree.PrintTopic) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 54 with Statement

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);
    }
}
Also used : DdlStatement(io.confluent.ksql.parser.tree.DdlStatement) Statement(io.confluent.ksql.parser.tree.Statement) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) WakeupException(org.apache.kafka.common.errors.WakeupException) WakeupException(org.apache.kafka.common.errors.WakeupException) KsqlException(io.confluent.ksql.util.KsqlException)

Aggregations

Statement (io.confluent.ksql.parser.tree.Statement)54 Test (org.junit.Test)38 Query (io.confluent.ksql.parser.tree.Query)24 QuerySpecification (io.confluent.ksql.parser.tree.QuerySpecification)18 AliasedRelation (io.confluent.ksql.parser.tree.AliasedRelation)7 SingleColumn (io.confluent.ksql.parser.tree.SingleColumn)7 KsqlException (io.confluent.ksql.util.KsqlException)7 Analysis (io.confluent.ksql.analyzer.Analysis)6 AnalysisContext (io.confluent.ksql.analyzer.AnalysisContext)6 Analyzer (io.confluent.ksql.analyzer.Analyzer)6 DdlStatement (io.confluent.ksql.parser.tree.DdlStatement)5 Expression (io.confluent.ksql.parser.tree.Expression)5 ArrayList (java.util.ArrayList)5 ComparisonExpression (io.confluent.ksql.parser.tree.ComparisonExpression)4 PlanNode (io.confluent.ksql.planner.plan.PlanNode)4 AggregateAnalysis (io.confluent.ksql.analyzer.AggregateAnalysis)3 AggregateAnalyzer (io.confluent.ksql.analyzer.AggregateAnalyzer)3 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)3 AbstractStreamCreateStatement (io.confluent.ksql.parser.tree.AbstractStreamCreateStatement)3 DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)3