Search in sources :

Example 16 with KsqlException

use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.

the class PhysicalPlanBuilder method buildPhysicalPlan.

public QueryMetadata buildPhysicalPlan(final Pair<String, PlanNode> statementPlanPair) throws Exception {
    final SchemaKStream resultStream = statementPlanPair.getRight().buildStream(builder, ksqlConfig, kafkaTopicClient, functionRegistry, overriddenStreamsProperties, schemaRegistryClient);
    final OutputNode outputNode = resultStream.outputNode();
    boolean isBareQuery = outputNode instanceof KsqlBareOutputNode;
    // the corresponding Kafka Streams job
    if (isBareQuery && !(resultStream instanceof QueuedSchemaKStream)) {
        throw new Exception(String.format("Mismatch between logical and physical output; " + "expected a QueuedSchemaKStream based on logical " + "KsqlBareOutputNode, found a %s instead", resultStream.getClass().getCanonicalName()));
    }
    String serviceId = getServiceId();
    String persistanceQueryPrefix = ksqlConfig.get(KsqlConfig.KSQL_PERSISTENT_QUERY_NAME_PREFIX_CONFIG).toString();
    String transientQueryPrefix = ksqlConfig.get(KsqlConfig.KSQL_TRANSIENT_QUERY_NAME_PREFIX_CONFIG).toString();
    if (isBareQuery) {
        return buildPlanForBareQuery((QueuedSchemaKStream) resultStream, (KsqlBareOutputNode) outputNode, serviceId, transientQueryPrefix, statementPlanPair.getLeft());
    } else if (outputNode instanceof KsqlStructuredDataOutputNode) {
        return buildPlanForStructuredOutputNode(statementPlanPair.getLeft(), resultStream, (KsqlStructuredDataOutputNode) outputNode, serviceId, persistanceQueryPrefix, statementPlanPair.getLeft());
    } else {
        throw new KsqlException("Sink data source of type: " + outputNode.getClass() + " is not supported.");
    }
}
Also used : KsqlBareOutputNode(io.confluent.ksql.planner.plan.KsqlBareOutputNode) KsqlStructuredDataOutputNode(io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode) OutputNode(io.confluent.ksql.planner.plan.OutputNode) KsqlBareOutputNode(io.confluent.ksql.planner.plan.KsqlBareOutputNode) SchemaKStream(io.confluent.ksql.structured.SchemaKStream) QueuedSchemaKStream(io.confluent.ksql.structured.QueuedSchemaKStream) KsqlStructuredDataOutputNode(io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode) QueuedSchemaKStream(io.confluent.ksql.structured.QueuedSchemaKStream) KsqlException(io.confluent.ksql.util.KsqlException) KsqlException(io.confluent.ksql.util.KsqlException)

Example 17 with KsqlException

use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.

the class PhysicalPlanBuilder method updateListProperty.

private void updateListProperty(Map<String, Object> properties, String key, Object value) {
    Object obj = properties.getOrDefault(key, new LinkedList<String>());
    List valueList;
    // names
    if (obj instanceof String) {
        // If its a string just split it on the separator so we dont have to worry about adding a
        // separator
        String asString = (String) obj;
        valueList = new LinkedList<>(Arrays.asList(asString.split("\\s*,\\s*")));
    } else if (obj instanceof List) {
        valueList = (List) obj;
    } else {
        throw new KsqlException("Expecting list or string for property: " + key);
    }
    valueList.add(value);
    properties.put(key, valueList);
}
Also used : LinkedList(java.util.LinkedList) List(java.util.List) KsqlException(io.confluent.ksql.util.KsqlException)

Example 18 with KsqlException

use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.

the class ArrayContainsKudf method jsonStringArrayContains.

private boolean jsonStringArrayContains(Object searchValue, String jsonArray) {
    JsonToken valueType = getType(searchValue);
    try (JsonParser parser = JSON_FACTORY.createParser(jsonArray)) {
        if (parser.nextToken() != START_ARRAY) {
            return false;
        }
        while (parser.currentToken() != null) {
            JsonToken token = parser.nextToken();
            if (token == null) {
                return searchValue == null;
            }
            if (token == END_ARRAY) {
                return false;
            }
            parser.skipChildren();
            if (valueType == token) {
                final Matcher matcher = matchers.get(valueType);
                if (matcher != null && matcher.matches(parser, searchValue)) {
                    return true;
                }
            }
        }
    } catch (IOException e) {
        throw new KsqlException("Invalid JSON format: " + jsonArray, e);
    }
    return false;
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) KsqlException(io.confluent.ksql.util.KsqlException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 19 with KsqlException

use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.

the class RegisterTopicCommand method run.

@Override
public DdlCommandResult run(MetaStore metaStore) {
    if (metaStore.getTopic(topicName) != null) {
        // Check IF NOT EXIST is set, if set, do not create topic if one exists.
        if (notExists) {
            return new DdlCommandResult(true, "Topic is not registered because it already registered" + ".");
        } else {
            throw new KsqlException("Topic already registered.");
        }
    }
    KsqlTopic ksqlTopic = new KsqlTopic(topicName, kafkaTopicName, topicSerDe);
    // TODO: Need to check if the topic exists.
    // Add the topic to the metastore
    metaStore.putTopic(ksqlTopic);
    return new DdlCommandResult(true, "Topic registered");
}
Also used : KsqlException(io.confluent.ksql.util.KsqlException) KsqlTopic(io.confluent.ksql.metastore.KsqlTopic)

Example 20 with KsqlException

use of io.confluent.ksql.util.KsqlException in project ksql by confluentinc.

the class KsqlResource method getStatementExecutionPlan.

private SourceDescription getStatementExecutionPlan(String queryId, Statement statement, String statementText, Map<String, Object> properties) throws KsqlException {
    if (queryId != null) {
        PersistentQueryMetadata metadata = ksqlEngine.getPersistentQueries().get(new QueryId(queryId));
        if (metadata == null) {
            throw new KsqlException(("Query with id:" + queryId + " does not exist, use SHOW QUERIES to view the full set of " + "queries."));
        }
        KsqlStructuredDataOutputNode outputNode = (KsqlStructuredDataOutputNode) metadata.getOutputNode();
        return new SourceDescription(outputNode, metadata.getStatementString(), metadata.getStatementString(), metadata.getTopologyDescription(), metadata.getExecutionPlan(), ksqlEngine.getTopicClient());
    }
    DdlCommandTask ddlCommandTask = ddlCommandTasks.get(statement.getClass());
    if (ddlCommandTask != null) {
        try {
            String executionPlan = ddlCommandTask.execute(statement, statementText, properties);
            return new SourceDescription("", "User-Evaluation", Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, "QUERY", "", "", "", "", true, "", "", "", executionPlan, 0, 0);
        } catch (KsqlException ksqlException) {
            throw ksqlException;
        } catch (Throwable t) {
            throw new KsqlException("Cannot RUN execution plan for this statement, " + statement, t);
        }
    }
    throw new KsqlException("Cannot FIND execution plan for this statement:" + statement);
}
Also used : QueryId(io.confluent.ksql.query.QueryId) KsqlStructuredDataOutputNode(io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode) KsqlException(io.confluent.ksql.util.KsqlException) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription)

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