[CALCITE-2417] Fix ClassCastException in RelToSqlConverter with structs#761
[CALCITE-2417] Fix ClassCastException in RelToSqlConverter with structs#761BenoitHanotte wants to merge 1 commit intoapache:masterfrom
Conversation
|
Overall LGTM. Can you rename |
f3dee40 to
ff2aaf8
Compare
|
Hello @michaelmior, thanks for the feedback :) |
|
Hi @BenoitHanotte, for creating appropriate tests I believe you can add a few test methods in If you need a Schema with more nesting in order to test your feature wait for PR762. |
ff2aaf8 to
d0ce4b4
Compare
|
Thanks @zabetak , indeed the |
d0ce4b4 to
cb34cc1
Compare
|
Unfortunately I discovered that this fix is not giving correct names for the nested fields: gives the following query: I'll have alook at it this afternoon but from my limited understanding of the code, we'll have to make sure that |
cb34cc1 to
d917a53
Compare
|
@zabetak @michaelmior I updated my PR, it seems that in addition to the cast issue we were not correctly mapping the field index to the For instance, for a This way we can get the I added a few test cases to ensure that names were correctly retrieved for nested fields. |
| for (Function<RelNode, RelNode> transform : transforms) { | ||
| rel = transform.apply(rel); | ||
| } | ||
| System.out.println(RelOptUtil.toString(rel)); |
There was a problem hiding this comment.
Minor, but looks like this was for debugging and should be removed.
There was a problem hiding this comment.
Sorry, I forgot to remove it
| final RexCorrelVariable variable = (RexCorrelVariable) access.getReferenceExpr(); | ||
| final Context aliasContext = correlTableMap.get(variable.id); | ||
| return aliasContext.field(access.getField().getIndex()); | ||
| default: |
There was a problem hiding this comment.
The code assumes that FIELD_ACCESS wraps always a CORREL_VARIABLE or INPUT_REF. I have the impression that this code will lead again to a ClassCastException just a bit later (e.g., for a doubly nested struct where there is a RexFieldAccess(RexFieldAccess(RexInputRef)).
There was a problem hiding this comment.
You're right, I thought that it could only go down one level but after adding tests for multiple nested levels I see that it can happen, I am updating the PR to support this and add tests for this case
8e82059 to
f9d609c
Compare
|
I updated the PR to do the following:
I haven't been able to find a more elegant solution to the correlation variable case as I don't seem to be able to get the field index without having access to the last level of I tested this patch on our production schema and it seems to have solved the issue. |
Trying to convert the pysical plan of a select * query on a table with a nested struct throws ClassCastException as RexInputRef cannot be cast to RexCorrelVariable. This is due to the cast to RexCorrelVariable not being done on the referenced expression of RexInputRef accessible through RexFieldAccess.getReferenceExpr()
f9d609c to
bb977dd
Compare
|
Hello @michaelmior @zabetak would you have time for a review of this PR so that we can see whether this is the right approach or not? Thanks! |
|
LGTM, merged! Sorry for the delay. I was waiting for the latest release to go through and this slipped off my radar. Thanks for the contribution :) |
…ts (Benoit Hanotte) Trying to convert the pysical plan of a select * query on a table with a nested struct throws ClassCastException as RexInputRef cannot be cast to RexCorrelVariable. This is due to the cast to RexCorrelVariable not being done on the referenced expression of RexInputRef accessible through RexFieldAccess.getReferenceExpr() Close apache#761
…ts (Benoit Hanotte) Trying to convert the pysical plan of a select * query on a table with a nested struct throws ClassCastException as RexInputRef cannot be cast to RexCorrelVariable. This is due to the cast to RexCorrelVariable not being done on the referenced expression of RexInputRef accessible through RexFieldAccess.getReferenceExpr() Close apache#761
…ts (Benoit Hanotte) Trying to convert the pysical plan of a select * query on a table with a nested struct throws ClassCastException as RexInputRef cannot be cast to RexCorrelVariable. This is due to the cast to RexCorrelVariable not being done on the referenced expression of RexInputRef accessible through RexFieldAccess.getReferenceExpr() Close apache#761
…ts (Benoit Hanotte) Trying to convert the pysical plan of a select * query on a table with a nested struct throws ClassCastException as RexInputRef cannot be cast to RexCorrelVariable. This is due to the cast to RexCorrelVariable not being done on the referenced expression of RexInputRef accessible through RexFieldAccess.getReferenceExpr() Close apache#761
…ts (Benoit Hanotte) Trying to convert the pysical plan of a select * query on a table with a nested struct throws ClassCastException as RexInputRef cannot be cast to RexCorrelVariable. This is due to the cast to RexCorrelVariable not being done on the referenced expression of RexInputRef accessible through RexFieldAccess.getReferenceExpr() Close apache#761
…ts (Benoit Hanotte) Trying to convert the pysical plan of a select * query on a table with a nested struct throws ClassCastException as RexInputRef cannot be cast to RexCorrelVariable. This is due to the cast to RexCorrelVariable not being done on the referenced expression of RexInputRef accessible through RexFieldAccess.getReferenceExpr() Close apache#761
…ts (Benoit Hanotte) Trying to convert the pysical plan of a select * query on a table with a nested struct throws ClassCastException as RexInputRef cannot be cast to RexCorrelVariable. This is due to the cast to RexCorrelVariable not being done on the referenced expression of RexInputRef accessible through RexFieldAccess.getReferenceExpr() Close apache#761
…ts (Benoit Hanotte) Trying to convert the pysical plan of a select * query on a table with a nested struct throws ClassCastException as RexInputRef cannot be cast to RexCorrelVariable. This is due to the cast to RexCorrelVariable not being done on the referenced expression of RexInputRef accessible through RexFieldAccess.getReferenceExpr() Close apache#761
…ts (Benoit Hanotte) - This patch changes RelToSqlConvertedTest framework which is needed by the calcite-3138 Trying to convert the pysical plan of a select * query on a table with a nested struct throws ClassCastException as RexInputRef cannot be cast to RexCorrelVariable. This is due to the cast to RexCorrelVariable not being done on the referenced expression of RexInputRef accessible through RexFieldAccess.getReferenceExpr() Close apache#761 Change-Id: I43416d770e757deb521e4a1cebe003fcc73df7ee
…ts (Benoit Hanotte) - This patch changes RelToSqlConvertedTest framework which is needed by the calcite-3138 Trying to convert the pysical plan of a select * query on a table with a nested struct throws ClassCastException as RexInputRef cannot be cast to RexCorrelVariable. This is due to the cast to RexCorrelVariable not being done on the referenced expression of RexInputRef accessible through RexFieldAccess.getReferenceExpr() Close apache#761 Change-Id: I43416d770e757deb521e4a1cebe003fcc73df7ee
Trying to convert the pysical plan of a select * query on a table with a nested struct throws ClassCastException as RexInputRef cannot be cast to RexCorrelVariable.
This is due to the cast to RexCorrelVariable not being done on the referenced expression of RexInputRef accessible through RexFieldAccess.getReferenceExpr()
I am not sure how you would advise testing such a case? In order to isolate the issue I had to recreate a custom schema with a nested struct, however this is adds a lot of boiler plate.