[ https://issues.apache.org/jira/browse/CALCITE-5532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17692347#comment-17692347 ]
Julian Hyde commented on CALCITE-5532: -------------------------------------- Thank you for the explanation. Would it be straightforward to add such an operator Foo to {{{}MockSqlOperatorTable{}}}? Then add a test to {{SqlToRelConverterTest}} that uses that operator (the test should generate {code:java} Foo(ARRAY[1,2,3], ARRAY[4,5,6]) {code} rather than {code:java} Foo(CAST(ARRAY[1,2,3] TO VARCHAR), CAST(ARRAY[4,5,6] TO VARCHAR)) {code} Such a test, while not a true unit test, is more comprehensible, more maintainable, and more likely to alert us to relevant regressions than the true unit test that you wrote. If you write that test I will merge. > CompositeOperandTypeChecker should check operands without type coercion first > ----------------------------------------------------------------------------- > > Key: CALCITE-5532 > URL: https://issues.apache.org/jira/browse/CALCITE-5532 > Project: Calcite > Issue Type: Bug > Components: core > Affects Versions: 1.33.0 > Reporter: Dmitry Sysolyatin > Assignee: Dmitry Sysolyatin > Priority: Major > Labels: pull-request-available > Time Spent: 10m > Remaining Estimate: 0h > > If define an operator with the following type checker: > {code} > SqlSingleOperandTypeChecker operandTypeChecker = OperandTypes.or( > OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING) > .and(OperandTypes.SAME_SAME), > OperandTypes.family(SqlTypeFamily.INTEGER, SqlTypeFamily.INTEGER) > .and(OperandTypes.SAME_SAME)); > {code} > and pass two operands with INTEGER type to this type checker. Then they will > be wrapped into CAST operator which will cast them to VARCHAR. But they > shouldn't be casted to VARCHAR. > Testcase: > {code:java} > @Test void testCompositeOperandTypeWithoutCast() { > SqlValidator validator = SqlTestFactory.INSTANCE.createValidator(); > SqlSingleOperandTypeChecker operandTypeChecker = OperandTypes.or( > OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING) > .and(OperandTypes.SAME_SAME), > OperandTypes.family(SqlTypeFamily.INTEGER, SqlTypeFamily.INTEGER) > .and(OperandTypes.SAME_SAME)); > SqlBinaryOperator op = new SqlBinaryOperator( > "~", > SqlKind.OTHER, > 60, > true, > null, > null, > null); > List<SqlLiteral> args = ImmutableList.of( > SqlLiteral.createExactNumeric("20", SqlParserPos.ZERO), > SqlLiteral.createExactNumeric("30", SqlParserPos.ZERO)); > SqlCallBinding binding = new SqlCallBinding( > validator, > new EmptyScope((SqlValidatorImpl) validator), > new SqlBasicCall(op, args, SqlParserPos.ZERO)); > List<RelDataType> typesBeforeChecking = > ImmutableList.of(binding.getOperandType(0), > binding.getOperandType(1)); > operandTypeChecker.checkOperandTypes(binding, false); > # It fails > assertEquals(typesBeforeChecking.get(0), binding.getOperandType(0)); > assertEquals(typesBeforeChecking.get(1), binding.getOperandType(1)); > } > {code} > -- This message was sent by Atlassian Jira (v8.20.10#820010)