如何从ksql中的一个主题创建不同的表?

93ze6v8z  于 2021-06-06  发布在  Kafka
关注(0)|答案(1)|浏览(691)

我有一个Kafka主题,其中有客户,购买,产品等数据。我想从这个主题创建不同的流。

brgchamk

brgchamk1#

让我假设您的Kafka主题的消息(json格式)如下:

{
    "customer_id":value,
    "customer_name":value,
    "purchase_id":value,
    "purchase_desc":value,
    "product_id":value,
    "product_name":value
}

假设主题名为 my_topic .
所以你可以这样做:
为了 customer 流:

CREATE STREAM customer (
    -- which 'customer_id' match the JSON key
    customer_id BIGINT,
    customer_name VARCHAR
) WITH (
    VALUE_FORMAT = 'JSON',
    KAFKA_TOPIC = 'my_topic'
);

为了 purchase 表格:

CREATE STREAM purchase (
    purchase_id BIGINT,
    purchase_desc VARCHAR
) WITH (
    VALUE_FORMAT = 'JSON',
    KAFKA_TOPIC = 'my_topic'
);

为了 product 表格:

CREATE STREAM product (
    product_id BIGINT,
    product_name VARCHAR
) WITH (
    VALUE_FORMAT = 'JSON',
    KAFKA_TOPIC = 'my_topic'
);

相关问题