Skip to content

Commit

Permalink
Test LENGTH, FARM_FINGERPRINT, ANSI aggregates
Browse files Browse the repository at this point in the history
  • Loading branch information
emk committed Oct 16, 2023
1 parent f637139 commit 5046269
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/sql/functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(..)
Expand All @@ -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(_,_)
Expand Down
27 changes: 27 additions & 0 deletions tests/sql/functions/aggregate/ansi.sql
Original file line number Diff line number Diff line change
@@ -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);
13 changes: 13 additions & 0 deletions tests/sql/functions/simple/farm_fingerprint.sql
Original file line number Diff line number Diff line change
@@ -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);
16 changes: 16 additions & 0 deletions tests/sql/functions/simple/length.sql
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 5046269

Please sign in to comment.