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!");
}
}
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()));
}
}
Aggregations