简体   繁体   English

KSQL:(拉)-查询连接表

[英]KSQL: (pull)-query on a joined table

I have two topics that I'd like to join and then query the join for the latest results.我有两个主题想要加入,然后查询加入以获取最新结果。 I have followed the docs on Create a ksqlDB Table from a ksqlDB Stream from here .我遵循了从这里Create a ksqlDB Table from a ksqlDB Stream的文档。

This is what I do:这就是我所做的:

CREATE TABLE CATALOGUE_TABLE
  (title STRING)
  WITH (KAFKA_TOPIC='catalogue-topic-test',
        VALUE_FORMAT='AVRO');
CREATE TABLE SCHEDULE_TABLE
  (fromInstant STRING,
   toInstant STRING)
  WITH (KAFKA_TOPIC='schedule-topic-test',
        VALUE_FORMAT='AVRO');

rest assured that the two underlying topics both have keys for all their entries.请放心,这两个基础主题都有其所有条目的键。 I then join them like this:然后我像这样加入他们:

CREATE TABLE MYTABLE AS
  SELECT c.title, s.fromInstant, s.toInstant
  FROM CATALOGUE_TABLE c
  INNER JOIN SCHEDULE_TABLE s
  ON s.ROWKEY = c.ROWKEY
  EMIT CHANGES;

I am not sure what I end up with it.我不确定我最终会得到什么。 whatever it is, I can run the following on:无论是什么,我都可以运行以下命令:

select * from MYTABLE EMIT CHANGES;

and I can see all the updates on it, with all the duplicates.我可以看到它的所有更新,以及所有重复项。 it's bascially a stream.它基本上是一个流。 Now if I run the following:现在,如果我运行以下命令:

select * from MYTABLE WHERE ROWKEY='12';

to get the last update with id=12, I get:要获得 id=12 的最后一次更新,我得到:

Table 'MYTABLE' is not materialized.表 'MYTABLE' 未具体化。 Refer to https://cnfl.io/queries for info on query types.有关查询类型的信息,请参阅https://cnfl.io/queries If you...如果你...

and the rest of the output is truncated so I can't see what it's trying to say.其余的输出被截断,所以我看不到它想说什么。 My guess is that I am somehow doing something wrong in MYTABLE.我的猜测是我在 MYTABLE 中以某种方式做错了。

I think I am missing a groupBy which would should be the piece responsible for getting rid of all the entries with repeated ids, but I can't figure out what I need to put there and whether I should do so at the MYTABLE level only, or if it should be done on all three tables.我想我错过了一个 groupBy,它应该是负责删除所有具有重复 ID 的条目的部分,但我不知道我需要在那里放什么以及我是否应该只在 MYTABLE 级别这样做,或者是否应该在所有三个表上完成。

Currently, ie, ksqlDB 0.6.0, only stream aggregation queries that return a table allow to query the result table.目前,即 ksqlDB 0.6.0,只有返回表的流聚合查询允许查询结果表。

For a table-table join, the result is not materialized into a local store, but only a changelog stream is produced and written to the result topic that corresponds to the result table.对于表-表连接,结果不会具体化到本地存储中,而只会生成更改日志流并将其写入与结果表对应的结果主题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM