Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: Fix issue with CAST and NULL checking. #50371

Merged
merged 2 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Nullability nullable() {
if (from().isNull()) {
return Nullability.TRUE;
}
return field().nullable();
return Nullability.UNKNOWN;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,20 @@ public void testNullFoldingIsNull() {
FoldNull foldNull = new FoldNull();
assertEquals(true, foldNull.rule(new IsNull(EMPTY, NULL)).fold());
assertEquals(false, foldNull.rule(new IsNull(EMPTY, TRUE)).fold());

Cast cast = new Cast(EMPTY, L("foo"), DataType.DATE);
IsNull isNull = new IsNull(EMPTY, cast);
assertEquals(isNull, foldNull.rule(isNull));
}

public void testNullFoldingIsNotNull() {
FoldNull foldNull = new FoldNull();
assertEquals(true, foldNull.rule(new IsNotNull(EMPTY, TRUE)).fold());
assertEquals(false, foldNull.rule(new IsNotNull(EMPTY, NULL)).fold());

Cast cast = new Cast(EMPTY, L("foo"), DataType.DATE);
IsNotNull isNotNull = new IsNotNull(EMPTY, cast);
assertEquals(isNotNull, foldNull.rule(isNotNull));
}

public void testGenericNullableExpression() {
Expand All @@ -461,6 +469,18 @@ public void testGenericNullableExpression() {
assertNullLiteral(rule.rule(new RLike(EMPTY, NULL, "123")));
}

public void testNullFoldingOnCast() {
FoldNull foldNull = new FoldNull();

Cast cast = new Cast(EMPTY, NULL, randomFrom(DataType.values()));
assertEquals(Nullability.TRUE, cast.nullable());
assertNull(foldNull.rule(cast).fold());

cast = new Cast(EMPTY, L("foo"), DataType.DATE);
assertEquals(Nullability.UNKNOWN, cast.nullable());
assertEquals(cast, foldNull.rule(cast));
}

public void testNullFoldingDoesNotApplyOnLogicalExpressions() {
FoldNull rule = new FoldNull();

Expand Down Expand Up @@ -1684,4 +1704,4 @@ public void testReplaceAttributesWithTarget() {
gt = (GreaterThan) and.left();
assertEquals(a, gt.left());
}
}
}