@@ -15,6 +15,19 @@ Flink lookup joins are important because they enable efficient, real-time enrich
1515
1616### Examples
17171 . Create two tables.
18+
19+ ``` sql title="Flink SQL"
20+ USE CATALOG fluss_catalog;
21+ ```
22+
23+ ``` sql title="Flink SQL"
24+ CREATE DATABASE my_db ;
25+ ```
26+
27+ ``` sql title="Flink SQL"
28+ USE my_db;
29+ ```
30+
1831``` sql title="Flink SQL"
1932CREATE TABLE `fluss_catalog `.` my_db` .` orders` (
2033 ` o_orderkey` INT NOT NULL ,
@@ -46,13 +59,6 @@ CREATE TABLE `fluss_catalog`.`my_db`.`customer` (
4659```
4760
48612 . Perform lookup join.
49- ``` sql title="Flink SQL"
50- USE CATALOG fluss_catalog;
51- ```
52-
53- ``` sql title="Flink SQL"
54- USE my_db;
55- ```
5662
5763``` sql title="Flink SQL"
5864CREATE TEMPORARY TABLE lookup_join_sink
@@ -135,8 +141,21 @@ For more details about Fluss partitioned table, see [Partitioned Tables](table-d
135141
136142### Examples
1371431 . Create two tables.
144+
138145``` sql title="Flink SQL"
139- CREATE TABLE `fluss_catalog `.` my_db` .` orders` (
146+ USE CATALOG fluss_catalog;
147+ ```
148+
149+ ``` sql title="Flink SQL"
150+ CREATE DATABASE my_db ;
151+ ```
152+
153+ ``` sql title="Flink SQL"
154+ USE my_db;
155+ ```
156+
157+ ``` sql title="Flink SQL"
158+ CREATE TABLE `fluss_catalog `.` my_db` .` orders_with_dt` (
140159 ` o_orderkey` INT NOT NULL ,
141160 ` o_custkey` INT NOT NULL ,
142161 ` o_orderstatus` CHAR (1 ) NOT NULL ,
@@ -154,7 +173,7 @@ CREATE TABLE `fluss_catalog`.`my_db`.`orders` (
154173``` sql title="Flink SQL"
155174-- primary keys are (c_custkey, c_nationkey)
156175-- bucket key is (c_custkey)
157- CREATE TABLE `fluss_catalog `.` my_db` .` customer ` (
176+ CREATE TABLE `fluss_catalog `.` my_db` .` customer_with_bucket_key ` (
158177 ` c_custkey` INT NOT NULL ,
159178 ` c_name` STRING NOT NULL ,
160179 ` c_address` STRING NOT NULL ,
@@ -170,16 +189,9 @@ CREATE TABLE `fluss_catalog`.`my_db`.`customer` (
170189```
171190
1721912 . Perform prefix lookup.
173- ``` sql title="Flink SQL"
174- USE CATALOG fluss_catalog;
175- ```
176192
177193``` sql title="Flink SQL"
178- USE my_db;
179- ```
180-
181- ``` sql title="Flink SQL"
182- CREATE TEMPORARY TABLE lookup_join_sink
194+ CREATE TEMPORARY TABLE prefix_lookup_join_sink
183195(
184196 order_key INT NOT NULL ,
185197 order_totalprice DECIMAL (15 , 2 ) NOT NULL ,
@@ -190,11 +202,11 @@ CREATE TEMPORARY TABLE lookup_join_sink
190202
191203``` sql title="Flink SQL"
192204-- prefix look up join in asynchronous mode.
193- INSERT INTO lookup_join_sink
205+ INSERT INTO prefix_lookup_join_sink
194206SELECT ` o` .` o_orderkey` , ` o` .` o_totalprice` , ` c` .` c_name` , ` c` .` c_address`
195207FROM
196- (SELECT ` orders ` .* , proctime() AS ptime FROM ` orders ` ) AS ` o`
197- LEFT JOIN ` customer `
208+ (SELECT ` orders_with_dt ` .* , proctime() AS ptime FROM ` orders_with_dt ` ) AS ` o`
209+ LEFT JOIN ` customer_with_bucket_key `
198210FOR SYSTEM_TIME AS OF ` o` .` ptime` AS ` c`
199211ON ` o` .` o_custkey` = ` c` .` c_custkey` ;
200212
@@ -203,11 +215,11 @@ ON `o`.`o_custkey` = `c`.`c_custkey`;
203215
204216``` sql title="Flink SQL"
205217-- prefix look up join in synchronous mode.
206- INSERT INTO lookup_join_sink
218+ INSERT INTO prefix_lookup_join_sink
207219SELECT ` o` .` o_orderkey` , ` o` .` o_totalprice` , ` c` .` c_name` , ` c` .` c_address`
208220FROM
209- (SELECT ` orders ` .* , proctime() AS ptime FROM ` orders ` ) AS ` o`
210- LEFT JOIN ` customer ` /* + OPTIONS('lookup.async' = 'false') */
221+ (SELECT ` orders_with_dt ` .* , proctime() AS ptime FROM ` orders_with_dt ` ) AS ` o`
222+ LEFT JOIN ` customer_with_bucket_key ` /* + OPTIONS('lookup.async' = 'false') */
211223FOR SYSTEM_TIME AS OF ` o` .` ptime` AS ` c`
212224ON ` o` .` o_custkey` = ` c` .` c_custkey` ;
213225```
@@ -219,7 +231,7 @@ Continuing from the previous prefix lookup example, if our dimension table is a
219231``` sql title="Flink SQL"
220232-- primary keys are (c_custkey, c_nationkey, dt)
221233-- bucket key is (c_custkey)
222- CREATE TABLE `fluss_catalog `.` my_db` .` customer_partitioned ` (
234+ CREATE TABLE `fluss_catalog `.` my_db` .` customer_partitioned_with_bukcet_key ` (
223235 ` c_custkey` INT NOT NULL ,
224236 ` c_name` STRING NOT NULL ,
225237 ` c_address` STRING NOT NULL ,
@@ -242,11 +254,11 @@ WITH (
242254To do a prefix lookup with the Fluss partitioned primary key table, the prefix lookup join key is in pattern of
243255` a prefix subset of primary keys (excluding partition key) ` + ` partition key ` .
244256``` sql title="Flink SQL"
245- INSERT INTO lookup_join_sink
257+ INSERT INTO prefix_lookup_join_sink
246258SELECT ` o` .` o_orderkey` , ` o` .` o_totalprice` , ` c` .` c_name` , ` c` .` c_address`
247259FROM
248- (SELECT ` orders ` .* , proctime() AS ptime FROM ` orders ` ) AS ` o`
249- LEFT JOIN ` customer_partitioned `
260+ (SELECT ` orders_with_dt ` .* , proctime() AS ptime FROM ` orders_with_dt ` ) AS ` o`
261+ LEFT JOIN ` customer_partitioned_with_bukcet_key `
250262FOR SYSTEM_TIME AS OF ` o` .` ptime` AS ` c`
251263ON ` o` .` o_custkey` = ` c` .` c_custkey` AND ` o` .` o_dt` = ` c` .` dt` ;
252264
0 commit comments