Skip to content

Adding null fix for rows and col stats information.#14617

Merged
cryptoe merged 2 commits intoapache:masterfrom
cryptoe:SQL_STATMENT_BUG_FIX
Jul 19, 2023
Merged

Adding null fix for rows and col stats information.#14617
cryptoe merged 2 commits intoapache:masterfrom
cryptoe:SQL_STATMENT_BUG_FIX

Conversation

@cryptoe
Copy link
Copy Markdown
Contributor

@cryptoe cryptoe commented Jul 19, 2023

Null pointer fix for sql statement endpoint for "replace/Insert" q's. Since we donot populate the size counters for segment generation stage, the value is always null. Adjusted the code to be more defensive.

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@cryptoe cryptoe added Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262 Bug labels Jul 19, 2023
@cryptoe cryptoe added this to the 27.0 milestone Jul 19, 2023
Copy link
Copy Markdown
Contributor

@LakshSingla LakshSingla left a comment

Choose a reason for hiding this comment

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

Nitty comment, PR LGTM 💯

for (PageInformation pageInformation : pageList.get()) {
rows += pageInformation.getNumRows();
size += pageInformation.getSizeInBytes();
rows += pageInformation.getNumRows() != null ? pageInformation.getNumRows() : 0L;
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.

nit:

From the code, it seems like numRows can't be null, so can we modify the PageInformation instead to remove the Nullable tag for numRows, convert it to a long, and remove the check here?

Similarly, with this change, we aren't using the nullity of PageInformation::sizeOfBytes() anywhere apart from this check, therefore can we convert it to a primitive long, populate it as 0 instead of null, remove the Nullable and clean up the special handling here?

Since we don't require any special ability of the boxed types, it seems better to clean them up. WDYT?

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.

Since page information is serialized as json in the SqlStatementResult, I prefer PageInformation#numRows and sizeOfBytes to be Long. That way if they are not populated for whatever reason, they are not sent across to the end users.

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.

In that case, please add @JsonInclude(JsonInclude.Include.NON_NULL) to the Jackson annotations of the members of PageInformation. By default, we do serialize and present null values to the user. So per the current behavior, page information would get serialized as {"numRows":null,"sizeInBytes":null,"id":5}.

Approving the PR since the fix is not related to the current change.

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.

Good catch. Will do that in the next PR.

@cryptoe cryptoe merged commit ae168c4 into apache:master Jul 19, 2023
@cryptoe
Copy link
Copy Markdown
Contributor Author

cryptoe commented Jul 19, 2023

Thanks @LakshSingla for the review.

cryptoe added a commit that referenced this pull request Jul 19, 2023
* Adding null fix for rows and col stats information.

* Null handling test case fix

(cherry picked from commit ae168c4)
sergioferragut pushed a commit to sergioferragut/druid that referenced this pull request Jul 21, 2023
* Adding null fix for rows and col stats information.

* Null handling test case fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262 Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants