我有一个Kafka主题,其中包含客户,购买,产品等数据。我想从这个单一主题创建不同的流。
答案 0 :(得分:0)
让我假设您的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'
);