Search in sources :

Example 1 with PrintTopic

use of io.confluent.ksql.parser.tree.PrintTopic in project ksql by confluentinc.

the class AstBuilder method visitPrintTopic.

@Override
public Node visitPrintTopic(SqlBaseParser.PrintTopicContext context) {
    boolean fromBeginning = context.FROM() != null;
    QualifiedName topicName = null;
    if (context.STRING() != null) {
        topicName = QualifiedName.of(unquote(context.STRING().getText(), "'"));
    } else {
        topicName = getQualifiedName(context.qualifiedName());
    }
    if (context.number() == null) {
        return new PrintTopic(getLocation(context), topicName, fromBeginning, null);
    } else if (context.number() instanceof SqlBaseParser.IntegerLiteralContext) {
        SqlBaseParser.IntegerLiteralContext integerLiteralContext = (SqlBaseParser.IntegerLiteralContext) context.number();
        return new PrintTopic(getLocation(context), topicName, fromBeginning, (LongLiteral) visitIntegerLiteral(integerLiteralContext));
    } else {
        throw new KsqlException("Interval value should be integer in 'PRINT' command!");
    }
}
Also used : LongLiteral(io.confluent.ksql.parser.tree.LongLiteral) QualifiedName(io.confluent.ksql.parser.tree.QualifiedName) PrintTopic(io.confluent.ksql.parser.tree.PrintTopic) KsqlException(io.confluent.ksql.util.KsqlException)

Example 2 with PrintTopic

use of io.confluent.ksql.parser.tree.PrintTopic 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)

Aggregations

PrintTopic (io.confluent.ksql.parser.tree.PrintTopic)2 LongLiteral (io.confluent.ksql.parser.tree.LongLiteral)1 QualifiedName (io.confluent.ksql.parser.tree.QualifiedName)1 Query (io.confluent.ksql.parser.tree.Query)1 Statement (io.confluent.ksql.parser.tree.Statement)1 KsqlException (io.confluent.ksql.util.KsqlException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1