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

GH-40249: [Java] Fix NPE in ArrowDatabaseMetadata #40988

Merged
merged 1 commit into from
Apr 7, 2024

Conversation

normanj-bitquill
Copy link
Contributor

@normanj-bitquill normanj-bitquill commented Apr 3, 2024

Rationale for this change

When retrieving database metadata using the JDBC driver, some data such as SQL keywords could be null. Before this change, an NPE would be thrown when trying to convert the list of SQL keywords into a String.

What changes are included in this PR?

The following database metadata fields:

  • SQL keywords
  • Numeric functions
  • String functions
  • System functions
  • Time/date functions

will convert to an empty string when they are null.

Are these changes tested?

A unit test has been added to verify that the fields above are converted to the empty string when null, with no exceptions thrown.

Are there any user-facing changes?

The fields above will now return an empty string rather than throw an NPE.

Copy link

github-actions bot commented Apr 3, 2024

⚠️ GitHub issue #40249 has been automatically assigned in GitHub to PR creator.

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Apr 3, 2024
@@ -754,7 +754,11 @@ private <T> T getSqlInfoAndCacheIfCacheIsEmpty(final SqlInfo sqlInfoCommand,
}

private String convertListSqlInfoToString(final List<?> sqlInfoList) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it would make more sense to return Optional<String> and update client code to explicitly decide what they want to do with missing values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is used by these methods:

  • getSqlKeywords()
  • getNumericFunctions()
  • getStringFunctions()
  • getSystemFunctions()
  • getTimeDateFunctions()

These methods come from Avatica, so we can't easily change the return type.

https://javadoc.io/static/org.apache.calcite.avatica/avatica-core/1.24.0/org/apache/calcite/avatica/AvaticaDatabaseMetaData.html#getSQLKeywords--

Copy link
Member

Choose a reason for hiding this comment

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

But we can update our implementations to be explicit, right?

In any case, defaulting to an empty string also seems fine so long as it's documented in the helper's docstring

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the return type of convertListSqlInfoToString() to a Optional<String>.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Apr 4, 2024
### Rationale for this change

When retrieving database metadata using the JDBC driver, some data such as SQL keywords
could be null. Before this change, an NPE would be thrown when trying to convert the
list of SQL keywords into a String.

### What changes are included in this PR?

The following database metadata fields:

* SQL keywords
* Numeric functions
* String functions
* System functions
* Time/date functions

will convert to an empty string when they are null.

### Are these changes tested?

A unit test has been added to verify that the fields above are converted to the empty
string when null, with no exceptions thrown.

### Are there any user-facing changes?

The fields above will now return an empty string rather than throw an NPE.
@normanj-bitquill normanj-bitquill force-pushed the 40249-nulls-in-sqlinfo branch from 35aa20a to 2a51fa6 Compare April 5, 2024 16:11
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Apr 5, 2024
@vibhatha
Copy link
Collaborator

vibhatha commented Apr 6, 2024

@github-actions crossbow submit java

Copy link

github-actions bot commented Apr 6, 2024

Revision: 2a51fa6

Submitted crossbow builds: ursacomputing/crossbow @ actions-f7fbc36bed

Task Status
java-jars GitHub Actions
verify-rc-source-java-linux-almalinux-8-amd64 GitHub Actions
verify-rc-source-java-linux-conda-latest-amd64 GitHub Actions
verify-rc-source-java-linux-ubuntu-20.04-amd64 GitHub Actions
verify-rc-source-java-linux-ubuntu-22.04-amd64 GitHub Actions
verify-rc-source-java-macos-amd64 GitHub Actions

@lidavidm lidavidm merged commit 805327e into apache:main Apr 7, 2024
16 checks passed
@lidavidm lidavidm removed the awaiting change review Awaiting change review label Apr 7, 2024
@github-actions github-actions bot added the awaiting merge Awaiting merge label Apr 7, 2024
Copy link

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 805327e.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 3 possible false positives for unstable benchmarks that are known to sometimes produce them.

verma-kartik pushed a commit to verma-kartik/arrow that referenced this pull request Apr 11, 2024
### Rationale for this change

When retrieving database metadata using the JDBC driver, some data such as SQL keywords could be null. Before this change, an NPE would be thrown when trying to convert the list of SQL keywords into a String.

### What changes are included in this PR?

The following database metadata fields:

* SQL keywords
* Numeric functions
* String functions
* System functions
* Time/date functions

will convert to an empty string when they are null.

### Are these changes tested?

A unit test has been added to verify that the fields above are converted to the empty string when null, with no exceptions thrown.

### Are there any user-facing changes?

The fields above will now return an empty string rather than throw an NPE.
* GitHub Issue: apache#40249

Authored-by: Norman Jordan <[email protected]>
Signed-off-by: David Li <[email protected]>
tolleybot pushed a commit to tmct/arrow that referenced this pull request May 2, 2024
### Rationale for this change

When retrieving database metadata using the JDBC driver, some data such as SQL keywords could be null. Before this change, an NPE would be thrown when trying to convert the list of SQL keywords into a String.

### What changes are included in this PR?

The following database metadata fields:

* SQL keywords
* Numeric functions
* String functions
* System functions
* Time/date functions

will convert to an empty string when they are null.

### Are these changes tested?

A unit test has been added to verify that the fields above are converted to the empty string when null, with no exceptions thrown.

### Are there any user-facing changes?

The fields above will now return an empty string rather than throw an NPE.
* GitHub Issue: apache#40249

Authored-by: Norman Jordan <[email protected]>
Signed-off-by: David Li <[email protected]>
vibhatha pushed a commit to vibhatha/arrow that referenced this pull request May 25, 2024
### Rationale for this change

When retrieving database metadata using the JDBC driver, some data such as SQL keywords could be null. Before this change, an NPE would be thrown when trying to convert the list of SQL keywords into a String.

### What changes are included in this PR?

The following database metadata fields:

* SQL keywords
* Numeric functions
* String functions
* System functions
* Time/date functions

will convert to an empty string when they are null.

### Are these changes tested?

A unit test has been added to verify that the fields above are converted to the empty string when null, with no exceptions thrown.

### Are there any user-facing changes?

The fields above will now return an empty string rather than throw an NPE.
* GitHub Issue: apache#40249

Authored-by: Norman Jordan <[email protected]>
Signed-off-by: David Li <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants