You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Dmitry Sysolyatin (Jira)" <ji...@apache.org> on 2023/02/16 15:16:00 UTC
[jira] [Created] (CALCITE-5532) CompositeOperandsTypeChecking should check operands without type coercion first
Dmitry Sysolyatin created CALCITE-5532:
------------------------------------------
Summary: CompositeOperandsTypeChecking 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
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)