Skip to content

Substrait string concat with more than two arguments fails conversion to Calcite #724

@bestbeforetoday

Description

@bestbeforetoday

The Substrait concat function is variadic so allows more than two arguments. When converting a Substrait concat expression with three (or more) arguments to Calcite, an error occurs since Calcite's corresponding || operator only allows two operands:

java.lang.AssertionError: wrong operand count 3 for ||
	at org.apache.calcite.util.Litmus.lambda$static$0(Litmus.java:31)
	at org.apache.calcite.sql.SqlBinaryOperator.validRexOperands(SqlBinaryOperator.java:229)
	at org.apache.calcite.rex.RexCall.<init>(RexCall.java:93)
	at org.apache.calcite.rex.RexBuilder.makeCall(RexBuilder.java:293)
	at org.apache.calcite.rex.RexBuilder.makeCall(RexBuilder.java:279)
	at io.substrait.isthmus.expression.ExpressionRexConverter.visit(ExpressionRexConverter.java:433)

This could be resolved by modifying the expression during conversion to be nested / chained expressions, each with only two arguments. For example, concat(a, b, c) becomes concat(concat(a, b), c). This results in the expected Calcite (and SQL) output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions