From 5046269f5a89dc33bb937e79e518b43076736902 Mon Sep 17 00:00:00 2001 From: Eric Kidd Date: Mon, 16 Oct 2023 12:20:23 -0400 Subject: [PATCH] Test LENGTH, FARM_FINGERPRINT, ANSI aggregates --- tests/sql/functions/README.md | 10 +++---- tests/sql/functions/aggregate/ansi.sql | 27 +++++++++++++++++++ .../sql/functions/simple/farm_fingerprint.sql | 13 +++++++++ tests/sql/functions/simple/length.sql | 16 +++++++++++ 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 tests/sql/functions/aggregate/ansi.sql create mode 100644 tests/sql/functions/simple/farm_fingerprint.sql create mode 100644 tests/sql/functions/simple/length.sql diff --git a/tests/sql/functions/README.md b/tests/sql/functions/README.md index 6f477c4..f0a3b55 100644 --- a/tests/sql/functions/README.md +++ b/tests/sql/functions/README.md @@ -15,19 +15,19 @@ generate your own version of this list by running `joinery parse - [x] LOWER(_) - [x] TO_HEX(_) - [x] SHA256(_) -- [ ] LENGTH(_) +- [x] LENGTH(_) - [x] CONCAT(*) - [x] TRIM(_) - [ ] ARRAY_TO_STRING(_,_) -- [ ] SUM(_) -- [ ] FARM_FINGERPRINT(_) +- [x] SUM(_) +- [x] FARM_FINGERPRINT(_) - [ ] ANY_VALUE(_) - [ ] ROW_NUMBER() OVER(..) - [ ] COUNTIF(_) - [x] UPPER(_) - [ ] ARRAY_AGG(_) - [ ] DATE_TRUNC(_,_) (special) -- [ ] MIN(_) +- [x] MIN(_) - [ ] FORMAT_DATETIME(_,_) - [ ] RAND() - [ ] RANK() OVER(..) @@ -38,7 +38,7 @@ generate your own version of this list by running `joinery parse - [ ] CURRENT_DATETIME() - [ ] DATE_SUB(_,_) - [ ] EXP(_) -- [ ] MAX(_) +- [x] MAX(_) - [ ] GENERATE_UUID() - [ ] DATE(_) - [ ] LEAST(_,_) diff --git a/tests/sql/functions/aggregate/ansi.sql b/tests/sql/functions/aggregate/ansi.sql new file mode 100644 index 0000000..15e4e34 --- /dev/null +++ b/tests/sql/functions/aggregate/ansi.sql @@ -0,0 +1,27 @@ +-- ANSI standard aggregate functions: AVG, COUNT, MAX, MIN, SUM + +CREATE TEMP TABLE ints (i INT64); +INSERT INTO ints VALUES (1), (2), (2), (3); + +CREATE OR REPLACE TABLE __result1 AS +SELECT + -- Our Snowflake driver has trouble comparing FLOAT64s right now. + CAST(AVG(i) AS INT64) AS avg, + COUNT(i) AS count_all, + COUNT(DISTINCT i) AS count_distinct, + MAX(i) AS max, + MIN(i) AS min, + SUM(i) AS sum +FROM ints; + +CREATE OR REPLACE TABLE __expected1 ( + avg INT64, + count_all INT64, + count_distinct INT64, + max INT64, + min INT64, + sum INT64, +); + +INSERT INTO __expected1 VALUES + (2.0, 4, 3, 3, 1, 8); diff --git a/tests/sql/functions/simple/farm_fingerprint.sql b/tests/sql/functions/simple/farm_fingerprint.sql new file mode 100644 index 0000000..c3d195a --- /dev/null +++ b/tests/sql/functions/simple/farm_fingerprint.sql @@ -0,0 +1,13 @@ +-- pending: snowflake FARM_FINGERPRINT only exists on BigQuery +-- pending: sqlite3 FARM_FINGERPRINT only exists on BigQuery +CREATE OR REPLACE TABLE __result1 AS +SELECT + FARM_FINGERPRINT('foo') AS str_farm, + FARM_FINGERPRINT(null) AS null_farm; + +CREATE OR REPLACE TABLE __expected1 ( + str_farm INT64, + null_farm INT64, +); +INSERT INTO __expected1 VALUES + (6150913649986995171, NULL); \ No newline at end of file diff --git a/tests/sql/functions/simple/length.sql b/tests/sql/functions/simple/length.sql new file mode 100644 index 0000000..b8f6eb6 --- /dev/null +++ b/tests/sql/functions/simple/length.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE TABLE __result1 AS +SELECT + length('日本国') AS str_len, + -- Snowflake requires `to_binary(s, 'utf-8')`. CAST + -- assumes the string is hex-encoded. + -- + --length(CAST('日本国' AS BYTES)) AS bytes_len, + length(null) AS null_len; + +CREATE OR REPLACE TABLE __expected1 ( + str_len INT64, + --bytes_len INT64, + null_len INT64, +); +INSERT INTO __expected1 VALUES + (3, /*9,*/ NULL);