Skip to content
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

ClassCastException when dropping a STREAM with 2+ INSERT INTO statements #8129

Closed
mikebin opened this issue Sep 14, 2021 · 0 comments · Fixed by #8205
Closed

ClassCastException when dropping a STREAM with 2+ INSERT INTO statements #8129

mikebin opened this issue Sep 14, 2021 · 0 comments · Fixed by #8205
Assignees
Labels
bug fix-it-week P0 Denotes must-have for a given milestone streaming-engine Tickets owned by the ksqlDB Streaming Team
Milestone

Comments

@mikebin
Copy link

mikebin commented Sep 14, 2021

Describe the bug
The following exception occurs when attempting to drop a STREAM which is associated with 2+ INSERT INTO statements:

class io.confluent.ksql.query.QueryId cannot be cast to class java.lang.Comparable (io.confluent.ksql.query.QueryId is in unnamed module of loader 'app'; java.lang.Comparable is in module java.base of loader 'bootstrap')

To Reproduce
ksqlDB 0.20.0

(Contrived example to illustrate the bug)

create stream s (val string) with (kafka_topic='s', value_format='json', partitions=1);
insert into s select * from s;
insert into s select * from s;

drop stream s delete topic;

Expected behavior
User-friendly error message explaining why stream S cannot be dropped, such as:

Cannot drop S.
The following queries read from this source: [INSERTQUERY_2, INSERTQUERY_3].
The following queries write into this source: [INSERTQUERY_2, INSERTQUERY_3].
You need to terminate them before dropping S.

Actual behaviour
The following error is returned to the user in the CLI:

class io.confluent.ksql.query.QueryId cannot be cast to class java.lang.Comparable (io.confluent.ksql.query.QueryId is in unnamed module of loader 'app'; java.lang.Comparable is in module java.base of loader 'bootstrap')

ksqlDB Server log:

ksqldb-server       | io.confluent.ksql.util.KsqlStatementException: class io.confluent.ksql.query.QueryId cannot be cast to class
 java.lang.Comparable (io.confluent.ksql.query.QueryId is in unnamed module of loader 'app'; java.lang.Comparable is in module jav
a.base of loader 'bootstrap')
ksqldb-server       | Statement: DROP STREAM S;
ksqldb-server       |   at io.confluent.ksql.engine.EngineExecutor.executeDdl(EngineExecutor.java:610)
ksqldb-server       |   at io.confluent.ksql.engine.EngineExecutor.lambda$execute$0(EngineExecutor.java:138)
ksqldb-server       |   at java.base/java.util.Optional.map(Optional.java:265)
ksqldb-server       |   at io.confluent.ksql.engine.EngineExecutor.execute(EngineExecutor.java:138)
ksqldb-server       |   at io.confluent.ksql.engine.SandboxedExecutionContext.execute(SandboxedExecutionContext.java:139)
ksqldb-server       |   at io.confluent.ksql.rest.server.computation.ValidatedCommandFactory.createForPlannedQuery(ValidatedComman
dFactory.java:139)
ksqldb-server       |   at io.confluent.ksql.rest.server.computation.ValidatedCommandFactory.createCommand(ValidatedCommandFactory
.java:106)
ksqldb-server       |   at io.confluent.ksql.rest.server.computation.ValidatedCommandFactory.create(ValidatedCommandFactory.java:6
6)
ksqldb-server       |   at io.confluent.ksql.rest.server.validation.RequestValidator.validate(RequestValidator.java:164)
ksqldb-server       |   at io.confluent.ksql.rest.server.validation.RequestValidator.validate(RequestValidator.java:130)
ksqldb-server       |   at io.confluent.ksql.rest.server.resources.KsqlResource.handleKsqlStatements(KsqlResource.java:281)
ksqldb-server       |   at io.confluent.ksql.rest.server.KsqlServerEndpoints.lambda$executeKsqlRequest$2(KsqlServerEndpoints.java:
202)
ksqldb-server       |   at io.confluent.ksql.rest.server.KsqlServerEndpoints.lambda$executeOldApiEndpointOnWorker$23(KsqlServerEnd
points.java:356)
ksqldb-server       |   at io.confluent.ksql.rest.server.KsqlServerEndpoints.lambda$executeOnWorker$22(KsqlServerEndpoints.java:34
2)
ksqldb-server       |   at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:313)
ksqldb-server       |   at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
ksqldb-server       |   at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
ksqldb-server       |   at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
ksqldb-server       |   at java.base/java.lang.Thread.run(Thread.java:829)
ksqldb-server       | Caused by: java.lang.ClassCastException: class io.confluent.ksql.query.QueryId cannot be cast to class java.
lang.Comparable (io.confluent.ksql.query.QueryId is in unnamed module of loader 'app'; java.lang.Comparable is in module java.base
 of loader 'bootstrap')
ksqldb-server       |   at java.base/java.util.Comparators$NaturalOrderComparator.compare(Comparators.java:47)
ksqldb-server       |   at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
ksqldb-server       |   at java.base/java.util.TimSort.sort(TimSort.java:220)
ksqldb-server       |   at java.base/java.util.Arrays.sort(Arrays.java:1515)
ksqldb-server       |   at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:353)
ksqldb-server       |   at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
ksqldb-server       |   at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
ksqldb-server       |   at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
ksqldb-server       |   at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
ksqldb-server       |   at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
ksqldb-server       |   at io.confluent.ksql.engine.EngineContext.throwIfInsertQueriesExist(EngineContext.java:261)
ksqldb-server       |   at io.confluent.ksql.engine.EngineContext.executeDdl(EngineContext.java:223)
ksqldb-server       |   at io.confluent.ksql.engine.EngineExecutor.executeDdl(EngineExecutor.java:606)
ksqldb-server       |   ... 18 more

Additional context
This code attempts to sort a set of QueryId, but QueryId is not a Comparable: https://github.com/confluentinc/ksql/blob/0.20.0-ksqldb/ksqldb-engine/src/main/java/io/confluent/ksql/engine/EngineContext.java#L259. Note: sorted is a no-op if there's only one QueryId in the set, so this bug only occurs if there are 2+ INSERT INTO statements read from/writing to the stream.

@agavra agavra added the streaming-engine Tickets owned by the ksqlDB Streaming Team label Sep 17, 2021
@vcrfxia vcrfxia added fix-it-week P0 Denotes must-have for a given milestone and removed needs-triage labels Sep 21, 2021
@vcrfxia vcrfxia added this to the 0.23 milestone Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix-it-week P0 Denotes must-have for a given milestone streaming-engine Tickets owned by the ksqlDB Streaming Team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants