Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gengliangwang committed Mar 24, 2021
1 parent 4cea569 commit a72dcfb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
Expand Up @@ -369,10 +369,11 @@ class AnsiTypeCoercionSuite extends AnalysisTest {
TypeCollection(ArrayType(StringType), StringType),
ArrayType(StringType, true))

// When there are multiple convertible types in the `TypeCollection`, use the closet convertible
// data type among convertible types.
// When there are multiple convertible types in the `TypeCollection`, use the closest
// convertible data type among convertible types.
shouldCast(IntegerType, TypeCollection(BinaryType, FloatType, LongType), LongType)
shouldCast(IntegerType, TypeCollection(BinaryType, LongType, NumericType), IntegerType)
shouldCast(ShortType, TypeCollection(BinaryType, LongType, IntegerType), IntegerType)
shouldCast(ShortType, TypeCollection(DateType, LongType, IntegerType, DoubleType), IntegerType)
// If the result is Float type and Double type is also among the convertible target types,
// use Double Type instead of Float type.
shouldCast(LongType, TypeCollection(FloatType, DoubleType, StringType), DoubleType)
Expand Down
Expand Up @@ -17,9 +17,11 @@ select position('bar' in 'foobarbar'), position(null, 'foobarbar'), position('aa

-- left && right
select left("abcd", 2), left("abcd", 5), left("abcd", '2'), left("abcd", null);
select left(null, -2), left("abcd", -2), left("abcd", 0), left("abcd", 'a');
select left(null, -2);
select left("abcd", -2), left("abcd", 0), left("abcd", 'a');
select right("abcd", 2), right("abcd", 5), right("abcd", '2'), right("abcd", null);
select right(null, -2), right("abcd", -2), right("abcd", 0), right("abcd", 'a');
select right(null, -2);
select right("abcd", -2), right("abcd", 0), right("abcd", 'a');

-- split function
SELECT split('aa1cc2ee3', '[1-9]+');
Expand Down
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 48
-- Number of queries: 50


-- !query
Expand Down Expand Up @@ -69,14 +69,23 @@ ab abcd ab NULL


-- !query
select left(null, -2), left("abcd", -2), left("abcd", 0), left("abcd", 'a')
select left(null, -2)
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
cannot resolve 'substring(NULL, 1, -2)' due to data type mismatch: argument 1 requires (string or binary) type, however, 'NULL' is of null type.; line 1 pos 7


-- !query
select left("abcd", -2), left("abcd", 0), left("abcd", 'a')
-- !query schema
struct<>
-- !query output
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
Expand All @@ -87,14 +96,23 @@ cannot resolve 'substring('abcd', (- CAST('2' AS DOUBLE)), 2147483647)' due to d


-- !query
select right(null, -2), right("abcd", -2), right("abcd", 0), right("abcd", 'a')
select right(null, -2)
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
cannot resolve 'substring(NULL, (- -2), 2147483647)' due to data type mismatch: argument 1 requires (string or binary) type, however, 'NULL' is of null type.; line 1 pos 7


-- !query
select right("abcd", -2), right("abcd", 0), right("abcd", 'a')
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
cannot resolve 'substring('abcd', (- CAST('a' AS DOUBLE)), 2147483647)' due to data type mismatch: argument 2 requires int type, however, '(- CAST('a' AS DOUBLE))' is of double type.; line 1 pos 44


-- !query
SELECT split('aa1cc2ee3', '[1-9]+')
-- !query schema
Expand Down
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 48
-- Number of queries: 50


-- !query
Expand Down Expand Up @@ -69,11 +69,19 @@ ab abcd ab NULL


-- !query
select left(null, -2), left("abcd", -2), left("abcd", 0), left("abcd", 'a')
select left(null, -2)
-- !query schema
struct<left(NULL, -2):string,left(abcd, -2):string,left(abcd, 0):string,left(abcd, a):string>
struct<left(NULL, -2):string>
-- !query output
NULL NULL
NULL


-- !query
select left("abcd", -2), left("abcd", 0), left("abcd", 'a')
-- !query schema
struct<left(abcd, -2):string,left(abcd, 0):string,left(abcd, a):string>
-- !query output
NULL


-- !query
Expand All @@ -85,11 +93,19 @@ cd abcd cd NULL


-- !query
select right(null, -2), right("abcd", -2), right("abcd", 0), right("abcd", 'a')
select right(null, -2)
-- !query schema
struct<right(NULL, -2):string>
-- !query output
NULL


-- !query
select 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<right(abcd, -2):string,right(abcd, 0):string,right(abcd, a):string>
-- !query output
NULL NULL
NULL


-- !query
Expand Down

0 comments on commit a72dcfb

Please sign in to comment.