diff --git a/sql/core/src/test/resources/sql-tests/inputs/pgSQL/text.sql b/sql/core/src/test/resources/sql-tests/inputs/pgSQL/text.sql new file mode 100644 index 0000000000000..04d3acc145e95 --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/inputs/pgSQL/text.sql @@ -0,0 +1,137 @@ +-- +-- Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group +-- +-- +-- TEXT +-- https://github.com/postgres/postgres/blob/REL_12_BETA2/src/test/regress/sql/text.sql + +SELECT string('this is a text string') = string('this is a text string') AS true; + +SELECT string('this is a text string') = string('this is a text strin') AS `false`; + +CREATE TABLE TEXT_TBL (f1 string) USING parquet; + +INSERT INTO TEXT_TBL VALUES ('doh!'); +INSERT INTO TEXT_TBL VALUES ('hi de ho neighbor'); + +SELECT '' AS two, * FROM TEXT_TBL; + +-- As of 8.3 we have removed most implicit casts to text, so that for example +-- this no longer works: +-- Spark SQL implicit cast integer to string +select length(42); + +-- But as a special exception for usability's sake, we still allow implicit +-- casting to text in concatenations, so long as the other input is text or +-- an unknown literal. So these work: +-- [SPARK-28033] String concatenation low priority than other arithmeticBinary +select string('four: ') || 2+2; +select 'four: ' || 2+2; + +-- but not this: +-- Spark SQL implicit cast both side to string +select 3 || 4.0; + +/* + * various string functions + */ +select concat('one'); +-- Spark SQL does not support YYYYMMDD, we replace it to yyyyMMdd +select concat(1,2,3,'hello',true, false, to_date('20100309','yyyyMMdd')); +select concat_ws('#','one'); +select concat_ws('#',1,2,3,'hello',true, false, to_date('20100309','yyyyMMdd')); +select concat_ws(',',10,20,null,30); +select concat_ws('',10,20,null,30); +select concat_ws(NULL,10,20,null,30) is null; +select reverse('abcde'); +-- [SPARK-28036] Built-in udf left/right has inconsistent behavior +-- [SPARK-28479] Parser error when enabling ANSI mode +set spark.sql.parser.ansi.enabled=false; +select i, left('ahoj', i), right('ahoj', i) from range(-5, 6) t(i) order by i; +set spark.sql.parser.ansi.enabled=true; +-- [SPARK-28037] Add built-in String Functions: quote_literal +-- select quote_literal(''); +-- select quote_literal('abc'''); +-- select quote_literal(e'\\'); + +-- Skip these tests because Spark does not support variadic labeled argument +-- check variadic labeled argument +-- select concat(variadic array[1,2,3]); +-- select concat_ws(',', variadic array[1,2,3]); +-- select concat_ws(',', variadic NULL::int[]); +-- select concat(variadic NULL::int[]) is NULL; +-- select concat(variadic '{}'::int[]) = ''; +--should fail +-- select concat_ws(',', variadic 10); + +-- [SPARK-27930] Replace format to format_string +/* + * format + */ +select format_string(NULL); +select format_string('Hello'); +select format_string('Hello %s', 'World'); +select format_string('Hello %%'); +select format_string('Hello %%%%'); +-- should fail +select format_string('Hello %s %s', 'World'); +select format_string('Hello %s'); +select format_string('Hello %x', 20); +-- check literal and sql identifiers +-- [SPARK-27930] format_string can not fully support PostgreSQL's format +-- select format_string('INSERT INTO %I VALUES(%L,%L)', 'mytab', 10, 'Hello'); +-- select format_string('%s%s%s','Hello', NULL,'World'); +-- select format_string('INSERT INTO %I VALUES(%L,%L)', 'mytab', 10, NULL); +-- select format_string('INSERT INTO %I VALUES(%L,%L)', 'mytab', NULL, 'Hello'); +-- should fail, sql identifier cannot be NULL +-- select format_string('INSERT INTO %I VALUES(%L,%L)', NULL, 10, 'Hello'); +-- check positional placeholders +select format_string('%1$s %3$s', 1, 2, 3); +select format_string('%1$s %12$s', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); +-- should fail +select format_string('%1$s %4$s', 1, 2, 3); +select format_string('%1$s %13$s', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); +--PostgreSQL throw ERROR: format specifies argument 0, but arguments are numbered from 1 +select format_string('%0$s', 'Hello'); +-- [SPARK-27930] format_string can not fully support PostgreSQL's format +-- select format_string('%*0$s', 'Hello'); +-- select format_string('%1$', 1); +-- select format_string('%1$1', 1); +-- check mix of positional and ordered placeholders +select format_string('Hello %s %1$s %s', 'World', 'Hello again'); +select format_string('Hello %s %s, %2$s %2$s', 'World', 'Hello again'); +-- Skip these tests because Spark does not support variadic labeled argument +-- check variadic labeled arguments +-- select format('%s, %s', variadic array['Hello','World']); +-- select format('%s, %s', variadic array[1, 2]); +-- select format('%s, %s', variadic array[true, false]); +-- select format('%s, %s', variadic array[true, false]::text[]); +-- check variadic with positional placeholders +-- select format('%2$s, %1$s', variadic array['first', 'second']); +-- select format('%2$s, %1$s', variadic array[1, 2]); +-- variadic argument can be array type NULL, but should not be referenced +-- select format('Hello', variadic NULL::int[]); +-- variadic argument allows simulating more than FUNC_MAX_ARGS parameters +-- select format(string_agg('%s',','), variadic array_agg(i)) +-- from generate_series(1,200) g(i); +-- check field widths and left, right alignment +select format_string('>>%10s<<', 'Hello'); +select format_string('>>%10s<<', NULL); +select format_string('>>%10s<<', ''); +select format_string('>>%-10s<<', ''); +select format_string('>>%-10s<<', 'Hello'); +select format_string('>>%-10s<<', NULL); +select format_string('>>%1$10s<<', 'Hello'); +-- [SPARK-27930] format_string can not fully support PostgreSQL's format +-- select format_string('>>%1$-10I<<', 'Hello'); +-- select format_string('>>%2$*1$L<<', 10, 'Hello'); +-- select format_string('>>%2$*1$L<<', 10, NULL); +-- select format_string('>>%2$*1$L<<', -10, NULL); +-- select format_string('>>%*s<<', 10, 'Hello'); +-- select format_string('>>%*1$s<<', 10, 'Hello'); +-- select format_string('>>%-s<<', 'Hello'); +-- select format_string('>>%10L<<', NULL); +-- select format_string('>>%2$*1$L<<', NULL, 'Hello'); +-- select format_string('>>%2$*1$L<<', 0, 'Hello'); + +DROP TABLE TEXT_TBL; diff --git a/sql/core/src/test/resources/sql-tests/results/pgSQL/text.sql.out b/sql/core/src/test/resources/sql-tests/results/pgSQL/text.sql.out new file mode 100644 index 0000000000000..cae75b8038c3b --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/results/pgSQL/text.sql.out @@ -0,0 +1,375 @@ +-- Automatically generated by SQLQueryTestSuite +-- Number of queries: 44 + + +-- !query 0 +SELECT string('this is a text string') = string('this is a text string') AS true +-- !query 0 schema +struct +-- !query 0 output +true + + +-- !query 1 +SELECT string('this is a text string') = string('this is a text strin') AS `false` +-- !query 1 schema +struct +-- !query 1 output +false + + +-- !query 2 +CREATE TABLE TEXT_TBL (f1 string) USING parquet +-- !query 2 schema +struct<> +-- !query 2 output + + + +-- !query 3 +INSERT INTO TEXT_TBL VALUES ('doh!') +-- !query 3 schema +struct<> +-- !query 3 output + + + +-- !query 4 +INSERT INTO TEXT_TBL VALUES ('hi de ho neighbor') +-- !query 4 schema +struct<> +-- !query 4 output + + + +-- !query 5 +SELECT '' AS two, * FROM TEXT_TBL +-- !query 5 schema +struct +-- !query 5 output +doh! + hi de ho neighbor + + +-- !query 6 +select length(42) +-- !query 6 schema +struct +-- !query 6 output +2 + + +-- !query 7 +select string('four: ') || 2+2 +-- !query 7 schema +struct<(CAST(concat(CAST(four: AS STRING), CAST(2 AS STRING)) AS DOUBLE) + CAST(2 AS DOUBLE)):double> +-- !query 7 output +NULL + + +-- !query 8 +select 'four: ' || 2+2 +-- !query 8 schema +struct<(CAST(concat(four: , CAST(2 AS STRING)) AS DOUBLE) + CAST(2 AS DOUBLE)):double> +-- !query 8 output +NULL + + +-- !query 9 +select 3 || 4.0 +-- !query 9 schema +struct +-- !query 9 output +34.0 + + +-- !query 10 +/* + * various string functions + */ +select concat('one') +-- !query 10 schema +struct +-- !query 10 output +one + + +-- !query 11 +select concat(1,2,3,'hello',true, false, to_date('20100309','yyyyMMdd')) +-- !query 11 schema +struct +-- !query 11 output +123hellotruefalse2010-03-09 + + +-- !query 12 +select concat_ws('#','one') +-- !query 12 schema +struct +-- !query 12 output +one + + +-- !query 13 +select concat_ws('#',1,2,3,'hello',true, false, to_date('20100309','yyyyMMdd')) +-- !query 13 schema +struct +-- !query 13 output +1#x#x#hello#true#false#x-03-09 + + +-- !query 14 +select concat_ws(',',10,20,null,30) +-- !query 14 schema +struct +-- !query 14 output +10,20,30 + + +-- !query 15 +select concat_ws('',10,20,null,30) +-- !query 15 schema +struct +-- !query 15 output +102030 + + +-- !query 16 +select concat_ws(NULL,10,20,null,30) is null +-- !query 16 schema +struct<(concat_ws(CAST(NULL AS STRING), CAST(10 AS STRING), CAST(20 AS STRING), NULL, CAST(30 AS STRING)) IS NULL):boolean> +-- !query 16 output +true + + +-- !query 17 +select reverse('abcde') +-- !query 17 schema +struct +-- !query 17 output +edcba + + +-- !query 18 +set spark.sql.parser.ansi.enabled=false +-- !query 18 schema +struct +-- !query 18 output +spark.sql.parser.ansi.enabled false + + +-- !query 19 +select i, left('ahoj', i), right('ahoj', i) from range(-5, 6) t(i) order by i +-- !query 19 schema +struct +-- !query 19 output +-5 +-4 +-3 +-2 +-1 +0 +1 a j +2 ah oj +3 aho hoj +4 ahoj ahoj +5 ahoj ahoj + + +-- !query 20 +set spark.sql.parser.ansi.enabled=true +-- !query 20 schema +struct +-- !query 20 output +spark.sql.parser.ansi.enabled true + + +-- !query 21 +/* + * format + */ +select format_string(NULL) +-- !query 21 schema +struct +-- !query 21 output +NULL + + +-- !query 22 +select format_string('Hello') +-- !query 22 schema +struct +-- !query 22 output +Hello + + +-- !query 23 +select format_string('Hello %s', 'World') +-- !query 23 schema +struct +-- !query 23 output +Hello World + + +-- !query 24 +select format_string('Hello %%') +-- !query 24 schema +struct +-- !query 24 output +Hello % + + +-- !query 25 +select format_string('Hello %%%%') +-- !query 25 schema +struct +-- !query 25 output +Hello %% + + +-- !query 26 +select format_string('Hello %s %s', 'World') +-- !query 26 schema +struct<> +-- !query 26 output +java.util.MissingFormatArgumentException +Format specifier '%s' + + +-- !query 27 +select format_string('Hello %s') +-- !query 27 schema +struct<> +-- !query 27 output +java.util.MissingFormatArgumentException +Format specifier '%s' + + +-- !query 28 +select format_string('Hello %x', 20) +-- !query 28 schema +struct +-- !query 28 output +Hello 14 + + +-- !query 29 +select format_string('%1$s %3$s', 1, 2, 3) +-- !query 29 schema +struct +-- !query 29 output +1 3 + + +-- !query 30 +select format_string('%1$s %12$s', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) +-- !query 30 schema +struct +-- !query 30 output +1 12 + + +-- !query 31 +select format_string('%1$s %4$s', 1, 2, 3) +-- !query 31 schema +struct<> +-- !query 31 output +java.util.MissingFormatArgumentException +Format specifier '%4$s' + + +-- !query 32 +select format_string('%1$s %13$s', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) +-- !query 32 schema +struct<> +-- !query 32 output +java.util.MissingFormatArgumentException +Format specifier '%13$s' + + +-- !query 33 +select format_string('%0$s', 'Hello') +-- !query 33 schema +struct +-- !query 33 output +Hello + + +-- !query 34 +select format_string('Hello %s %1$s %s', 'World', 'Hello again') +-- !query 34 schema +struct +-- !query 34 output +Hello World World Hello again + + +-- !query 35 +select format_string('Hello %s %s, %2$s %2$s', 'World', 'Hello again') +-- !query 35 schema +struct +-- !query 35 output +Hello World Hello again, Hello again Hello again + + +-- !query 36 +select format_string('>>%10s<<', 'Hello') +-- !query 36 schema +struct>%10s<<, Hello):string> +-- !query 36 output +>> Hello<< + + +-- !query 37 +select format_string('>>%10s<<', NULL) +-- !query 37 schema +struct>%10s<<, NULL):string> +-- !query 37 output +>> null<< + + +-- !query 38 +select format_string('>>%10s<<', '') +-- !query 38 schema +struct>%10s<<, ):string> +-- !query 38 output +>> << + + +-- !query 39 +select format_string('>>%-10s<<', '') +-- !query 39 schema +struct>%-10s<<, ):string> +-- !query 39 output +>> << + + +-- !query 40 +select format_string('>>%-10s<<', 'Hello') +-- !query 40 schema +struct>%-10s<<, Hello):string> +-- !query 40 output +>>Hello << + + +-- !query 41 +select format_string('>>%-10s<<', NULL) +-- !query 41 schema +struct>%-10s<<, NULL):string> +-- !query 41 output +>>null << + + +-- !query 42 +select format_string('>>%1$10s<<', 'Hello') +-- !query 42 schema +struct>%1$10s<<, Hello):string> +-- !query 42 output +>> Hello<< + + +-- !query 43 +DROP TABLE TEXT_TBL +-- !query 43 schema +struct<> +-- !query 43 output +