-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for the release note entry! Nit suggestion to help it follow the Order of changes phrasing in the Release Notes Guidelines.
|
@@ -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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
146edcd
to
6893594
Compare
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.
6893594
to
b00448a
Compare
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.
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.