Rafael Acevedo created CALCITE-7245:
---------------------------------------
Summary: 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
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)