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.");
}
}
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);
}
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;
}
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");
}
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);
}
Aggregations