Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking: ASOF JOIN #17765

Open
2 of 4 tasks
lmatz opened this issue Jul 22, 2024 · 2 comments
Open
2 of 4 tasks

Tracking: ASOF JOIN #17765

lmatz opened this issue Jul 22, 2024 · 2 comments
Assignees
Labels
Milestone

Comments

@lmatz
Copy link
Contributor

lmatz commented Jul 22, 2024

Background

We have a few users whose workload has the need to do the following:

For each row in the first (or left) table, the join finds a single row in the second (or right) table that has the closest timestamp value.

The qualifying row on the right side is the closest match, which could be equal in time, earlier in time, or later in time, depending on the specified comparison operator.

This is exactly the semantics of ASOF JOIN.

It has been supported by a few popular DBs such as snowflake, duckdb, questdb, clickhouse, kdb.

https://duckdb.org/2023/09/15/asof-joins-fuzzy-temporal-lookups

Tracking

@github-actions github-actions bot added this to the release-1.11 milestone Jul 22, 2024
@lmatz
Copy link
Contributor Author

lmatz commented Jul 22, 2024

Repost @st1page's dubkdb examples on Slack:

# ok
select * from t1 asof join t2 on t1.ts < t2.ts and t1.k=t2.k;

# ok, it does not rely on the columns's datatype
select * from t1 asof join t2 on t1.ts = t2.ts and t1.k>t2.k;

# ok
select * from t1 asof join t2 on t1.k=t2.k and t1.ts + INTERVAL 5 minute > date_trunc('hour', t2.ts);

# error, only support one condition
select * from t1 asof join t2 on t1.ts < t2.ts and t1.k>t2.k;
Binder Error: Multiple ASOF JOIN inequalities

# error 
select * from t1 asof join t2 where t1.k=t2.k and t1.ts > t2.ts;
Parser Error: syntax error at or near "where"
LINE 1: select * from t1 asof join t2 where t1.k=t2.k and t1.ts > t2.ts;

# error
select * from t1 asof join t2 on t1.k = t2.k where t1.ts > t2.ts;
Binder Error: Missing ASOF JOIN inequality

@lmatz
Copy link
Contributor Author

lmatz commented Aug 2, 2024

QuestDB has both ASOF Join (can be equal) and LT(strictly prior to) Join.
Other DBs use the comparison_operator to specify two use cases.

KDB differentiates the use cases by https://code.kx.com/q/basics/joins/#as-of-joins aj, aj0, ajf, ajf0.
0 is essentially ASOF LEFT JOIN in Clickhouse.

@fuyufjh fuyufjh modified the milestones: release-2.0, release-2.1 Aug 19, 2024
@fuyufjh fuyufjh changed the title Support ASOF JOIN Tracking: ASOF JOIN Sep 23, 2024
@fuyufjh fuyufjh added the type/tracking Tracking issue. label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants