Skip to content

[CALCITE-7683] SessionizationEnumerator produces wrong results for SESSION table function - #5137

Open
mihaibudiu wants to merge 1 commit into
apache:mainfrom
mihaibudiu:issue7683
Open

[CALCITE-7683] SessionizationEnumerator produces wrong results for SESSION table function#5137
mihaibudiu wants to merge 1 commit into
apache:mainfrom
mihaibudiu:issue7683

Conversation

@mihaibudiu

Copy link
Copy Markdown
Contributor

Jira Link

CALCITE-7683

Changes Proposed

Computing session windows needs to sort by timestamp, but the data structure that was being used SortedMultiMap was not doing this.

@mihaibudiu
mihaibudiu requested a review from amaliujia July 31, 2026 17:55
@mihaibudiu

Copy link
Copy Markdown
Contributor Author

@amaliujia seems to have authored this code, so I am requesting his review.

…SSION table function

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@sonarqubecloud

Copy link
Copy Markdown

@amaliujia

Copy link
Copy Markdown
Contributor

Ah It's been a while to go back to this code and thanks for the finding. I will take a look.

"element[indexOfWatermarkedColumn]");
Object watermark = element[indexOfWatermarkedColumn];
if (watermark == null) {
// A row without a timestamp belongs to no session, and window_start

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is changing behavior:

The previous we expect all the rows should have timestamp otherwise will fail by requireNonNull.

Can you remind me when a row without timestamp could hit here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is a test: just insert a row with null timestamp in the input table.
The validator does not reject that.

// The windows of each key are kept sorted by start time; the merge
// below only compares a window with the one that precedes it.
Map<@Nullable Object, NavigableMap<Pair<Long, Long>, List<@Nullable Object[]>>>
sessionKeyMap = new HashMap<>();

@amaliujia amaliujia Aug 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am a bit confused: how do we achieve sorted timestamp here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SortedMultiMap sorts values (previous implementation), but NavigableMap is a subclass of SortedMap which sorts keys. Keys are Pair objects, which are Comparable.

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