You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Mihai Budiu (Jira)" <ji...@apache.org> on 2025/10/24 17:52:00 UTC
[jira] [Commented] (CALCITE-7245) Codegen generates invalid java code with case when and ROW types
[ https://issues.apache.org/jira/browse/CALCITE-7245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18032835#comment-18032835 ]
Mihai Budiu commented on CALCITE-7245:
--------------------------------------
I would not call that "type inference"; inference has been done a long time before, in the validator; this is just retrieving a type.
Clearly, the types are wrong. For each internal RelDataType there should be a unique representation in Java that everyone agrees on.
So the question is: which one of the two sides (caller or callee) is wrong, and how should it be fixed. Is there a constructor for Record1_ being generated? Maybe the constructor should be used to convert the array into a Record1_ object. That would be the responsibility of the cast I imagine.
Can this be turned into a quidem test? These are easier to read and write.
> Codegen generates invalid java code with case when and ROW types
> ----------------------------------------------------------------
>
> Key: CALCITE-7245
> URL: https://issues.apache.org/jira/browse/CALCITE-7245
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.41.0
> Reporter: Rafael Acevedo
> Priority: Major
> Attachments: 0001-Reproducer-for-case-when-issue-with-ROW.patch
>
>
> If a query has a structure like:
> {code:sql}
> CASE WHEN <condition> THEN cast(row(1) as row(a integer)) END
> {code}
> codegen using EnumerableRelImplementor generates invalid java code. The generated code infers that the case_when_value type is something like Record1_, while the cast expression returns a Object[] (the result of a SqlFunctions.array call).
> It seems that the type inference for those cases happen [here|https://github.com/apache/calcite/blob/cfaadedd8fd34c480395f9e843a73bf4bb8fe459/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java#L1522]. I've validated that the storageType for those cases is correct (Object[]), so maybe we should use it along with the typeFactory.getJavaClass result?
> I've attached a patch that reproduces the issue in CodeGeneratorTest. Note that generated code works fine for other types of casting happening inside a THEN clause but fails for ROW types.
> Any help is appreciated. I'm available to work on a patch if the approach I suggested makes sense. Thanks!
--
This message was sent by Atlassian Jira
(v8.20.10#820010)