@Override public boolean equals(final Object o) { if (this == o) { return true; } if (!(o instanceof PrintTopic)) { return false; } final PrintTopic that = (PrintTopic) o; return getFromBeginning() == that.getFromBeginning() && Objects.equals(getTopic(), that.getTopic()) && getIntervalValue() == that.getIntervalValue(); }
private void handlePrintTopic(final SessionAndRequest info, final PrintTopic printTopic) { final String topicName = printTopic.getTopic().toString(); if (!serviceContext.getTopicClient().isTopicExists(topicName)) { throw new IllegalArgumentException( "Topic does not exist, or KSQL does not have permission to list the topic: " + topicName); } final WebSocketSubscriber<String> topicSubscriber = new WebSocketSubscriber<>(info.session, mapper); this.subscriber = topicSubscriber; topicPublisher.start(exec, serviceContext.getSchemaRegistryClient(), ksqlConfig.getKsqlStreamConfigProps(), topicName, printTopic.getFromBeginning(), topicSubscriber ); }
private static PrintTopic printTopic(final String name, final boolean fromBeginning) { return new PrintTopic( new NodeLocation(0, 1), QualifiedName.of(name), fromBeginning, Optional.empty() ); }
@Override public Node visitPrintTopic(final SqlBaseParser.PrintTopicContext context) { final 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, Optional.empty() ); } else if (context.number() instanceof SqlBaseParser.IntegerLiteralContext) { final SqlBaseParser.IntegerLiteralContext integerLiteralContext = (SqlBaseParser.IntegerLiteralContext) context.number(); final IntegerLiteral literal = (IntegerLiteral) visitIntegerLiteral(integerLiteralContext); return new PrintTopic( getLocation(context), topicName, fromBeginning, Optional.of(literal.getValue()) ); } else { throw new KsqlException("Interval value should be integer in 'PRINT' command!"); } }
@Override public int hashCode() { return Objects.hash(getTopic(), getFromBeginning(), getIntervalValue()); }
private Response handlePrintTopic(final PreparedStatement<PrintTopic> statement) { final PrintTopic printTopic = statement.getStatement(); final String topicName = printTopic.getTopic().toString(); if (!serviceContext.getTopicClient().isTopicExists(topicName)) { throw new KsqlRestException( Errors.badRequest(String.format( "Could not find topic '%s', " + "or the KSQL user does not have permissions to list the topic." + System.lineSeparator() + "KSQL will treat unquoted topic names as uppercase." + System.lineSeparator() + "To print a case-sensitive topic use quotes, for example: print \'Topic\';", topicName))); } final TopicStreamWriter topicStreamWriter = new TopicStreamWriter( serviceContext.getSchemaRegistryClient(), ksqlConfig.getKsqlStreamConfigProps(), topicName, printTopic.getIntervalValue(), disconnectCheckInterval, printTopic.getFromBeginning() ); log.info("Printing topic '{}'", topicName); return Response.ok().entity(topicStreamWriter).build(); } }