KSQL - drop topic

2019-08-04 02:05发布

问题:

Is there a way to drop the topic from KSQL? According to github it is possible, and I tried

DROP TOPIC my-topic
DROP TOPIC "my-topic"
DROP TOPIC 'my-topic'
DROP TOPIC `my-topic`

But neither of this commands works. I get message

 Message
-------------------------------------------------------------------------------
 io.confluent.ksql.util.KsqlException: No topic with name true was registered.

回答1:

KSQL topic is different concept than Kafka topic. KSQL topic is an internal concept for KSQL that represents a kafka topic along with metadata about that topic including the topic format. Since we do not expose KSQL topic externally you should not use it in KSQL statements. If you wanna delete a kafka topic, you should delete it from kafka. In future we plan to add topic management capability to KSQL.



回答2:

When you create stream or table using a TOPIC then the topic gets registered in KSQL As shown below.

ksql> SHOW TOPICS;

Kafka Topic| Registered| Partitions | Partition Replicas | Consumers | Consumer Groups` 

---------------------------------------------------------------------------------------

 __confluent.support.metric| false      | 1          | 1                  | 0         | 0

_confluent-ksql-default__command_topic | true       | 1          | 1                  | 0         | 0

_schemas                               | false      | 1          | 1                  | 0         | 0

connect-configs                        | false      | 1          | 1                  | 0         | 0

connect-offsets                        | false      | 25         | 1                  | 0         | 0

connect-statuses                       | false      | 5          | 1                  | 0         | 0

email-filters                          | false      | 4          | 1                  | 0         | 0

Please observe the email-filters topics is saying Registered is false because there is no corresponding stream and table.

So when you try to drop it. like this :

ksql> DROP TOPIC "email-filters";

 Message
-----------------------------------------
 No topic with name true was registered.
-----------------------------------------
ksql>

So the answer is correct by @Hojjat is correct.

This is the explanation.