-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Snowflake JSON and Geo-Spatial functions
Signed-off-by: Andreas Reichel <[email protected]>
- Loading branch information
1 parent
8e16734
commit 35f05fa
Showing
8 changed files
with
224 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
-- provided | ||
SELECT ST_AsBinary(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326)) b; | ||
SELECT 1; | ||
|
||
-- expected | ||
SELECT ST_ASWKB(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))'))::BLOB b; | ||
SELECT 1; | ||
|
||
-- count | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/resources/ai/starlake/transpiler/snowflake/geometry.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- provided | ||
SELECT ST_GEOMETRYFROMEWKB('0101000020797F000066666666A9CB17411F85EBC19E325641') g; | ||
|
||
-- expected | ||
SELECT | ||
IF( | ||
REGEXP_MATCHES('0101000020797F000066666666A9CB17411F85EBC19E325641','^[0-9A-Fa-f]+$') | ||
, ST_GEOMFROMHEXEWKB('0101000020797F000066666666A9CB17411F85EBC19E325641') | ||
, ST_GEOMFROMWKB(ENCODE('0101000020797F000066666666A9CB17411F85EBC19E325641') | ||
) | ||
) g; | ||
|
||
-- result | ||
"g" | ||
"POINT (389866.35 5819003.03)" | ||
|
||
|
||
-- provided | ||
SELECT TO_GEOMETRY('SRID=4326;POINT(1820.12 890.56)') g; | ||
|
||
-- expected | ||
SELECT Cast('SRID=4326;POINT(1820.12 890.56)' AS GEOMETRY) g; | ||
|
||
-- result | ||
"g" | ||
"POINT (1820.12 890.56)" |
89 changes: 89 additions & 0 deletions
89
src/test/resources/ai/starlake/transpiler/snowflake/json.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
-- prolog | ||
DROP TABLE IF EXISTS sample_json_table; | ||
CREATE TABLE sample_json_table (ID INTEGER, varchar1 VARCHAR, variant1 BLOB); | ||
INSERT INTO sample_json_table (ID, varchar1) VALUES | ||
(1, '{"ValidKey1": "ValidValue1"}'), | ||
(2, '{"Malformed -- Missing value": }'), | ||
(3, NULL) | ||
; | ||
UPDATE sample_json_table SET variant1 = varchar1::BLOB; | ||
|
||
-- provided | ||
SELECT ID, CHECK_JSON(varchar1) v, varchar1 FROM sample_json_table ORDER BY ID; | ||
|
||
-- expected | ||
SELECT ID, json_valid(varchar1) v, varchar1 FROM sample_json_table ORDER BY ID; | ||
|
||
-- result | ||
"ID","v","varchar1" | ||
"1","true","{""ValidKey1"": ""ValidValue1""}" | ||
"2","false","{""Malformed -- Missing value"": }" | ||
"3","","" | ||
|
||
-- epilog | ||
DROP TABLE IF EXISTS sample_json_table; | ||
|
||
|
||
-- prolog | ||
DROP TABLE IF EXISTS demo1; | ||
CREATE TABLE demo1 (id INTEGER, json_data VARCHAR); | ||
INSERT INTO demo1 SELECT | ||
1, '{"level_1_key": "level_1_value"}'; | ||
INSERT INTO demo1 SELECT | ||
2, '{"level_1_key": {"level_2_key": "level_2_value"}}'; | ||
INSERT INTO demo1 SELECT | ||
3, '{"level_1_key": {"level_2_key": ["zero", "one", "two"]}}'; | ||
|
||
-- provided | ||
SELECT | ||
JSON_EXTRACT_PATH_TEXT(json_data, 'level_1_key') | ||
AS JSON_EXTRACT_PATH_TEXT | ||
FROM demo1 | ||
ORDER BY id; | ||
|
||
|
||
-- expected | ||
SELECT | ||
json_data::JSON -> 'level_1_key' | ||
AS JSON_EXTRACT_PATH_TEXT | ||
FROM demo1 | ||
ORDER BY id; | ||
|
||
-- result | ||
"JSON_EXTRACT_PATH_TEXT" | ||
"""level_1_value""" | ||
"{""level_2_key"":""level_2_value""}" | ||
"{""level_2_key"":[""zero"",""one"",""two""]}" | ||
|
||
|
||
-- epilog | ||
DROP TABLE IF EXISTS demo1; | ||
|
||
|
||
-- prolog | ||
DROP TABLE IF EXISTS vartab; | ||
CREATE OR REPLACE TABLE vartab (ID INTEGER, v VARCHAR); | ||
|
||
INSERT INTO vartab (id, v) VALUES | ||
(1, '[-1, 12, 289, 2188, false,]'), | ||
(2, '{ "x" : "abc", "y" : false, "z": 10} '), | ||
(3, '{ "bad" : "json", "missing" : true, "close_brace": 10 '); | ||
|
||
-- provided | ||
SELECT ID, TRY_PARSE_JSON(v) j | ||
FROM vartab | ||
ORDER BY ID; | ||
|
||
-- expected | ||
SELECT ID, Try_Cast(v AS JSON) j | ||
FROM vartab | ||
ORDER BY ID; | ||
|
||
-- result | ||
"ID","j" | ||
"1","[-1, 12, 289, 2188, false,]" | ||
"2","{ ""x"" : ""abc"", ""y"" : false, ""z"": 10} " | ||
"3","" | ||
|
||
-- epilog | ||
DROP TABLE IF EXISTS vartab; |