Handle exception for empty tables in elasticsearch#23850
Handle exception for empty tables in elasticsearch#23850tdcmeehan merged 1 commit intoprestodb:masterfrom
Conversation
|
|
|
Thanks for the release note entry! Nit suggestion to help it follow the Order of changes phrasing in the Release Notes Guidelines. |
| 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.
| 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); |
| catch (IOException e) { | ||
| throw new PrestoException(ELASTICSEARCH_INVALID_RESPONSE, e); | ||
| } | ||
| catch (NoSuchElementException e) { |
There was a problem hiding this comment.
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.
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.
So instead of catching an exception, can you instead check if !hasNext() and throw?
6893594 to
b00448a
Compare
Gracefully handle cases where Elasticsearch tables have no columns by returning empty metadata instead of triggering an internal error in Presto.
b00448a to
4a1df65
Compare
|
@tdcmeehan, as suggested, I’ve updated the code to return an empty list instead of throwing an error when encountering tables without columns. This change resolves the failing test case and functions as expected. Now, if a Could you please review the changes? |
|
Why does this connector throw at all if there are no columns? Can't it return a table with no columns? |
|
The connector is currently set to return an empty list, but Presto has a check in the StatementAnalyzer that throws an error if a table has no columns. |
|
Can we let the exception occur in the analyzer, instead of throwing within the Elastic Search connector? |
|
@tdcmeehan We are not throwing an exception within the connector. I've updated the code so that it now returns an empty list. The exception is now only thrown by the Analyzer. |
|
Got it. I was confused because I saw this message also in the Elastic client. |
|
Saved that user @K-Naga-Vivek is from IBM |
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.