-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-28038][SQL][TEST] Port text.sql #24862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
304c5c7
1068a10
4be0f9e
c9d3d16
10204c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| -- | ||
| -- 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 string('four: ') || 2+2; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: duplicate test
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update it to |
||
|
|
||
| -- 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 | ||
| -- select i, left('ahoj', i), right('ahoj', i) from range(-5, 5) t(i) order by i; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you comment out this? (I just want to check current output...)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of ANSI mode: spark-sql> select left('12345', 2);
12
spark-sql> set spark.sql.parser.ansi.enabled=true;
spark.sql.parser.ansi.enabled true
spark-sql> select left('12345', 2);
Error in query:
no viable alternative at input 'left'(line 1, pos 7)
== SQL ==
select left('12345', 2)
-------^^^https://issues.apache.org/jira/browse/SPARK-28479 The output if disable ANSI mode: Spark SQL: spark-sql> select i, left('ahoj', i), right('ahoj', i) from range(-5, 6) t(i) order by i;
-5
-4
-3
-2
-1
0
1 a j
2 ah oj
3 aho hoj
4 ahoj ahoj
5 ahoj ahojPostgreSQL: postgres=# select i, left('ahoj', i), right('ahoj', i) from generate_series(-5, 5) t(i) order by i;
i | left | right
----+------+-------
-5 | |
-4 | |
-3 | a | j
-2 | ah | oj
-1 | aho | hoj
0 | |
1 | a | j
2 | ah | oj
3 | aho | hoj
4 | ahoj | ahoj
5 | ahoj | ahoj
(11 rows)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. Can you turn temporarily off the mode for the query here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| -- [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; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: If we strictly follow ANSI/SQL, we don't allow this implicit cast along with PostgresSQL.
cc: @gengliangwang
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this casting an integer to string? If yes, I think it is allowed in ANSI SQL and up-cast.