Skip to content

Incremental GROUP BY _block_num and DISTINCT BY _block_num#1877

Open
leoyvens wants to merge 8 commits intomainfrom
incremental-distinct-on
Open

Incremental GROUP BY _block_num and DISTINCT BY _block_num#1877
leoyvens wants to merge 8 commits intomainfrom
incremental-distinct-on

Conversation

@leoyvens
Copy link
Collaborator

This implements two related features:

  1. Streaming DISTINCT ON and GROUP BY, when the key is _block_num
  2. Using function call syntax block_num() to more easily refer to the block number anywhere in the query.

Our execution semantics essentially already support the special case where an aggregation is restricted to within a block, thanks to the assumption that data for a same block never spans more than a single microbatch. So executing the aggregation in isolation on each microbatch yields correct results. The necessary changes were around incremental query validation checks and block number propagation.

leoyvens and others added 6 commits February 26, 2026 15:13
Signed-off-by: Leonardo Yvens <leoyvens@gmail.com>
Allow GROUP BY queries that include _block_num as a group key to work with
incremental processing instead of being rejected.

- Handle Aggregate in BlockNumPropagator by setting next_block_num_expr
- Remove Aggregate from the unsupported-node error arm

Signed-off-by: Leonardo Yvens <leoyvens@gmail.com>
@leoyvens leoyvens requested a review from Theodus February 27, 2026 14:49
@leoyvens leoyvens marked this pull request as draft February 27, 2026 14:49
@leoyvens leoyvens marked this pull request as ready for review February 27, 2026 15:00
Copy link
Contributor

@LNSD LNSD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, check my comments 🙂

pub use datafusion::{arrow, parquet};
pub use datasets_common::{block_num::BlockNum, block_range::BlockRange, end_block::EndBlock};

pub mod block_num_udf;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename the module to just block_num? maybe we can move all the UDFs under common::udfs (e.g., common::udfs::evm::* or common::udfs::block_num)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed

Signed-off-by: Leo <leo@edgeandnode.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants