Skip to content

[FIX] Coerce NullLiteral to boolean in UnwrapCastInComparison#16444

Merged
martint merged 1 commit intotrinodb:masterfrom
gaurav8297:gaurav8297/fix_predicate_pushdown_null_literal
Mar 8, 2023
Merged

[FIX] Coerce NullLiteral to boolean in UnwrapCastInComparison#16444
martint merged 1 commit intotrinodb:masterfrom
gaurav8297:gaurav8297/fix_predicate_pushdown_null_literal

Conversation

@gaurav8297
Copy link
Copy Markdown
Member

@gaurav8297 gaurav8297 commented Mar 8, 2023

Coerce NullLiteral to boolean type in UnwrapCastInComparison otherwise PredicatePushDown rule could throw an error while creating FilterNode with NullLiteral as a predicate. This is because FilterNode cannot be created with just NullLiteral without proper coercions.

Steps to reproduce the issue in the current version:

CREATE TABLE sample_table_1 (a smallint, b varchar);

CREATE TABLE sample_table_2 (a smallint, b varchar);

WITH t AS (SELECT a,
CASE 
  WHEN b = 'ABCD' THEN 'ABC'
  ELSE 'CDB' END AS channel 
  FROM sample_table_2 t2)
SELECT * FROM sample_table_1 t1 JOIN t ON t1.a = t.a WHERE channel = 'TESTING';

Error: Query 20230308_141912_00008_fy4xb failed: Predicate must be an expression of boolean type: null

Description

Additional context and related issues

Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Mar 8, 2023
@gaurav8297 gaurav8297 marked this pull request as ready for review March 8, 2023 17:52
@gaurav8297 gaurav8297 changed the title [BUG] Coerce NullLiteral to boolean in UnwrapCastInComparison [FIX] Coerce NullLiteral to boolean in UnwrapCastInComparison Mar 8, 2023
@gaurav8297 gaurav8297 requested a review from sopel39 March 8, 2023 18:00
@sopel39 sopel39 requested a review from martint March 8, 2023 19:11
Coerce NullLiteral to boolean type otherwise predicate
pushdown rule could throw an error while creating FilterNode
with NullLiteral as a predicate. This is because FilterNode
cannot be created with just NullLiteral without proper
coercions.
@martint martint merged commit 9c64c56 into trinodb:master Mar 8, 2023
@github-actions github-actions bot added this to the 410 milestone Mar 9, 2023
@martint
Copy link
Copy Markdown
Member

martint commented Mar 9, 2023

I found a much simple reproduction. @gaurav8297, would you mind putting up a PR to replace the existing test with this?

WITH t(a) AS (
    VALUES 'a', 'b'
)
SELECT *
FROM t t1 JOIN t t2 ON true
WHERE t1.a = 'aa';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants