use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.
the class KsqlResource method describeTopic.
private TopicDescription describeTopic(String statementText, String name) throws KsqlException {
KsqlTopic ksqlTopic = ksqlEngine.getMetaStore().getTopic(name);
if (ksqlTopic == null) {
throw new KsqlException(String.format("Could not find Topic '%s' in the Metastore", name));
}
String schemaString = null;
TopicDescription topicDescription = new TopicDescription(statementText, name, ksqlTopic.getKafkaTopicName(), ksqlTopic.getKsqlTopicSerDe().getSerDe().toString(), schemaString);
return topicDescription;
}
use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.
the class Ksql method loadProperties.
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private static Properties loadProperties(final Optional<String> propertiesFile) {
final Properties properties = new Properties();
propertiesFile.ifPresent(file -> {
try (final FileInputStream input = new FileInputStream(file)) {
properties.load(input);
if (properties.containsKey(KsqlConfig.KSQL_SERVICE_ID_CONFIG)) {
properties.put(StreamsConfig.APPLICATION_ID_CONFIG, properties.getProperty(KsqlConfig.KSQL_SERVICE_ID_CONFIG));
}
} catch (final IOException e) {
throw new KsqlException("failed to load properties file: " + file, e);
}
});
return properties;
}
use of io.confluent.ksql.util.KsqlException 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.util.KsqlException in project ksql by confluentinc.
the class AstBuilder method visitWindowExpression.
@Override
public Node visitWindowExpression(SqlBaseParser.WindowExpressionContext ctx) {
String windowName = DEFAULT_WINDOW_NAME;
if (ctx.IDENTIFIER() != null) {
windowName = ctx.IDENTIFIER().getText();
}
windowName = windowName.toUpperCase();
if (ctx.tumblingWindowExpression() != null) {
TumblingWindowExpression tumblingWindowExpression = (TumblingWindowExpression) visitTumblingWindowExpression(ctx.tumblingWindowExpression());
return new WindowExpression(windowName, tumblingWindowExpression);
} else if (ctx.hoppingWindowExpression() != null) {
HoppingWindowExpression hoppingWindowExpression = (HoppingWindowExpression) visitHoppingWindowExpression(ctx.hoppingWindowExpression());
return new WindowExpression(windowName, hoppingWindowExpression);
} else if (ctx.sessionWindowExpression() != null) {
SessionWindowExpression sessionWindowExpression = (SessionWindowExpression) visitSessionWindowExpression(ctx.sessionWindowExpression());
return new WindowExpression(windowName, sessionWindowExpression);
}
throw new KsqlException("Window description is not correct.");
}
use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.
the class QueryEngine method maybeAddFieldsFromSchemaRegistry.
private Pair<DdlStatement, String> maybeAddFieldsFromSchemaRegistry(AbstractStreamCreateStatement streamCreateStatement) {
if (streamCreateStatement.getProperties().containsKey(DdlConfig.TOPIC_NAME_PROPERTY)) {
String ksqlRegisteredTopicName = StringUtil.cleanQuotes(streamCreateStatement.getProperties().get(DdlConfig.TOPIC_NAME_PROPERTY).toString().toUpperCase());
KsqlTopic ksqlTopic = ksqlEngine.getMetaStore().getTopic(ksqlRegisteredTopicName);
if (ksqlTopic == null) {
throw new KsqlException(String.format("Could not find %s topic in the metastore.", ksqlRegisteredTopicName));
}
Map<String, Expression> newProperties = new HashMap<>();
newProperties.put(DdlConfig.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral(ksqlTopic.getKafkaTopicName()));
newProperties.put(DdlConfig.VALUE_FORMAT_PROPERTY, new StringLiteral(ksqlTopic.getKsqlTopicSerDe().getSerDe().toString()));
streamCreateStatement = streamCreateStatement.copyWith(streamCreateStatement.getElements(), newProperties);
}
Pair<AbstractStreamCreateStatement, String> avroCheckResult = new AvroUtil().checkAndSetAvroSchema(streamCreateStatement, new HashMap<>(), ksqlEngine.getSchemaRegistryClient());
if (avroCheckResult.getRight() != null) {
if (avroCheckResult.getLeft() instanceof CreateStream) {
return new Pair<>((CreateStream) avroCheckResult.getLeft(), avroCheckResult.getRight());
} else if (avroCheckResult.getLeft() instanceof CreateTable) {
return new Pair<>((CreateTable) avroCheckResult.getLeft(), avroCheckResult.getRight());
}
}
return new Pair<>(null, null);
}
Aggregations