Type a nested field access as the field's type, not the whole row - #5764
Conversation
PR Reviewer Guide 🔍(Review updated until commit e3207f7)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to e3207f7 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 00b639e
Suggestions up to commit f7bf594
Suggestions up to commit f43e49b
|
f43e49b to
f7bf594
Compare
|
Persistent review updated to latest commit f7bf594 |
f7bf594 to
00b639e
Compare
|
Persistent review updated to latest commit 00b639e |
|
Have you tried a field that's two levels deep, like From what I can tell, the whole remaining path arrives here as a single name —
|
A `nested` mapping is exposed as ARRAY<ROW<...>>, so a dotted access into it (parent.child) becomes ITEM(<array-of-rows>, 'child'). Calcite typed that as the whole ROW, so any later use of the value (a comparison, aggregation, etc.) failed with "Unsupported conversion for Relational Data type: ROW". Now we look the field up in the row and give the result that field's type (nullable, since an empty array reads as NULL). Only array-of-row access is affected; array indexing and map-key access are unchanged. Adds a unit test. Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
00b639e to
e3207f7
Compare
|
Persistent review updated to latest commit e3207f7 |
|
Yeah, you're right. Confirmed it: It's exactly what you said. Let's keep this PR to single level. I'll handle the deeper case with tests in a follow-up. |
Description
Nested fields don't work in PPL right now when the query runs through the analytics engine. The engine hands Calcite a nested field as an array of rows (
ARRAY<ROW<...>>), so something likeparent.childturns intoITEM(parent, 'child')(whereparentis the array andchildis the field name).The problem is that Calcite ignores the field name when it works out the type, so it types the result as the whole row instead of the
childfield. Any operation on it then breaks with:So even a simple
where parent.child > 4fails.This PR fixes the return type: when
ITEMis used on an array of rows with a field name, we look the field up in the row and use its type. It's nullable because an empty array returns null. Regular array indexing (arr[0]) and map access (map['key']) are not affected.Added a unit test for these cases.
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.