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

Handle exception for empty tables in elasticsearch #23850

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

K-Naga-Vivek
Copy link

@K-Naga-Vivek K-Naga-Vivek commented Oct 17, 2024

Add a catch block to handle the exception when a table in Elasticsearch does not have any columns. Previously, this situation would cause an internal error in Presto.

The code iterates through the mappings (columns) but lacks an exception handler for cases where an element is not found. So, catching the NoSuchElementException to throw the appropriate error.

Motivation and Context

#23849

Test Plan

Added the related testcase to the code change.

Tested and working as excepted.
image

Contributor checklist

  • Please make sure your submission complies with our development, formatting, commit message, and attribution guidelines.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

Elasticsearch Changes
* Improve handling of exceptions for empty tables in Elasticsearch :pr:`23850`

@K-Naga-Vivek K-Naga-Vivek requested a review from a team as a code owner October 17, 2024 03:30
Copy link

linux-foundation-easycla bot commented Oct 17, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@steveburnett
Copy link
Contributor

Thanks for the release note entry! Nit suggestion to help it follow the Order of changes phrasing in the Release Notes Guidelines.

== RELEASE NOTES ==

Elasticsearch Changes
* Improve handling of exceptions for empty tables in Elasticsearch :pr:`23850`

@@ -502,6 +503,9 @@ public IndexMetadata getIndexMetadata(String index)
catch (IOException e) {
throw new PrestoException(ELASTICSEARCH_INVALID_RESPONSE, e);
}
catch (NoSuchElementException e) {
throw new PrestoException(ELASTICSEARCH_QUERY_FAILURE, "Relation does not have any columns");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw new PrestoException(ELASTICSEARCH_QUERY_FAILURE, "Relation does not have any columns");
throw new PrestoException(ELASTICSEARCH_QUERY_FAILURE, "Relation does not have any columns", e);

@@ -502,6 +503,9 @@ public IndexMetadata getIndexMetadata(String index)
catch (IOException e) {
throw new PrestoException(ELASTICSEARCH_INVALID_RESPONSE, e);
}
catch (NoSuchElementException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain where this is thrown? I'm just wondering if it's because of the iteration on line 496.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, the issue occurs on the line mappings = mappings.elements().next();. When there are no properties, the flow enters the condition and proceeds to iterate to the next element, which leads to a NoSuchElementException.

Copy link
Contributor

@tdcmeehan tdcmeehan Oct 18, 2024

Choose a reason for hiding this comment

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

So instead of catching an exception, can you instead check if !hasNext() and throw?

@K-Naga-Vivek K-Naga-Vivek force-pushed the elasticsearch_fix branch 2 times, most recently from 146edcd to 6893594 Compare October 19, 2024 02:12
Add a catch block to handle the exception when a table in Elasticsearch
does not have any columns. Previously, this situation would cause an
internal error in Presto.
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.

3 participants