From 18117bb7cccbea4e450ea7057da9937950f8c33b Mon Sep 17 00:00:00 2001 From: Tanner Clary Date: Wed, 27 Mar 2024 10:27:31 -0700 Subject: [PATCH] [b/330573524] Prevent IF from treating NULL as FALSE Tableau offers the IIF function with the signature IIF(bool, val1, val2[, val3]). If bool is TRUE, it returns val1, if it is FALSE, it returns val2, and if it is NULL, it returns val3 if provided, otherwise it returns NULL. Previously, we translated this behavior by rewriting it as BigQuery's IF. The issue however, is that if bool is NULL, BigQuery defaults to val2 instead of NULL or val3. This commit corrects for that by wrapping the expression in another IF that checks if bool is NULL. If it is, it returns val3 if specified, otherwise NULL. If bool is not null, it follows normal IF behavior. --- connector/tableau/looker-jdbc/dialect.tdd | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/connector/tableau/looker-jdbc/dialect.tdd b/connector/tableau/looker-jdbc/dialect.tdd index 7136ee4bff4..389a86521dd 100644 --- a/connector/tableau/looker-jdbc/dialect.tdd +++ b/connector/tableau/looker-jdbc/dialect.tdd @@ -667,7 +667,8 @@ - IF((%1), (%2), (%3)) + + IF((%1) IS NOT NULL, IF((%1), (%2), (%3)), NULL) @@ -687,7 +688,7 @@ - IF((%1), (%2), (%3)) + IF((%1) IS NOT NULL, IF((%1), (%2), (%3)), NULL) @@ -700,7 +701,7 @@ - IF((%1), (%2), (%3)) + IF((%1) IS NOT NULL, IF((%1), (%2), (%3)), NULL) @@ -713,7 +714,7 @@ - IF((%1), (%2), (%3)) + IF((%1) IS NOT NULL, IF((%1), (%2), (%3)), NULL) @@ -726,7 +727,7 @@ - IF((%1), (%2), (%3)) + IF((%1) IS NOT NULL, IF((%1), (%2), (%3)), NULL) @@ -739,7 +740,7 @@ - IF((%1), (%2), (%3)) + IF((%1) IS NOT NULL, IF((%1), (%2), (%3)), NULL)