在KSQL中创建表时如何设置键字段?

时间:2019-03-15 02:00:50

标签: apache-kafka ksql

我想问创建表格时可以设置键字段吗?

我通过汇总创建了一个表格,如下所示:

CREATE TABLE withdrawal_less_than_5min AS 
SELECT executedate, status, count(*) as count 
FROM TB3_WITHDRAW_RECORD_EXCLUDE_INTERNAL_USERS 
GROUP BY executedate,status;

当我DESCRIBE EXTENDED withdrawal_less_than_5min时,表的关键字段设置如下,我认为应该是执行和状态。

Key field : KSQL_INTERNAL_COL_0|+|KSQL_INTERNAL_COL_1

但是,当我尝试将其与具有相同聚合的另一个表联接时,会返回此错误。

Source table (A) key column (KSQL_INTERNAL_COL_0|+|KSQL_INTERNAL_COL_1) 
is not the column used in the join criteria (EXECUTEDATE).

如何设置键字段?谢谢。

1 个答案:

答案 0 :(得分:0)

您可以通过以下方式创建密钥-

CREATE TABLE withdrawal_less_than_5min with (key='EXECUTEDATE') AS 
SELECT executedate, status, count(*) as count 
FROM TB3_WITHDRAW_RECORD_EXCLUDE_INTERNAL_USERS 
GROUP BY executedate,status partition by 'EXECUTEDATE';

您也可以关注Robin的博客-https://www.confluent.io/stream-processing-cookbook/ksql-recipes/inspecting-changing-topic-keys

对于Ksql的任何错误或问题,搜索Robin Moffet,他已经回答了我们的问题以提供帮助:)