-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce primary keys for lookup joins
- Loading branch information
Showing
9 changed files
with
103 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
crates/arroyo-planner/src/test/queries/error_lookup_join_non_primary_key.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--fail=the right-side of a look-up join condition must be a PRIMARY KEY column, but 'value' is not | ||
create table impulse with ( | ||
connector = 'impulse', | ||
event_rate = '2' | ||
); | ||
|
||
create temporary table lookup ( | ||
key TEXT PRIMARY KEY GENERATED ALWAYS AS (metadata('key')) STORED, | ||
value TEXT, | ||
len INT | ||
) with ( | ||
connector = 'redis', | ||
format = 'raw_string', | ||
address = 'redis://localhost:6379', | ||
format = 'json', | ||
'lookup.cache.max_bytes' = '100000' | ||
); | ||
|
||
select A.counter, B.key, B.value, len | ||
from impulse A inner join lookup B | ||
on cast((A.counter % 10) as TEXT) = B.value; |
19 changes: 19 additions & 0 deletions
19
crates/arroyo-planner/src/test/queries/error_missing_redis_key.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--fail=Redis lookup tables must have a PRIMARY KEY field defined as `field_name TEXT GENERATED ALWAYS AS (metadata('key')) STORED` | ||
create table impulse with ( | ||
connector = 'impulse', | ||
event_rate = '2' | ||
); | ||
|
||
create table lookup ( | ||
key TEXT PRIMARY KEY, | ||
value TEXT | ||
) with ( | ||
connector = 'redis', | ||
format = 'json', | ||
address = 'redis://localhost:6379', | ||
type = 'lookup' | ||
); | ||
|
||
select A.counter, B.key, B.value | ||
from impulse A left join lookup B | ||
on cast((A.counter % 10) as TEXT) = B.key; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,31 @@ | ||
CREATE TABLE orders ( | ||
order_id INT, | ||
user_id INT, | ||
product_id INT, | ||
quantity INT, | ||
order_timestamp TIMESTAMP | ||
) with ( | ||
CREATE TABLE events ( | ||
event_id TEXT, | ||
timestamp TIMESTAMP, | ||
customer_id TEXT, | ||
event_type TEXT | ||
) WITH ( | ||
connector = 'kafka', | ||
bootstrap_servers = 'localhost:9092', | ||
topic = 'events', | ||
type = 'source', | ||
topic = 'orders', | ||
format = 'json' | ||
format = 'json', | ||
bootstrap_servers = 'broker:9092' | ||
); | ||
|
||
CREATE TEMPORARY TABLE products ( | ||
key TEXT PRIMARY KEY, | ||
product_name TEXT, | ||
unit_price FLOAT, | ||
category TEXT, | ||
last_updated TIMESTAMP | ||
create temporary table customers ( | ||
customer_id TEXT PRIMARY KEY GENERATED ALWAYS AS (metadata('key')) STORED, | ||
customer_name TEXT, | ||
plan TEXT | ||
) with ( | ||
connector = 'redis', | ||
format = 'raw_string', | ||
address = 'redis://localhost:6379', | ||
format = 'json', | ||
type = 'lookup', | ||
address = 'redis://localhost:6379' | ||
'lookup.cache.max_bytes' = '1000000', | ||
'lookup.cache.ttl' = '5 second' | ||
); | ||
|
||
SELECT | ||
o.order_id, | ||
o.user_id, | ||
o.quantity, | ||
o.order_timestamp, | ||
p.product_name, | ||
p.unit_price, | ||
p.category, | ||
(o.quantity * p.unit_price) as total_amount | ||
FROM orders o | ||
JOIN products p | ||
ON concat('blah', o.product_id) = p.key; | ||
SELECT e.event_id, e.timestamp, e.customer_id, e.event_type, c.customer_name, c.plan | ||
FROM events e | ||
LEFT JOIN customers c | ||
ON e.customer_id = c.customer_id | ||
WHERE c.plan = 'Premium'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters