Search in sources :

Example 1 with AstBuilder

use of io.confluent.ksql.parser.AstBuilder in project ksql by confluentinc.

the class CliUtils method getAvroSchemaIfAvroTopic.

public Optional<String> getAvroSchemaIfAvroTopic(SqlBaseParser.RegisterTopicContext registerTopicContext) {
    AstBuilder astBuilder = new AstBuilder(null);
    RegisterTopic registerTopic = (RegisterTopic) astBuilder.visitRegisterTopic(registerTopicContext);
    if (registerTopic.getProperties().get(DdlConfig.VALUE_FORMAT_PROPERTY) == null) {
        throw new KsqlException("VALUE_FORMAT is not set for the topic.");
    }
    if (registerTopic.getProperties().get(DdlConfig.VALUE_FORMAT_PROPERTY).toString().equalsIgnoreCase("'AVRO'")) {
        if (registerTopic.getProperties().containsKey(DdlConfig.AVRO_SCHEMA_FILE)) {
            String avroSchema = getAvroSchema(AstBuilder.unquote(registerTopic.getProperties().get(DdlConfig.AVRO_SCHEMA_FILE).toString(), "'"));
            return Optional.of(avroSchema);
        } else {
            throw new KsqlException("You need to provide avro schema file path for topics in avro format.");
        }
    }
    return Optional.empty();
}
Also used : AstBuilder(io.confluent.ksql.parser.AstBuilder) RegisterTopic(io.confluent.ksql.parser.tree.RegisterTopic)

Aggregations

AstBuilder (io.confluent.ksql.parser.AstBuilder)1 RegisterTopic (io.confluent.ksql.parser.tree.RegisterTopic)1