简体   繁体   中英

How to output all rows of KTable to Kafka Topic using KSQL

I am new to Ksql and trying aggregation, have created a Kstream & a Ktable which looks like this

kstream...

 CREATE STREAM test
  (id BIGINT,
   type VARCHAR,
   sales BIGINT
  WITH (KAFKA_TOPIC='test1',
        VALUE_FORMAT='JSON');

ktable...

CREATE TABLE test_total AS
SELECT ID,
       SUM(SALES) AS TOTAL_SALES
FROM test
GROUP BY ID
EMIT CHANGES;

Published these values into Kafka test1 topic

{"id": 1, "type": "test","sales": 200}
{"id": 1, "type": "test","sales": 300}

When I use the Kafka console consumer I only see the output as

{"TOTAL_SALES":200} {"TOTAL_SALES":500}

How can I see the id also printed into the Kafka topic? Do I have to create some kind of view out of the table?

In your console-consumer command add

--property print.key=true

If you already using ksql, you can also SELECT from your created TABLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM