xuzifu666 commented on code in PR #4679:
URL: https://github.com/apache/calcite/pull/4679#discussion_r2612580892
##########
core/src/test/java/org/apache/calcite/rex/RexProgramTest.java:
##########
@@ -3152,7 +3152,9 @@ private SqlOperator getNoDeterministicOperator() {
checkSimplify(cast(literal(1), varcharType), "'1':VARCHAR(10)");
checkSimplifyUnchanged(cast(literalAbc, booleanType));
checkSimplify(cast(literal(1), booleanType),
- "false"); // different from Hive
+ "true"); // different from Hive
Review Comment:
Thanks, here not need this comment, I would delete it.
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java:
##########
@@ -430,6 +430,9 @@ private Expression getConvertExpression(
return Expressions.call(BuiltInMethod.STRING_TO_BOOLEAN.method,
operand);
default:
+ if (sourceType.getFamily() == SqlTypeFamily.NUMERIC) {
Review Comment:
I initially did it this way too, but considering that there will be many
```SqlTypeFamily.NUMERIC``` types, if new subtypes of this type are added in
the future, this part will also need to be modified accordingly, which may
cause omissions. What do you think about this?
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -825,6 +825,18 @@ void testCastToExactNumeric(CastType castType,
SqlOperatorFixture f) {
f.checkNull("CAST(CAST(NULL AS VARCHAR) AS VARBINARY)");
}
+ /**
+ * Test case for <a
href="https://issues.apache.org/jira/browse/CALCITE-7323">
+ * Result of cast Number to Boolean is not correct</a>. */
+ @Test public void testNumbericBooleanCast() {
+ SqlOperatorFixture f = fixture();
+ f.checkScalar("CAST(1 AS BOOLEAN)", "true", "BOOLEAN NOT NULL");
+ f.checkScalar("CAST(2 AS BOOLEAN)", "true", "BOOLEAN NOT NULL");
+ f.checkScalar("CAST(0 AS BOOLEAN)", "false", "BOOLEAN NOT NULL");
+ f.checkScalar("CAST(1.2 AS BOOLEAN)", "true", "BOOLEAN NOT NULL");
Review Comment:
Thanks for reminder, I would add more case about it.
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java:
##########
@@ -430,6 +430,9 @@ private Expression getConvertExpression(
return Expressions.call(BuiltInMethod.STRING_TO_BOOLEAN.method,
operand);
default:
+ if (sourceType.getFamily() == SqlTypeFamily.NUMERIC) {
+ return Expressions.call(BuiltInMethod.STRING_TO_BOOLEAN.method,
operand);
Review Comment:
I've confirmed that ```BuiltInMethod.STRING_TO_BOOLEAN``` directly calls
```SqlFunction.boolean toBoolean(Object o)```. It processes both String and
Number objects; it just seems the name is a bit odd.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]