[
https://issues.apache.org/jira/browse/CALCITE-5532?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Dmitry Sysolyatin resolved CALCITE-5532.
----------------------------------------
Resolution: Fixed
Fixed in
[9b4eff0|https://github.com/apache/calcite/commit/9b4eff06d6a16b3013f01d5fe4bceeaff6822603].
Thanks for review [~mbudiu]!
> 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
> Fix For: 1.39.0
>
> 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)