You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Vladimir Sitnikov (JIRA)" <ji...@apache.org> on 2018/08/02 21:54:00 UTC
[jira] [Comment Edited] (CALCITE-2438) RexCall#isAlwaysTrue return
incorrect result
[ https://issues.apache.org/jira/browse/CALCITE-2438?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16567490#comment-16567490 ]
Vladimir Sitnikov edited comment on CALCITE-2438 at 8/2/18 9:53 PM:
--------------------------------------------------------------------
Here's a test case (to be placed in {{RexProgramTest}}):
{code:java}
@Test public void testAlwaysTrueFalse() {
RelDataType in = typeFactory.createSqlType(SqlTypeName.BOOLEAN);
SqlOperator[] operators = new SqlOperator[]{
SqlStdOperatorTable.NOT,
SqlStdOperatorTable.IS_FALSE,
SqlStdOperatorTable.IS_NOT_FALSE,
SqlStdOperatorTable.IS_TRUE,
SqlStdOperatorTable.IS_NOT_TRUE,
SqlStdOperatorTable.IS_NULL,
SqlStdOperatorTable.IS_NOT_NULL,
SqlStdOperatorTable.IS_UNKNOWN,
SqlStdOperatorTable.IS_NOT_UNKNOWN
};
for(boolean argNullability: new boolean[]{true, false}) {
RexInputRef arg = rexBuilder.makeInputRef(
typeFactory.createTypeWithNullability(
in, argNullability),
0);
for (SqlOperator op1 : operators) {
RexNode n1 = rexBuilder.makeCall(op1, arg);
checkTrueFalse(n1);
for (SqlOperator op2 : operators) {
RexNode n2 = rexBuilder.makeCall(op2, n1);
checkTrueFalse(n2);
for (SqlOperator op3 : operators) {
RexNode n3 = rexBuilder.makeCall(op3, n2);
checkTrueFalse(n3);
for (SqlOperator op4 : operators) {
RexNode n4 = rexBuilder.makeCall(op4, n3);
checkTrueFalse(n4);
}
}
}
}
}
}
private void checkTrueFalse(RexNode node) {
RexNode opt = this.simplify.simplify(node);
if (trueLiteral.equals(opt)) {
assertFalse(node.toString() + " optimizes to TRUE, isAlwaysFalse MUST not be true",
node.isAlwaysFalse());
if (!node.isAlwaysTrue()) {
assertTrue(node.toString() + " optimizes to TRUE, isAlwaysTrue MUST be true",
node.isAlwaysTrue());
}
}
if (falseLiteral.equals(opt)) {
assertFalse(node.toString() + " optimizes to FALSE, isAlwaysTrue MUST not be true",
node.isAlwaysTrue());
assertTrue(node.toString() + " optimizes to FALSE, isAlwaysFalse MUST be true",
node.isAlwaysFalse());
}
if (nullLiteral.equals(opt)) {
assertFalse(node.toString() + " optimizes to NULL, isAlwaysTrue MUST not be true",
node.isAlwaysTrue());
assertFalse(node.toString() + " optimizes to NULL, isAlwaysFalse MUST not be true",
node.isAlwaysFalse());
}
}
{code}
was (Author: vladimirsitnikov):
Here's a test case (to be placed in {{RexProgramTest}}):
{code:java}
@Test public void testAlwaysTrueFalse() {
RelDataType in = typeFactory.createSqlType(SqlTypeName.BOOLEAN);
SqlPostfixOperator[] operators = new SqlPostfixOperator[]{
SqlStdOperatorTable.IS_FALSE,
SqlStdOperatorTable.IS_NOT_FALSE,
SqlStdOperatorTable.IS_TRUE,
SqlStdOperatorTable.IS_NOT_TRUE,
SqlStdOperatorTable.IS_NULL,
SqlStdOperatorTable.IS_NOT_NULL,
SqlStdOperatorTable.IS_UNKNOWN,
SqlStdOperatorTable.IS_NOT_UNKNOWN
};
for(boolean argNullability: new boolean[]{true, false}) {
RexInputRef arg = rexBuilder.makeInputRef(
typeFactory.createTypeWithNullability(
in, argNullability),
0);
for (SqlPostfixOperator op1 : operators) {
RexNode n1 = rexBuilder.makeCall(op1, arg);
checkTrueFalse(n1);
for (SqlPostfixOperator op2 : operators) {
RexNode n2 = rexBuilder.makeCall(op2, n1);
checkTrueFalse(n2);
for (SqlPostfixOperator op3 : operators) {
RexNode n3 = rexBuilder.makeCall(op3, n2);
checkTrueFalse(n3);
for (SqlPostfixOperator op4 : operators) {
RexNode n4 = rexBuilder.makeCall(op4, n3);
checkTrueFalse(n4);
}
}
}
}
}
}
private void checkTrueFalse(RexNode node) {
RexNode opt = this.simplify.simplify(node);
if (trueLiteral.equals(opt)) {
assertFalse(node.toString() + " optimizes to TRUE, isAlwaysFalse MUST not be true",
node.isAlwaysFalse());
assertTrue(node.toString() + " optimizes to TRUE, isAlwaysTrue MUST be true",
node.isAlwaysTrue());
}
if (falseLiteral.equals(opt)) {
assertFalse(node.toString() + " optimizes to FALSE, isAlwaysTrue MUST not be true",
node.isAlwaysTrue());
assertTrue(node.toString() + " optimizes to FALSE, isAlwaysFalse MUST be true",
node.isAlwaysFalse());
}
if (nullLiteral.equals(opt)) {
assertFalse(node.toString() + " optimizes to NULL, isAlwaysTrue MUST not be true",
node.isAlwaysTrue());
assertFalse(node.toString() + " optimizes to NULL, isAlwaysFalse MUST not be true",
node.isAlwaysFalse());
}
}
{code}
> RexCall#isAlwaysTrue return incorrect result
> ---------------------------------------------
>
> Key: CALCITE-2438
> URL: https://issues.apache.org/jira/browse/CALCITE-2438
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.17.0
> Reporter: pengzhiwei
> Assignee: Julian Hyde
> Priority: Critical
> Attachments: 屏幕快照 2018-08-02 下午7.26.20.png, 屏幕快照 2018-08-02 下午7.34.26.png
>
>
> In the expression as followed:
> {code:java}
> ((sal IS NULL) IS NOT NULL) IS FALSE
> {code}
> The RexCall#isAlwaysTrue return true,however the correct answer is false.
> I find the reason is that there is a wrong logic in the isAlwaysTrue,when getKind() is IS_NOT_FALSE、IS_FALSE and IS_NOT_FALSE :
> !屏幕快照 2018-08-02 下午7.34.26.png!
> Can you have a check for me,thanks!
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)