Reputation: 33
Is it possible to join more than two streams/tables in KSQL?
Example:
I have three streams:
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');
I try to create another stream by joining those three streams:
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;
I get the following exception:
mismatched input 'JOIN' expecting ';'
Caused by: org.antlr.v4.runtime.InputMismatchException
Upvotes: 3
Views: 2765
Reputation: 32090
No, you can only join two per query in KSQL up to v5.0. You'd need to daisy-chain your queries, something like this:
Intermediate Stream:
CREATE STREAM ABStream AS \
SELECT * \
FROM StreamA a \
JOIN StreamB b \
ON b.aid = a.id;
Multi- join stream
CREATE STREAM ABCStream AS \
SELECT * \
FROM ABStream AB \
JOIN StreamC c \
WITHIN 1 HOURS \
ON c.bid = AB.b_id;
Upvotes: 5