-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: CREATE IF NOT EXISTS does not work at all #6073
Changes from all commits
2965dcd
b01aebc
a21ee7f
b861426
6bc0a99
7dfd7f5
ff9c504
9fe2c4a
8a84700
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient; | ||
import io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException; | ||
import io.confluent.ksql.KsqlExecutionContext; | ||
import io.confluent.ksql.KsqlExecutionContext.ExecuteResult; | ||
import io.confluent.ksql.execution.ddl.commands.CreateSourceCommand; | ||
import io.confluent.ksql.parser.properties.with.SourcePropertiesUtil; | ||
import io.confluent.ksql.parser.tree.CreateAsSelect; | ||
import io.confluent.ksql.parser.tree.CreateSource; | ||
|
@@ -43,7 +43,6 @@ | |
import io.confluent.ksql.util.KsqlConfig; | ||
import io.confluent.ksql.util.KsqlSchemaRegistryNotConfiguredException; | ||
import io.confluent.ksql.util.KsqlStatementException; | ||
import io.confluent.ksql.util.PersistentQueryMetadata; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
@@ -111,26 +110,28 @@ private void registerForCreateSource(final ConfiguredStatement<? extends CreateS | |
} | ||
|
||
private void registerForCreateAs(final ConfiguredStatement<? extends CreateAsSelect> cas) { | ||
final ServiceContext sandboxServiceContext = SandboxedServiceContext.create(serviceContext); | ||
final ExecuteResult executeResult = executionContext | ||
.createSandbox(sandboxServiceContext) | ||
.execute(sandboxServiceContext, cas); | ||
|
||
final PersistentQueryMetadata queryMetadata = (PersistentQueryMetadata) executeResult | ||
.getQuery() | ||
.orElseThrow(() -> new KsqlStatementException( | ||
"Could not determine output schema for query due to error: " | ||
+ executeResult.getCommandResult(), | ||
cas.getStatementText() | ||
)); | ||
final CreateSourceCommand createSourceCommand; | ||
|
||
try { | ||
final ServiceContext sandboxServiceContext = SandboxedServiceContext.create(serviceContext); | ||
createSourceCommand = (CreateSourceCommand) | ||
executionContext.createSandbox(sandboxServiceContext) | ||
.plan(sandboxServiceContext, cas) | ||
.getDdlCommand() | ||
.get(); | ||
} catch (final Exception e) { | ||
throw new KsqlStatementException( | ||
"Could not determine output schema for query due to error: " | ||
+ e.getMessage(), cas.getStatementText(), e); | ||
} | ||
|
||
registerSchemas( | ||
queryMetadata.getLogicalSchema(), | ||
queryMetadata.getResultTopic().getKafkaTopicName(), | ||
queryMetadata.getResultTopic().getKeyFormat().getFormatInfo(), | ||
queryMetadata.getPhysicalSchema().keySchema().features(), | ||
queryMetadata.getResultTopic().getValueFormat().getFormatInfo(), | ||
queryMetadata.getPhysicalSchema().valueSchema().features(), | ||
createSourceCommand.getSchema(), | ||
createSourceCommand.getTopicName(), | ||
createSourceCommand.getFormats().getKeyFormat(), | ||
createSourceCommand.getFormats().getKeyFeatures(), | ||
createSourceCommand.getFormats().getValueFormat(), | ||
createSourceCommand.getFormats().getValueFeatures(), | ||
Comment on lines
+129
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to build the query information from the plan instead of executing it. This avoids failing with an error if the |
||
cas.getSessionConfig().getConfig(false), | ||
cas.getStatementText(), | ||
true | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@big-andy-coates @spena
I noticed that
CreateStreamCommand
did not have the boolean flag for ifNotExists set here , I thought if this approach is ok , I will add that too and fail the query if its not set and source existsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The place to put the check is in the
CreateSourceFactory
. You'll need to pass theMetaStore
in to the factory's constructor.See
DropSourceFactory
for an example of the pattern.