[ 
https://issues.apache.org/jira/browse/CALCITE-6210?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17817314#comment-17817314
 ] 

Gonzalo Ortiz commented on CALCITE-6210:
----------------------------------------

As said, I'm very new to this. But AFAIU the rewrite is done _after_ type
inference. Correct me if I'm wrong, but I though the order was:
* Parsing (transforms from String to SqlNode)
* Validation (transforms from SqlNode to Rel). Type inference is done here.
* Optimization (my transformation is done here)

The transformation I'm applying may be naive, but it is done when types
match and is preserving the types. Specifically, it is rewriting
`cast(strExpression as VARBINARY)` as `hexToBinary(strExpression)` and
`hexToBinary` is a function that takes a single argument of type String
(aka VARCHAR) and transforms it to VARBINARY. I guess I'm relaxing the
types because the same code is applied when `strExpression` is CHAR[N] and
also when casting to BINARY, but in Pinot BINARY and VARBINARY are the same
type (and the same happens with CHAR[n] and VARCHAR).

El mar, 13 feb 2024 a las 23:28, Mihai Budiu (Jira) (<j...@apache.org>)



> Cast to VARBINARY causes an assertion failure
> ---------------------------------------------
>
>                 Key: CALCITE-6210
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6210
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.36.0
>            Reporter: Mihai Budiu
>            Priority: Minor
>              Labels: pull-request-available
>
> This test in SqlOperatorTest:
> {code:java}
>  SqlOperatorFixture f = fixture();
>  f.checkScalar("CAST('00' AS VARBINARY)", "00", "VARBINARY NOT NULL");
> {code}
> Causes the following assertion failure:
> {code}
> java.lang.AssertionError: value 00 does not match type class      
> org.apache.calcite.avatica.util.ByteString
>       at 
> org.apache.calcite.linq4j.tree.ConstantExpression.<init>(ConstantExpression.java:51)
>       at 
> org.apache.calcite.linq4j.tree.Expressions.constant(Expressions.java:585)
>       at 
> org.apache.calcite.linq4j.tree.OptimizeShuttle.visit(OptimizeShuttle.java:305)
>       at 
> org.apache.calcite.linq4j.tree.UnaryExpression.accept(UnaryExpression.java:39)
>       at 
> org.apache.calcite.linq4j.tree.TernaryExpression.accept(TernaryExpression.java:47)
>       at 
> org.apache.calcite.linq4j.tree.DeclarationStatement.accept(DeclarationStatement.java:45)
>       at 
> org.apache.calcite.linq4j.tree.DeclarationStatement.accept(DeclarationStatement.java:27)
>       at 
> org.apache.calcite.linq4j.tree.BlockBuilder.optimize(BlockBuilder.java:426)
>       at 
> org.apache.calcite.linq4j.tree.BlockBuilder.toBlock(BlockBuilder.java:340)
>       at 
> org.apache.calcite.rex.RexExecutorImpl.compile(RexExecutorImpl.java:102)
>       at 
> org.apache.calcite.rex.RexExecutorImpl.compile(RexExecutorImpl.java:68)
>       at 
> org.apache.calcite.rex.RexExecutorImpl.reduce(RexExecutorImpl.java:133)
>       at 
> org.apache.calcite.rex.RexSimplify.simplifyCast(RexSimplify.java:2272)
>       at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:292)
>       at 
> org.apache.calcite.rex.RexSimplify.simplifyUnknownAs(RexSimplify.java:250)
>       at 
> org.apache.calcite.rex.RexSimplify.simplifyPreservingType(RexSimplify.java:189)
>       at 
> org.apache.calcite.rex.RexSimplify.simplifyPreservingType(RexSimplify.java:184)
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to