Repository navigation
[CALCITE-5948] Use explicit casting if element type in ARRAY/MAP does not equal derived component type - #3395
Conversation
1556351 to
8075f6c
Compare
| } else { | ||
| elementType = oddType; | ||
| } | ||
| if (operandTypes.get(i).equalsSansFieldNames(elementType)) { |
There was a problem hiding this comment.
can this be rewritten as if(!operandTypes.get(i)....) { call.setOperand() }
There was a problem hiding this comment.
yes, good point. fixed. thanks tanner for reviewing.
|
@tanclary hi, tanner. I have solved some comments. If you have time, could you help to review it again? thanks! |
|
@tanclary hi, Tanner. Sorry to ping you. It's been two weeks, could you help to review it again? Looking forward your comments. |
a48da42 to
824f2bb
Compare
| +------------------+ | ||
| | EXPR$0 | | ||
| +------------------+ | ||
| | [a , null, bcd] | |
There was a problem hiding this comment.
Why is there an extra space?
There was a problem hiding this comment.
@JiajunBernoulli thanks for reviewing. this is a import change in this PR.
if we have array('A', 'AB'), the derived component type is char(2), the old behavior not cast 'A' to char(2) in runtime to match derived component type. The correct behavior let 'A' match the char(2), 'A' cast to char(2), then it will fill with extra spaces by default in calcite.
This is calcite and sql standard limitation. Of course, this does look weird, actually calcite has other ways to remove spaces. We can activate SqlConformanceEnum.PRAGMATIC_2003 to let shouldConvertRaggedUnionTypesToVarying be true, it will change array/map char type to varchar type to skip these spaces.
More details can be found in javadoc https://github.com/apache/calcite/blob/d9dd3ac8a9f695e111a0a5e77f45b61b90f4b5b6/core/src/main/java/org/apache/calcite/sql/validate/SqlConformance.java#L465C7-L465C7
I also have added some cases in the PR to show this difference.
There was a problem hiding this comment.
@JiajunBernoulli hi, Jiajun. If you have time, could you help to review it again? thanks
There was a problem hiding this comment.
Ok, Thank you for your clear explanation.
tanclary
left a comment
There was a problem hiding this comment.
Hi @chucheng92 Sorry for delay, thanks for addressing the changes. I'm okay to merge this as soon as @JiajunBernoulli is too.
824f2bb to
57737be
Compare
57737be to
06464ea
Compare
|
Thanks Tanner and Jiajun for reviewing. All comments are resolved/confirmed. |
|
@julianhyde hi, julian. I noticed that you gave a comment in the ticket to suggest giving a test case for calcite-5960. I have added it, if you have time, could you help to review it? If you approve that, then i will squash the commits. thanks! |
95ec19f to
a30469b
Compare
8704704 to
4feaa6b
Compare
calcite-5960 has been resolved. |
|
thanks Julian and Vladimir for reviewing the related commit calcite-5960. Considering that commit has been resolved, so I have rebased this PR. Currently all comments are resolved. Hi, @tanclary sorry to ping you, if you have time, could you help to recheck/merge this? |
a9befa2 to
90de969
Compare
… not equal derived component type
90de969 to
f64e4ac
Compare
|
Kudos, SonarCloud Quality Gate passed! |
|
hi Tanner @tanclary , if you are free, could you help to take a look again? Sorry to bother you. |
|
@tanclary Hi, Tanner, I have updated the commit & jira name and added javadocs. If you have time, could you help to review it again? thank you. |
tanclary
left a comment
There was a problem hiding this comment.
Hi @chucheng92 sorry for the delay, I was out unexpectedly for a couple of weeks. Thank you for resolving all of the comments, I think this looks great.
| // Result should be "EXPR$0=[1, 1.1]\n"; [CALCITE-4850] logged. | ||
| CalciteAssert.that() | ||
| .query("select array[1, 1.1]") | ||
| .returns("EXPR$0=[0E+1, 1.1]\n"); |
There was a problem hiding this comment.
@tanclary thanks for patient reviewing! btw, I think we can safely close CALCITE-4850. The result has been corrected.
|
This change appears to introduce a severe performance regression when validating very large array constructors containing mixed-width string literals. We reproduced it using Apache Druid’s EXPLAIN PLAN FOR
SELECT COUNT(*)
FROM foo
WHERE long1 = 8
OR LOWER(string1) IN ('1', '2', ..., '1000000')Benchmark parameters:
Results:
The regression first appears after upgrading from Calcite 1.35 to 1.37; this PR was included in Calcite 1.36. A JFR profile of the 100,000-string case attributed most allocation pressure to:
The dominant stack was:
Numeric arrays generally do not reproduce the same degradation because their elements commonly already have the derived component type. Related Druid investigation: apache/druid#20326 (comment) |
|
Commenting on a closed PR is not useful, you should open a new issue in JIRA. |








https://issues.apache.org/jira/browse/CALCITE-5948