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

fix(sql): unhandled ArrayIndexOutOfBoundsException in ASOF and LT JOIN on empty table #3302

Merged
merged 2 commits into from
May 4, 2023

Conversation

puzpuzpuz
Copy link
Contributor

Fixes #3301

@puzpuzpuz puzpuzpuz added Bug Incorrect or unexpected behavior SQL Issues or changes relating to SQL execution labels May 4, 2023
@puzpuzpuz puzpuzpuz self-assigned this May 4, 2023
@jerrinot
Copy link
Contributor

jerrinot commented May 4, 2023

If I understand the problem well, it's caused by the fact the record.getRowId() has undefined behaviour when the Record does not point to anything, because there was no cursor.hasNext() returning true called. Is that right?

Do you think it would make sense to define the getRow() contract that way? currently, it says this:

    /**
     * Gets the numeric ID of this row. This can be not real table row id
     *
     * @return numeric ID of the current row
     */

how about:

    /**
     * Gets the numeric ID of this row. This can be not real table row id. 
     *
     * @return numeric ID of the current row or Long.LONG_NaN when the record is not associated with a valid row. 
     */

Or do you think LONG_NaN could be used to represent an actual row?

@jerrinot jerrinot self-requested a review May 4, 2023 10:04
@puzpuzpuz
Copy link
Contributor Author

Do you think it would make sense to define the getRow() contract that way?

To me, getRowId() contact should be the same as for getStr(int) or any other column accessor method, i.e. it should be called only when the record is initialized with a previous hasNext() call that returned true. Introducing a special contract for getRowId() only would make the Record API less consistent.

@jerrinot WDYT?

@jerrinot
Copy link
Contributor

jerrinot commented May 4, 2023

@puzpuzpuz that's a good point.

I thought the getRowId() was more meta-method than e.g getStr() and thus it should always return a well-defined result. but I understand your view too.

@puzpuzpuz
Copy link
Contributor Author

@jerrinot thanks for the review!

@ideoma
Copy link
Collaborator

ideoma commented May 4, 2023

[PR Coverage check]

😍 pass : 6 / 6 (100.00%)

file detail

path covered line new line coverage
🔵 io/questdb/griffin/engine/join/LtJoinLightRecordCursorFactory.java 3 3 100.00%
🔵 io/questdb/griffin/engine/join/AsOfJoinLightRecordCursorFactory.java 3 3 100.00%

@bluestreak01 bluestreak01 merged commit c92f227 into master May 4, 2023
20 checks passed
@bluestreak01 bluestreak01 deleted the puzpuzpuz_indexoutofbounds_in_asof_join branch May 4, 2023 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Incorrect or unexpected behavior SQL Issues or changes relating to SQL execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ArrayIndexOutOfBoundsException in ASOF JOIN query
4 participants