ksql连接两个以上的流

disbfnqx  于 2021-06-06  发布在  Kafka
关注(0)|答案(1)|浏览(429)

在ksql中是否可以连接两个以上的流/表?
例子:
我有三条溪流:

CREATE STREAM StreamA (id BIGINT, message VARCHAR) WITH 
(KAFKA_TOPIC='TopicA', VALUE_FORMAT='DELIMITED');
CREATE STREAM StreamB (id BIGINT, aid BIGINT, message VARCHAR) WITH . 
(KAFKA_TOPIC='TopicB', VALUE_FORMAT='DELIMITED');
CREATE STREAM StreamC (id BIGINT, bid BIGINT, message VARCHAR) WITH 
(KAFKA_TOPIC='TopicC', VALUE_FORMAT='DELIMITED');

我尝试通过连接这三个流来创建另一个流:

CREATE STREAM ABCStream AS SELECT * FROM StreamA a JOIN 
StreamB b ON b.aid = a.id JOIN StreamC c WITHIN 1 HOURS ON 
c.bid = b.id;

我得到以下例外:

mismatched input 'JOIN' expecting ';'  
Caused by: org.antlr.v4.runtime.InputMismatchException
vwhgwdsa

vwhgwdsa1#

不,在ksql版本5.0之前,每个查询只能连接两个。你需要把你的查询串起来,类似这样:
中间流:

CREATE STREAM ABStream AS \
   SELECT * \
     FROM StreamA a \
     JOIN StreamB b \
          ON b.aid = a.id;

多连接流

CREATE STREAM ABCStream AS \
   SELECT * \
     FROM ABStream AB \
     JOIN StreamC c \
          WITHIN 1 HOURS \
          ON c.bid = AB.b_id;

相关问题