Search in sources :

Example 21 with KsqlException

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;
}
Also used : TopicDescription(io.confluent.ksql.rest.entity.TopicDescription) KsqlException(io.confluent.ksql.util.KsqlException) KsqlTopic(io.confluent.ksql.metastore.KsqlTopic)

Example 22 with KsqlException

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;
}
Also used : IOException(java.io.IOException) Properties(java.util.Properties) KsqlException(io.confluent.ksql.util.KsqlException) FileInputStream(java.io.FileInputStream)

Example 23 with KsqlException

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!");
    }
}
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 24 with KsqlException

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.");
}
Also used : HoppingWindowExpression(io.confluent.ksql.parser.tree.HoppingWindowExpression) TumblingWindowExpression(io.confluent.ksql.parser.tree.TumblingWindowExpression) HoppingWindowExpression(io.confluent.ksql.parser.tree.HoppingWindowExpression) SessionWindowExpression(io.confluent.ksql.parser.tree.SessionWindowExpression) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) KsqlException(io.confluent.ksql.util.KsqlException) SessionWindowExpression(io.confluent.ksql.parser.tree.SessionWindowExpression) TumblingWindowExpression(io.confluent.ksql.parser.tree.TumblingWindowExpression)

Example 25 with KsqlException

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);
}
Also used : HashMap(java.util.HashMap) CreateTable(io.confluent.ksql.parser.tree.CreateTable) CreateStream(io.confluent.ksql.parser.tree.CreateStream) AbstractStreamCreateStatement(io.confluent.ksql.parser.tree.AbstractStreamCreateStatement) KsqlException(io.confluent.ksql.util.KsqlException) AvroUtil(io.confluent.ksql.util.AvroUtil) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) Expression(io.confluent.ksql.parser.tree.Expression) KsqlTopic(io.confluent.ksql.metastore.KsqlTopic) Pair(io.confluent.ksql.util.Pair)

Aggregations

KsqlException (io.confluent.ksql.util.KsqlException)42 HashMap (java.util.HashMap)9 StructuredDataSource (io.confluent.ksql.metastore.StructuredDataSource)6 Pair (io.confluent.ksql.util.Pair)6 KsqlTopic (io.confluent.ksql.metastore.KsqlTopic)5 Expression (io.confluent.ksql.parser.tree.Expression)5 Statement (io.confluent.ksql.parser.tree.Statement)5 ArrayList (java.util.ArrayList)5 CreateTable (io.confluent.ksql.parser.tree.CreateTable)4 StringLiteral (io.confluent.ksql.parser.tree.StringLiteral)4 SchemaKStream (io.confluent.ksql.structured.SchemaKStream)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 CreateStreamCommand (io.confluent.ksql.ddl.commands.CreateStreamCommand)3 RegisterTopicCommand (io.confluent.ksql.ddl.commands.RegisterTopicCommand)3 AbstractStreamCreateStatement (io.confluent.ksql.parser.tree.AbstractStreamCreateStatement)3 CreateStream (io.confluent.ksql.parser.tree.CreateStream)3 Query (io.confluent.ksql.parser.tree.Query)3 TableElement (io.confluent.ksql.parser.tree.TableElement)3 KsqlStructuredDataOutputNode (io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode)3