From 0c731059f49ef2a1aba1550cf279c8f6db296da4 Mon Sep 17 00:00:00 2001 From: Tanner Clary Date: Wed, 20 Mar 2024 10:43:02 -0700 Subject: [PATCH] [b/330547397] Adjust negative index handling for SPLIT If we receive a request like `SPLIT("a-b-c", "-", -2)`, we should return `b` since that is the second to last element of the resulting split ([a, b, c]). We can do this in BigQuery by reversing the array (using ARRAY_REVERSE) and then multiplying the index by -1. Previously, we correctly reversed the array, but we continued using the original negative index instead of its additive inverse. This change corrects that. --- connector/tableau/looker-jdbc/dialect.tdd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/connector/tableau/looker-jdbc/dialect.tdd b/connector/tableau/looker-jdbc/dialect.tdd index 579025a0369..04046273bcc 100644 --- a/connector/tableau/looker-jdbc/dialect.tdd +++ b/connector/tableau/looker-jdbc/dialect.tdd @@ -1648,7 +1648,8 @@ (SPLIT((%1), (%2))[SAFE_ORDINAL(%3)]) - (ARRAY_REVERSE(SPLIT((%1), (%2)))[SAFE_ORDINAL(%3)]) + + (ARRAY_REVERSE(SPLIT((%1), (%2)))[SAFE_ORDINAL(%3 * -1)])