diff --git a/docker/trino/install-udfs b/docker/trino/install-udfs index 9d2f639..1b2a7b0 100755 --- a/docker/trino/install-udfs +++ b/docker/trino/install-udfs @@ -8,6 +8,7 @@ set -euo pipefail # URL of our Trino server. trino_url="${1:-"http://localhost:8080"}" +#echo trino_url: "$trino_url" until curl -s "$trino_url/v1/info" | grep -q '"starting":false'; do sleep 1; done trino --file "/etc/trino/trino_compat.sql" "$trino_url" diff --git a/sql/trino_compat.sql b/sql/trino_compat.sql index 1faf788..3e74eb0 100644 --- a/sql/trino_compat.sql +++ b/sql/trino_compat.sql @@ -1,34 +1,34 @@ -- Compatibility functions for Trino, needed to run code generated by Joinery. -CREATE FUNCTION memory.joinery_compat.DATETIME(date VARCHAR) +CREATE OR REPLACE FUNCTION memory.joinery_compat.DATETIME(date VARCHAR) RETURNS TIMESTAMP RETURNS NULL ON NULL INPUT RETURN ( CAST(date AS TIMESTAMP) ); -CREATE FUNCTION memory.joinery_compat.DATETIME(date DATE) +CREATE OR REPLACE FUNCTION memory.joinery_compat.DATETIME(date DATE) RETURNS TIMESTAMP RETURNS NULL ON NULL INPUT RETURN ( CAST(date AS TIMESTAMP) ); -CREATE FUNCTION memory.joinery_compat.GENERATE_UUID() +CREATE OR REPLACE FUNCTION memory.joinery_compat.GENERATE_UUID() RETURNS VARCHAR NOT DETERMINISTIC RETURN ( CAST(UUID() AS VARCHAR) ); -CREATE FUNCTION memory.joinery_compat.SHA256_COMPAT(input VARCHAR) +CREATE OR REPLACE FUNCTION memory.joinery_compat.SHA256_COMPAT(input VARCHAR) RETURNS VARBINARY RETURNS NULL ON NULL INPUT RETURN ( SHA256(TO_UTF8(input)) ); -CREATE FUNCTION memory.joinery_compat.SHA256_COMPAT(input VARBINARY) +CREATE OR REPLACE FUNCTION memory.joinery_compat.SHA256_COMPAT(input VARBINARY) RETURNS VARBINARY RETURNS NULL ON NULL INPUT RETURN ( @@ -36,7 +36,7 @@ RETURN ( ); -- Handle odd BigQuery behaviour around the `pos` argument. -CREATE FUNCTION memory.joinery_compat.SUBSTR_COMPAT(input VARCHAR, pos INT) +CREATE OR REPLACE FUNCTION memory.joinery_compat.SUBSTR_COMPAT(input VARCHAR, pos INT) RETURNS VARCHAR RETURNS NULL ON NULL INPUT RETURN ( @@ -50,7 +50,7 @@ RETURN ( -- As the two argument case, but also treat a length greater than the string as -- as "to the end of the string". -CREATE FUNCTION memory.joinery_compat.SUBSTR_COMPAT(input VARCHAR, pos INT, len INT) +CREATE OR REPLACE FUNCTION memory.joinery_compat.SUBSTR_COMPAT(input VARCHAR, pos INT, len INT) RETURNS VARCHAR RETURNS NULL ON NULL INPUT RETURN ( @@ -72,7 +72,7 @@ RETURN ( END ); -CREATE FUNCTION memory.joinery_compat.TO_HEX_COMPAT(input VARBINARY) +CREATE OR REPLACE FUNCTION memory.joinery_compat.TO_HEX_COMPAT(input VARBINARY) RETURNS VARCHAR RETURNS NULL ON NULL INPUT RETURN (