This is an automated email from the ASF dual-hosted git repository.
yamamuro pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new 2183345 [SPARK-29854][SQL][TESTS] Add tests to check lpad/rpad throw
an exception for invalid length input
2183345 is described below
commit 218334523dacd116a03f2340ad89e33abe93e452
Author: Takeshi Yamamuro <[email protected]>
AuthorDate: Sat May 23 08:48:29 2020 +0900
[SPARK-29854][SQL][TESTS] Add tests to check lpad/rpad throw an exception
for invalid length input
### What changes were proposed in this pull request?
This PR intends to add trivial tests to check
https://github.com/apache/spark/pull/27024 has already been fixed in the master.
Closes #27024
### Why are the changes needed?
For test coverage.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Added tests.
Closes #28604 from maropu/SPARK-29854.
Authored-by: Takeshi Yamamuro <[email protected]>
Signed-off-by: Takeshi Yamamuro <[email protected]>
(cherry picked from commit 7ca73f03fbc6e213c30e725bf480709ed036a376)
Signed-off-by: Takeshi Yamamuro <[email protected]>
---
.../sql-tests/inputs/ansi/string-functions.sql | 1 +
.../sql-tests/inputs/string-functions.sql | 6 +++-
.../results/{ => ansi}/string-functions.sql.out | 34 +++++++++++++++++-----
.../sql-tests/results/string-functions.sql.out | 18 +++++++++++-
4 files changed, 50 insertions(+), 9 deletions(-)
diff --git
a/sql/core/src/test/resources/sql-tests/inputs/ansi/string-functions.sql
b/sql/core/src/test/resources/sql-tests/inputs/ansi/string-functions.sql
new file mode 100644
index 0000000..dd28e9b
--- /dev/null
+++ b/sql/core/src/test/resources/sql-tests/inputs/ansi/string-functions.sql
@@ -0,0 +1 @@
+--IMPORT string-functions.sql
diff --git a/sql/core/src/test/resources/sql-tests/inputs/string-functions.sql
b/sql/core/src/test/resources/sql-tests/inputs/string-functions.sql
index 8e33471..f5ed203 100644
--- a/sql/core/src/test/resources/sql-tests/inputs/string-functions.sql
+++ b/sql/core/src/test/resources/sql-tests/inputs/string-functions.sql
@@ -48,4 +48,8 @@ SELECT trim(LEADING 'xyz' FROM 'zzzytestxyz');
SELECT trim(LEADING 'xy' FROM 'xyxXxyLAST WORD');
SELECT trim(TRAILING 'xyz' FROM 'testxxzx');
SELECT trim(TRAILING 'xyz' FROM 'xyztestxxzx');
-SELECT trim(TRAILING 'xy' FROM 'TURNERyxXxy');
\ No newline at end of file
+SELECT trim(TRAILING 'xy' FROM 'TURNERyxXxy');
+
+-- Check lpad/rpad with invalid length parameter
+SELECT lpad('hi', 'invalid_length');
+SELECT rpad('hi', 'invalid_length');
diff --git
a/sql/core/src/test/resources/sql-tests/results/string-functions.sql.out
b/sql/core/src/test/resources/sql-tests/results/ansi/string-functions.sql.out
similarity index 87%
copy from sql/core/src/test/resources/sql-tests/results/string-functions.sql.out
copy to
sql/core/src/test/resources/sql-tests/results/ansi/string-functions.sql.out
index 43c18f5..b507713 100644
--- a/sql/core/src/test/resources/sql-tests/results/string-functions.sql.out
+++
b/sql/core/src/test/resources/sql-tests/results/ansi/string-functions.sql.out
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
--- Number of queries: 34
+-- Number of queries: 36
-- !query
@@ -63,7 +63,7 @@ struct<locate(bar, foobarbar, 1):int,locate(CAST(NULL AS
STRING), foobarbar, 1):
-- !query
select left("abcd", 2), left("abcd", 5), left("abcd", '2'), left("abcd", null)
-- !query schema
-struct<left('abcd', 2):string,left('abcd', 5):string,left('abcd',
'2'):string,left('abcd', NULL):string>
+struct<left(abcd, 2):string,left(abcd, 5):string,left(abcd,
2):string,left(abcd, NULL):string>
-- !query output
ab abcd ab NULL
@@ -71,15 +71,16 @@ ab abcd ab NULL
-- !query
select left(null, -2), left("abcd", -2), left("abcd", 0), left("abcd", 'a')
-- !query schema
-struct<left(NULL, -2):string,left('abcd', -2):string,left('abcd',
0):string,left('abcd', 'a'):string>
+struct<>
-- !query output
-NULL NULL
+java.lang.NumberFormatException
+invalid input syntax for type numeric: a
-- !query
select right("abcd", 2), right("abcd", 5), right("abcd", '2'), right("abcd",
null)
-- !query schema
-struct<right('abcd', 2):string,right('abcd', 5):string,right('abcd',
'2'):string,right('abcd', NULL):string>
+struct<right(abcd, 2):string,right(abcd, 5):string,right(abcd,
2):string,right(abcd, NULL):string>
-- !query output
cd abcd cd NULL
@@ -87,9 +88,10 @@ cd abcd cd NULL
-- !query
select right(null, -2), right("abcd", -2), right("abcd", 0), right("abcd", 'a')
-- !query schema
-struct<right(NULL, -2):string,right('abcd', -2):string,right('abcd',
0):string,right('abcd', 'a'):string>
+struct<>
-- !query output
-NULL NULL
+java.lang.NumberFormatException
+invalid input syntax for type numeric: a
-- !query
@@ -274,3 +276,21 @@ SELECT trim(TRAILING 'xy' FROM 'TURNERyxXxy')
struct<TRIM(TRAILING xy FROM TURNERyxXxy):string>
-- !query output
TURNERyxX
+
+
+-- !query
+SELECT lpad('hi', 'invalid_length')
+-- !query schema
+struct<>
+-- !query output
+java.lang.NumberFormatException
+invalid input syntax for type numeric: invalid_length
+
+
+-- !query
+SELECT rpad('hi', 'invalid_length')
+-- !query schema
+struct<>
+-- !query output
+java.lang.NumberFormatException
+invalid input syntax for type numeric: invalid_length
diff --git
a/sql/core/src/test/resources/sql-tests/results/string-functions.sql.out
b/sql/core/src/test/resources/sql-tests/results/string-functions.sql.out
index 43c18f5..cb5501d 100644
--- a/sql/core/src/test/resources/sql-tests/results/string-functions.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/string-functions.sql.out
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
--- Number of queries: 34
+-- Number of queries: 36
-- !query
@@ -274,3 +274,19 @@ SELECT trim(TRAILING 'xy' FROM 'TURNERyxXxy')
struct<TRIM(TRAILING xy FROM TURNERyxXxy):string>
-- !query output
TURNERyxX
+
+
+-- !query
+SELECT lpad('hi', 'invalid_length')
+-- !query schema
+struct<lpad(hi, CAST(invalid_length AS INT), ):string>
+-- !query output
+NULL
+
+
+-- !query
+SELECT rpad('hi', 'invalid_length')
+-- !query schema
+struct<rpad(hi, CAST(invalid_length AS INT), ):string>
+-- !query output
+NULL
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]