Ksql:左连接显示流中的列但不显示表 [英] Ksql: Left Join Displays columns from stream but not tables

查看:21
本文介绍了Ksql:左连接显示流中的列但不显示表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 KSQL 中有一个 Steam 和一个表,如下所述:

I have one steam and a table in KSQL as mentioned below:

流名称:DEAL_STREAM

Stream name: DEAL_STREAM

表名:EXPENSE_TABLE

Table name: EXPENSE_TABLE

当我运行以下查询时,它只显示流中的列,但没有显示表列.

When I run the below queries it displays only columns from the stream but no table columns are being displays.

这是预期的输出吗?如果不是我做错了什么?

Is this the expected output. If not am I doing something wrong?

SELECT TD.EXPENSE_CODE, TD.BRANCH_CODE, TE.EXPENSE_DESC
FROM DEAL_STREAM TD
LEFT JOIN EXPENSE_TABLE TE ON TD.EXPENSE_CODE = TE.EXPENSE_CODE
WHERE TD.EXPENSE_CODE LIKE '%NL%' AND TD.BRANCH_CODE LIKE '%AM%';

查询的输出如下所示.

NL8232@#0          | AM   | null
NL0232@#0          | AM   | null
NL6232@!0          | AM   | null
NL5232^%0          | AM   | null

推荐答案

当我运行以下查询时,它只显示流中的列,但没有显示表列.

When I run the below queries it displays only columns from the stream but no table columns are being displays.

在流表(左)联接中,如果联接时表中没有匹配的记录,则输出记录将包含 null 列(对于表侧列)/查找.

In a stream-table (left) join, the output records will contain null columns (for table-side columns) if there is not matching record in the table at the time of the join/lookup.

这是预期的输出吗?如果不是我做错了什么?

Is this the expected output. If not am I doing something wrong?

是否有可能,例如,您在将 (2) 输入数据写入表之前将 (1) 输入数据写入流?如果是这样,那么流表连接查询将在 (1) 时刻尝试执行表查找,而此时表中尚无此类查找数据可用(因为发生在稍后的时刻 (2)).因为没有这样的表数据可用,连接写入了表侧列为 null 的输出记录.

Is it possible that, for example, you wrote the (1) input data into the stream before you wrote (2) the input data into the table? If so, then the stream-table join query would have attempted to perform table-lookups at the time of (1) when no such lookup data was available in the table yet (because that happened later at time (2)). Because there was no such table data available, the join wrote output records where the table-side columns were null.

注意:KSQL 中的这种流表连接(以及构建 KSQL 的 Apache Kafka 的 Streams API)几乎是流媒体世界中连接的标准.这里,只有流表连接的流端会触发下游连接输出,如果在连接新输入记录时表端没有匹配流记录,则表端列将为 null.然而,由于这是用户混淆的常见原因,我们目前正在努力将连接输出的表端触发添加到 Apache Kafka 的 Streams API 和 KSQL.当这样的功能可用时,您上面的问题就不会再发生了.

Note: This stream-table join in KSQL (and, by extension, Apache Kafka's Streams API, on which KSQL is built) is the pretty much the norm for joins in the streaming world. Here, only the stream-side of the stream-table join will trigger downstream join outputs, and if there's no matching for a stream record on the table-side at the time when a new input record is being joined, then the table-side columns will be null. Since this is, however, a common cause of user confusion, we are currently working on adding table-side triggering of join output to Apache Kafka's Streams API and KSQL. When such a feature is available, then your issue above would not happen anymore.

这篇关于Ksql:左连接显示流中的列但不显示表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆