From 8f2c066622214dfae0ad36f7e55fae03fabb959e Mon Sep 17 00:00:00 2001 From: Takeshi Yamamuro Date: Wed, 13 Nov 2019 15:03:15 +0900 Subject: [PATCH 1/4] Fix --- .../ansi/decimalArithmeticOperations.sql | 2 + .../inputs/ansi/higher-order-functions.sql | 1 + .../sql-tests/inputs/ansi/interval.sql | 9 +- .../sql-tests/inputs/ansi/literals.sql | 2 + .../inputs/decimalArithmeticOperations.sql | 24 - .../inputs/higher-order-functions.sql | 5 - .../resources/sql-tests/inputs/literals.sql | 11 - .../ansi/decimalArithmeticOperations.sql.out | 347 ++++++++ .../ansi/higher-order-functions.sql.out | 284 +++++++ .../sql-tests/results/ansi/interval.sql.out | 246 +++--- .../sql-tests/results/ansi/literals.sql.out | 794 ++++++++++++++++++ .../decimalArithmeticOperations.sql.out | 129 +-- .../results/higher-order-functions.sql.out | 46 +- .../sql-tests/results/literals.sql.out | 162 +--- .../apache/spark/sql/SQLQueryTestSuite.scala | 34 +- .../ThriftServerQueryTestSuite.scala | 2 +- 16 files changed, 1622 insertions(+), 476 deletions(-) create mode 100644 sql/core/src/test/resources/sql-tests/inputs/ansi/decimalArithmeticOperations.sql create mode 100644 sql/core/src/test/resources/sql-tests/inputs/ansi/higher-order-functions.sql create mode 100644 sql/core/src/test/resources/sql-tests/inputs/ansi/literals.sql create mode 100644 sql/core/src/test/resources/sql-tests/results/ansi/decimalArithmeticOperations.sql.out create mode 100644 sql/core/src/test/resources/sql-tests/results/ansi/higher-order-functions.sql.out create mode 100644 sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out diff --git a/sql/core/src/test/resources/sql-tests/inputs/ansi/decimalArithmeticOperations.sql b/sql/core/src/test/resources/sql-tests/inputs/ansi/decimalArithmeticOperations.sql new file mode 100644 index 000000000000..200de766e86a --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/inputs/ansi/decimalArithmeticOperations.sql @@ -0,0 +1,2 @@ +-- throw an exception instead of returning NULL, according to SQL ANSI 2011 +--import decimalArithmeticOperations.sql diff --git a/sql/core/src/test/resources/sql-tests/inputs/ansi/higher-order-functions.sql b/sql/core/src/test/resources/sql-tests/inputs/ansi/higher-order-functions.sql new file mode 100644 index 000000000000..4068a27fcb2a --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/inputs/ansi/higher-order-functions.sql @@ -0,0 +1 @@ +--import higher-order-functions.sql diff --git a/sql/core/src/test/resources/sql-tests/inputs/ansi/interval.sql b/sql/core/src/test/resources/sql-tests/inputs/ansi/interval.sql index 4a831855a091..f662769f016c 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/ansi/interval.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/ansi/interval.sql @@ -1,6 +1,3 @@ --- Turns on ANSI mode -SET spark.sql.ansi.enabled=true; - select '1' second, 2 seconds, @@ -184,5 +181,7 @@ select date '2012-01-01' + interval (a + 1) day from t; select date '2012-01-01' + (a + 1) day from t; --- Turns off ANSI mode -SET spark.sql.ansi.enabled=false; +-- malformed interval literal with ansi mode +select 1 year to month; +select '1' year to second; +select 1 year '2-1' year to month; diff --git a/sql/core/src/test/resources/sql-tests/inputs/ansi/literals.sql b/sql/core/src/test/resources/sql-tests/inputs/ansi/literals.sql new file mode 100644 index 000000000000..170690ea699c --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/inputs/ansi/literals.sql @@ -0,0 +1,2 @@ +--- malformed interval literal with ansi mode +--import literals.sql diff --git a/sql/core/src/test/resources/sql-tests/inputs/decimalArithmeticOperations.sql b/sql/core/src/test/resources/sql-tests/inputs/decimalArithmeticOperations.sql index a946123f709c..28a0e20c0f49 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/decimalArithmeticOperations.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/decimalArithmeticOperations.sql @@ -83,28 +83,4 @@ select 12345678912345678912345678912.1234567 + 9999999999999999999999999999999.1 select 123456789123456789.1234567890 * 1.123456789123456789; select 12345678912345.123456789123 / 0.000000012345678; --- throw an exception instead of returning NULL, according to SQL ANSI 2011 -set spark.sql.ansi.enabled=true; - --- test operations between decimals and constants -select id, a*10, b/10 from decimals_test order by id; - --- test operations on constants -select 10.3 * 3.0; -select 10.3000 * 3.0; -select 10.30000 * 30.0; -select 10.300000000000000000 * 3.000000000000000000; -select 10.300000000000000000 * 3.0000000000000000000; - --- arithmetic operations causing an overflow throw exception -select (5e36 + 0.1) + 5e36; -select (-4e36 - 0.1) - 7e36; -select 12345678901234567890.0 * 12345678901234567890.0; -select 1e35 / 0.1; - --- arithmetic operations causing a precision loss throw exception -select 123456789123456789.1234567890 * 1.123456789123456789; -select 123456789123456789.1234567890 * 1.123456789123456789; -select 12345678912345.123456789123 / 0.000000012345678; - drop table decimals_test; diff --git a/sql/core/src/test/resources/sql-tests/inputs/higher-order-functions.sql b/sql/core/src/test/resources/sql-tests/inputs/higher-order-functions.sql index 8d5d9fae7a73..7665346f86ba 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/higher-order-functions.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/higher-order-functions.sql @@ -87,8 +87,3 @@ select transform_values(ys, (k, v) -> k + v) as v from nested; -- use non reversed keywords: all is non reversed only if !ansi select transform(ys, all -> all * all) as v from values (array(32, 97)) as t(ys); select transform(ys, (all, i) -> all + i) as v from values (array(32, 97)) as t(ys); - -set spark.sql.ansi.enabled=true; -select transform(ys, all -> all * all) as v from values (array(32, 97)) as t(ys); -select transform(ys, (all, i) -> all + i) as v from values (array(32, 97)) as t(ys); -set spark.sql.ansi.enabled=false; diff --git a/sql/core/src/test/resources/sql-tests/inputs/literals.sql b/sql/core/src/test/resources/sql-tests/inputs/literals.sql index 8c927d456c8b..c19d3f7055cd 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/literals.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/literals.sql @@ -143,17 +143,6 @@ select interval 1 year '2-1' year to month; select interval 1 year '12:11:10' hour to second; select interval '10-9' year to month '1' year; select interval '12:11:10' hour to second '1' year; --- malformed interval literal with ansi mode -SET spark.sql.ansi.enabled=true; -select interval; -select interval 1 fake_unit; -select interval 1 year to month; -select 1 year to month; -select interval '1' year to second; -select '1' year to second; -select interval 1 year '2-1' year to month; -select 1 year '2-1' year to month; -SET spark.sql.ansi.enabled=false; -- awareness of the negative sign before type select -integer '7'; diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/decimalArithmeticOperations.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/decimalArithmeticOperations.sql.out new file mode 100644 index 000000000000..9da6d0958527 --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/results/ansi/decimalArithmeticOperations.sql.out @@ -0,0 +1,347 @@ +-- Automatically generated by SQLQueryTestSuite +-- Number of queries: 40 + + +-- !query 0 +CREATE TEMPORARY VIEW t AS SELECT 1.0 as a, 0.0 as b +-- !query 0 schema +struct<> +-- !query 0 output + + + +-- !query 1 +select a / b from t +-- !query 1 schema +struct<(CAST(a AS DECIMAL(2,1)) / CAST(b AS DECIMAL(2,1))):decimal(8,6)> +-- !query 1 output +NULL + + +-- !query 2 +select a % b from t +-- !query 2 schema +struct<(CAST(a AS DECIMAL(2,1)) % CAST(b AS DECIMAL(2,1))):decimal(1,1)> +-- !query 2 output +NULL + + +-- !query 3 +select pmod(a, b) from t +-- !query 3 schema +struct +-- !query 3 output +NULL + + +-- !query 4 +create table decimals_test(id int, a decimal(38,18), b decimal(38,18)) using parquet +-- !query 4 schema +struct<> +-- !query 4 output + + + +-- !query 5 +insert into decimals_test values(1, 100.0, 999.0), (2, 12345.123, 12345.123), + (3, 0.1234567891011, 1234.1), (4, 123456789123456789.0, 1.123456789123456789) +-- !query 5 schema +struct<> +-- !query 5 output + + + +-- !query 6 +select id, a+b, a-b, a*b, a/b from decimals_test order by id +-- !query 6 schema +struct +-- !query 6 output +1 1099 -899 99900 0.1001 +2 24690.246 0 152402061.885129 1 +3 1234.2234567891011 -1233.9765432108989 152.358023 0.0001 +4 123456789123456790.12345678912345679 123456789123456787.87654321087654321 138698367904130467.515623 109890109097814272.043109 + + +-- !query 7 +select id, a*10, b/10 from decimals_test order by id +-- !query 7 schema +struct +-- !query 7 output +1 1000 99.9 +2 123451.23 1234.5123 +3 1.234567891011 123.41 +4 1234567891234567890 0.112345678912345679 + + +-- !query 8 +select 10.3 * 3.0 +-- !query 8 schema +struct<(CAST(10.3 AS DECIMAL(3,1)) * CAST(3.0 AS DECIMAL(3,1))):decimal(6,2)> +-- !query 8 output +30.9 + + +-- !query 9 +select 10.3000 * 3.0 +-- !query 9 schema +struct<(CAST(10.3000 AS DECIMAL(6,4)) * CAST(3.0 AS DECIMAL(6,4))):decimal(9,5)> +-- !query 9 output +30.9 + + +-- !query 10 +select 10.30000 * 30.0 +-- !query 10 schema +struct<(CAST(10.30000 AS DECIMAL(7,5)) * CAST(30.0 AS DECIMAL(7,5))):decimal(11,6)> +-- !query 10 output +309 + + +-- !query 11 +select 10.300000000000000000 * 3.000000000000000000 +-- !query 11 schema +struct<(CAST(10.300000000000000000 AS DECIMAL(20,18)) * CAST(3.000000000000000000 AS DECIMAL(20,18))):decimal(38,34)> +-- !query 11 output +30.9 + + +-- !query 12 +select 10.300000000000000000 * 3.0000000000000000000 +-- !query 12 schema +struct<(CAST(10.300000000000000000 AS DECIMAL(21,19)) * CAST(3.0000000000000000000 AS DECIMAL(21,19))):decimal(38,34)> +-- !query 12 output +30.9 + + +-- !query 13 +select 2.35E10 * 1.0 +-- !query 13 schema +struct<(CAST(2.35E+10 AS DECIMAL(12,1)) * CAST(1.0 AS DECIMAL(12,1))):decimal(6,-7)> +-- !query 13 output +23500000000 + + +-- !query 14 +select (5e36 + 0.1) + 5e36 +-- !query 14 schema +struct<> +-- !query 14 output +java.lang.ArithmeticException +Decimal(expanded,10000000000000000000000000000000000000.1,39,1}) cannot be represented as Decimal(38, 1). + + +-- !query 15 +select (-4e36 - 0.1) - 7e36 +-- !query 15 schema +struct<> +-- !query 15 output +java.lang.ArithmeticException +Decimal(expanded,-11000000000000000000000000000000000000.1,39,1}) cannot be represented as Decimal(38, 1). + + +-- !query 16 +select 12345678901234567890.0 * 12345678901234567890.0 +-- !query 16 schema +struct<> +-- !query 16 output +java.lang.ArithmeticException +Decimal(expanded,1.5241578753238836750190519987501905210E+38,38,-1}) cannot be represented as Decimal(38, 2). + + +-- !query 17 +select 1e35 / 0.1 +-- !query 17 schema +struct<> +-- !query 17 output +java.lang.ArithmeticException +Decimal(expanded,1000000000000000000000000000000000000,37,0}) cannot be represented as Decimal(38, 6). + + +-- !query 18 +select 1.2345678901234567890E30 * 1.2345678901234567890E25 +-- !query 18 schema +struct<> +-- !query 18 output +java.lang.ArithmeticException +Decimal(expanded,1.5241578753238836750190519987501905210E+55,38,-18}) cannot be represented as Decimal(38, -17). + + +-- !query 19 +select 12345678912345678912345678912.1234567 + 9999999999999999999999999999999.12345 +-- !query 19 schema +struct<(CAST(12345678912345678912345678912.1234567 AS DECIMAL(38,6)) + CAST(9999999999999999999999999999999.12345 AS DECIMAL(38,6))):decimal(38,6)> +-- !query 19 output +10012345678912345678912345678911.246907 + + +-- !query 20 +select 123456789123456789.1234567890 * 1.123456789123456789 +-- !query 20 schema +struct<(CAST(123456789123456789.1234567890 AS DECIMAL(36,18)) * CAST(1.123456789123456789 AS DECIMAL(36,18))):decimal(38,18)> +-- !query 20 output +138698367904130467.654320988515622621 + + +-- !query 21 +select 12345678912345.123456789123 / 0.000000012345678 +-- !query 21 schema +struct<(CAST(12345678912345.123456789123 AS DECIMAL(29,15)) / CAST(1.2345678E-8 AS DECIMAL(29,15))):decimal(38,9)> +-- !query 21 output +1000000073899961059796.725866332 + + +-- !query 22 +set spark.sql.decimalOperations.allowPrecisionLoss=false +-- !query 22 schema +struct +-- !query 22 output +spark.sql.decimalOperations.allowPrecisionLoss false + + +-- !query 23 +select id, a+b, a-b, a*b, a/b from decimals_test order by id +-- !query 23 schema +struct<> +-- !query 23 output +java.lang.ArithmeticException +Decimal(expanded,99900.000000000000000000000000000000000,38,33}) cannot be represented as Decimal(38, 36). + + +-- !query 24 +select id, a*10, b/10 from decimals_test order by id +-- !query 24 schema +struct +-- !query 24 output +1 1000 99.9 +2 123451.23 1234.5123 +3 1.234567891011 123.41 +4 1234567891234567890 0.1123456789123456789 + + +-- !query 25 +select 10.3 * 3.0 +-- !query 25 schema +struct<(CAST(10.3 AS DECIMAL(3,1)) * CAST(3.0 AS DECIMAL(3,1))):decimal(6,2)> +-- !query 25 output +30.9 + + +-- !query 26 +select 10.3000 * 3.0 +-- !query 26 schema +struct<(CAST(10.3000 AS DECIMAL(6,4)) * CAST(3.0 AS DECIMAL(6,4))):decimal(9,5)> +-- !query 26 output +30.9 + + +-- !query 27 +select 10.30000 * 30.0 +-- !query 27 schema +struct<(CAST(10.30000 AS DECIMAL(7,5)) * CAST(30.0 AS DECIMAL(7,5))):decimal(11,6)> +-- !query 27 output +309 + + +-- !query 28 +select 10.300000000000000000 * 3.000000000000000000 +-- !query 28 schema +struct<(CAST(10.300000000000000000 AS DECIMAL(20,18)) * CAST(3.000000000000000000 AS DECIMAL(20,18))):decimal(38,36)> +-- !query 28 output +30.9 + + +-- !query 29 +select 10.300000000000000000 * 3.0000000000000000000 +-- !query 29 schema +struct<> +-- !query 29 output +java.lang.ArithmeticException +Decimal(expanded,30.900000000000000000000000000000000000,38,36}) cannot be represented as Decimal(38, 37). + + +-- !query 30 +select 2.35E10 * 1.0 +-- !query 30 schema +struct<(CAST(2.35E+10 AS DECIMAL(12,1)) * CAST(1.0 AS DECIMAL(12,1))):decimal(6,-7)> +-- !query 30 output +23500000000 + + +-- !query 31 +select (5e36 + 0.1) + 5e36 +-- !query 31 schema +struct<> +-- !query 31 output +java.lang.ArithmeticException +Decimal(expanded,10000000000000000000000000000000000000.1,39,1}) cannot be represented as Decimal(38, 1). + + +-- !query 32 +select (-4e36 - 0.1) - 7e36 +-- !query 32 schema +struct<> +-- !query 32 output +java.lang.ArithmeticException +Decimal(expanded,-11000000000000000000000000000000000000.1,39,1}) cannot be represented as Decimal(38, 1). + + +-- !query 33 +select 12345678901234567890.0 * 12345678901234567890.0 +-- !query 33 schema +struct<> +-- !query 33 output +java.lang.ArithmeticException +Decimal(expanded,1.5241578753238836750190519987501905210E+38,38,-1}) cannot be represented as Decimal(38, 2). + + +-- !query 34 +select 1e35 / 0.1 +-- !query 34 schema +struct<> +-- !query 34 output +java.lang.ArithmeticException +Decimal(expanded,1000000000000000000000000000000000000,37,0}) cannot be represented as Decimal(38, 3). + + +-- !query 35 +select 1.2345678901234567890E30 * 1.2345678901234567890E25 +-- !query 35 schema +struct<> +-- !query 35 output +java.lang.ArithmeticException +Decimal(expanded,1.5241578753238836750190519987501905210E+55,38,-18}) cannot be represented as Decimal(38, -17). + + +-- !query 36 +select 12345678912345678912345678912.1234567 + 9999999999999999999999999999999.12345 +-- !query 36 schema +struct<> +-- !query 36 output +java.lang.ArithmeticException +Decimal(expanded,10012345678912345678912345678911.2469067,39,7}) cannot be represented as Decimal(38, 7). + + +-- !query 37 +select 123456789123456789.1234567890 * 1.123456789123456789 +-- !query 37 schema +struct<> +-- !query 37 output +java.lang.ArithmeticException +Decimal(expanded,138698367904130467.65432098851562262075,38,20}) cannot be represented as Decimal(38, 28). + + +-- !query 38 +select 12345678912345.123456789123 / 0.000000012345678 +-- !query 38 schema +struct<> +-- !query 38 output +java.lang.ArithmeticException +Decimal(expanded,1000000073899961059796.7258663315210392,38,16}) cannot be represented as Decimal(38, 18). + + +-- !query 39 +drop table decimals_test +-- !query 39 schema +struct<> +-- !query 39 output + diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/higher-order-functions.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/higher-order-functions.sql.out new file mode 100644 index 000000000000..e7dae6595a89 --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/results/ansi/higher-order-functions.sql.out @@ -0,0 +1,284 @@ +-- Automatically generated by SQLQueryTestSuite +-- Number of queries: 29 + + +-- !query 0 +create or replace temporary view nested as values + (1, array(32, 97), array(array(12, 99), array(123, 42), array(1))), + (2, array(77, -76), array(array(6, 96, 65), array(-1, -2))), + (3, array(12), array(array(17))) + as t(x, ys, zs) +-- !query 0 schema +struct<> +-- !query 0 output + + + +-- !query 1 +select upper(x -> x) as v +-- !query 1 schema +struct<> +-- !query 1 output +org.apache.spark.sql.AnalysisException +A lambda function should only be used in a higher order function. However, its class is org.apache.spark.sql.catalyst.expressions.Upper, which is not a higher order function.; line 1 pos 7 + + +-- !query 2 +select transform(zs, z -> z) as v from nested +-- !query 2 schema +struct>> +-- !query 2 output +[[12,99],[123,42],[1]] +[[17]] +[[6,96,65],[-1,-2]] + + +-- !query 3 +select transform(ys, y -> y * y) as v from nested +-- !query 3 schema +struct> +-- !query 3 output +[1024,9409] +[144] +[5929,5776] + + +-- !query 4 +select transform(ys, (y, i) -> y + i) as v from nested +-- !query 4 schema +struct> +-- !query 4 output +[12] +[32,98] +[77,-75] + + +-- !query 5 +select transform(zs, z -> concat(ys, z)) as v from nested +-- !query 5 schema +struct>> +-- !query 5 output +[[12,17]] +[[32,97,12,99],[32,97,123,42],[32,97,1]] +[[77,-76,6,96,65],[77,-76,-1,-2]] + + +-- !query 6 +select transform(ys, 0) as v from nested +-- !query 6 schema +struct> +-- !query 6 output +[0,0] +[0,0] +[0] + + +-- !query 7 +select transform(cast(null as array), x -> x + 1) as v +-- !query 7 schema +struct> +-- !query 7 output +NULL + + +-- !query 8 +select filter(ys, y -> y > 30) as v from nested +-- !query 8 schema +struct> +-- !query 8 output +[32,97] +[77] +[] + + +-- !query 9 +select filter(cast(null as array), y -> true) as v +-- !query 9 schema +struct> +-- !query 9 output +NULL + + +-- !query 10 +select transform(zs, z -> filter(z, zz -> zz > 50)) as v from nested +-- !query 10 schema +struct>> +-- !query 10 output +[[96,65],[]] +[[99],[123],[]] +[[]] + + +-- !query 11 +select aggregate(ys, 0, (y, a) -> y + a + x) as v from nested +-- !query 11 schema +struct +-- !query 11 output +131 +15 +5 + + +-- !query 12 +select aggregate(ys, (0 as sum, 0 as n), (acc, x) -> (acc.sum + x, acc.n + 1), acc -> acc.sum / acc.n) as v from nested +-- !query 12 schema +struct +-- !query 12 output +0.5 +12.0 +64.5 + + +-- !query 13 +select transform(zs, z -> aggregate(z, 1, (acc, val) -> acc * val * size(z))) as v from nested +-- !query 13 schema +struct> +-- !query 13 output +[1010880,8] +[17] +[4752,20664,1] + + +-- !query 14 +select aggregate(cast(null as array), 0, (a, y) -> a + y + 1, a -> a + 2) as v +-- !query 14 schema +struct +-- !query 14 output +NULL + + +-- !query 15 +select exists(ys, y -> y > 30) as v from nested +-- !query 15 schema +struct +-- !query 15 output +false +true +true + + +-- !query 16 +select exists(cast(null as array), y -> y > 30) as v +-- !query 16 schema +struct +-- !query 16 output +NULL + + +-- !query 17 +select zip_with(ys, zs, (a, b) -> a + size(b)) as v from nested +-- !query 17 schema +struct> +-- !query 17 output +[13] +[34,99,null] +[80,-74] + + +-- !query 18 +select zip_with(array('a', 'b', 'c'), array('d', 'e', 'f'), (x, y) -> concat(x, y)) as v +-- !query 18 schema +struct> +-- !query 18 output +["ad","be","cf"] + + +-- !query 19 +select zip_with(array('a'), array('d', null, 'f'), (x, y) -> coalesce(x, y)) as v +-- !query 19 schema +struct> +-- !query 19 output +["a",null,"f"] + + +-- !query 20 +create or replace temporary view nested as values + (1, map(1, 1, 2, 2, 3, 3)), + (2, map(4, 4, 5, 5, 6, 6)) + as t(x, ys) +-- !query 20 schema +struct<> +-- !query 20 output + + + +-- !query 21 +select transform_keys(ys, (k, v) -> k) as v from nested +-- !query 21 schema +struct> +-- !query 21 output +{1:1,2:2,3:3} +{4:4,5:5,6:6} + + +-- !query 22 +select transform_keys(ys, (k, v) -> k + 1) as v from nested +-- !query 22 schema +struct> +-- !query 22 output +{2:1,3:2,4:3} +{5:4,6:5,7:6} + + +-- !query 23 +select transform_keys(ys, (k, v) -> k + v) as v from nested +-- !query 23 schema +struct> +-- !query 23 output +{10:5,12:6,8:4} +{2:1,4:2,6:3} + + +-- !query 24 +select transform_values(ys, (k, v) -> v) as v from nested +-- !query 24 schema +struct> +-- !query 24 output +{1:1,2:2,3:3} +{4:4,5:5,6:6} + + +-- !query 25 +select transform_values(ys, (k, v) -> v + 1) as v from nested +-- !query 25 schema +struct> +-- !query 25 output +{1:2,2:3,3:4} +{4:5,5:6,6:7} + + +-- !query 26 +select transform_values(ys, (k, v) -> k + v) as v from nested +-- !query 26 schema +struct> +-- !query 26 output +{1:2,2:4,3:6} +{4:8,5:10,6:12} + + +-- !query 27 +select transform(ys, all -> all * all) as v from values (array(32, 97)) as t(ys) +-- !query 27 schema +struct<> +-- !query 27 output +org.apache.spark.sql.catalyst.parser.ParseException + +no viable alternative at input 'all'(line 1, pos 21) + +== SQL == +select transform(ys, all -> all * all) as v from values (array(32, 97)) as t(ys) +---------------------^^^ + + +-- !query 28 +select transform(ys, (all, i) -> all + i) as v from values (array(32, 97)) as t(ys) +-- !query 28 schema +struct<> +-- !query 28 output +org.apache.spark.sql.catalyst.parser.ParseException + +no viable alternative at input 'all'(line 1, pos 22) + +== SQL == +select transform(ys, (all, i) -> all + i) as v from values (array(32, 97)) as t(ys) +----------------------^^^ diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/interval.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/interval.sql.out index 0085cacf0d0b..a9c90ccc8093 100644 --- a/sql/core/src/test/resources/sql-tests/results/ansi/interval.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/ansi/interval.sql.out @@ -1,16 +1,8 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 35 +-- Number of queries: 36 -- !query 0 -SET spark.sql.ansi.enabled=true --- !query 0 schema -struct --- !query 0 output -spark.sql.ansi.enabled true - - --- !query 1 select '1' second, 2 seconds, @@ -24,35 +16,35 @@ select 2 months, '1' year, 2 years --- !query 1 schema +-- !query 0 schema struct<1 seconds:interval,2 seconds:interval,1 minutes:interval,2 minutes:interval,1 hours:interval,2 hours:interval,1 days:interval,2 days:interval,1 months:interval,2 months:interval,1 years:interval,2 years:interval> --- !query 1 output +-- !query 0 output 1 seconds 2 seconds 1 minutes 2 minutes 1 hours 2 hours 1 days 2 days 1 months 2 months 1 years 2 years --- !query 2 +-- !query 1 select interval '10-11' year to month, interval '10' year, interval '11' month --- !query 2 schema +-- !query 1 schema struct<10 years 11 months:interval,10 years:interval,11 months:interval> --- !query 2 output +-- !query 1 output 10 years 11 months 10 years 11 months --- !query 3 +-- !query 2 select '10-11' year to month, '10' year, '11' month --- !query 3 schema +-- !query 2 schema struct<10 years 11 months:interval,10 years:interval,11 months:interval> --- !query 3 output +-- !query 2 output 10 years 11 months 10 years 11 months --- !query 4 +-- !query 3 select interval '10 9:8:7.987654321' day to second, interval '10' day, @@ -60,13 +52,13 @@ select interval '12' minute, interval '13' second, interval '13.123456789' second --- !query 4 schema +-- !query 3 schema struct<10 days 9 hours 8 minutes 7.987654 seconds:interval,10 days:interval,11 hours:interval,12 minutes:interval,13 seconds:interval,13.123456 seconds:interval> --- !query 4 output +-- !query 3 output 10 days 9 hours 8 minutes 7.987654 seconds 10 days 11 hours 12 minutes 13 seconds 13.123456 seconds --- !query 5 +-- !query 4 select '10 9:8:7.987654321' day to second, '10' day, @@ -74,40 +66,40 @@ select '12' minute, '13' second, '13.123456789' second --- !query 5 schema +-- !query 4 schema struct<10 days 9 hours 8 minutes 7.987654 seconds:interval,10 days:interval,11 hours:interval,12 minutes:interval,13 seconds:interval,13.123456 seconds:interval> --- !query 5 output +-- !query 4 output 10 days 9 hours 8 minutes 7.987654 seconds 10 days 11 hours 12 minutes 13 seconds 13.123456 seconds --- !query 6 +-- !query 5 select map(1, interval 1 day, 2, interval 3 week) --- !query 6 schema +-- !query 5 schema struct> --- !query 6 output +-- !query 5 output {1:1 days,2:21 days} --- !query 7 +-- !query 6 select map(1, 1 day, 2, 3 week) --- !query 7 schema +-- !query 6 schema struct> --- !query 7 output +-- !query 6 output {1:1 days,2:21 days} --- !query 8 +-- !query 7 create temporary view interval_arithmetic as select CAST(dateval AS date), CAST(tsval AS timestamp) from values ('2012-01-01', '2012-01-01') as interval_arithmetic(dateval, tsval) --- !query 8 schema +-- !query 7 schema struct<> --- !query 8 output +-- !query 7 output --- !query 9 +-- !query 8 select dateval, dateval - interval '2-2' year to month, @@ -117,13 +109,13 @@ select - interval '2-2' year to month + dateval, interval '2-2' year to month + dateval from interval_arithmetic --- !query 9 schema +-- !query 8 schema struct --- !query 9 output +-- !query 8 output 2012-01-01 2009-11-01 2014-03-01 2014-03-01 2009-11-01 2009-11-01 2014-03-01 --- !query 10 +-- !query 9 select dateval, dateval - '2-2' year to month, @@ -133,13 +125,13 @@ select - '2-2' year to month + dateval, '2-2' year to month + dateval from interval_arithmetic --- !query 10 schema +-- !query 9 schema struct --- !query 10 output +-- !query 9 output 2012-01-01 2009-11-01 2014-03-01 2014-03-01 2009-11-01 2009-11-01 2014-03-01 --- !query 11 +-- !query 10 select tsval, tsval - interval '2-2' year to month, @@ -149,13 +141,13 @@ select - interval '2-2' year to month + tsval, interval '2-2' year to month + tsval from interval_arithmetic --- !query 11 schema +-- !query 10 schema struct --- !query 11 output +-- !query 10 output 2012-01-01 00:00:00 2009-11-01 00:00:00 2014-03-01 00:00:00 2014-03-01 00:00:00 2009-11-01 00:00:00 2009-11-01 00:00:00 2014-03-01 00:00:00 --- !query 12 +-- !query 11 select tsval, tsval - '2-2' year to month, @@ -165,35 +157,35 @@ select - '2-2' year to month + tsval, '2-2' year to month + tsval from interval_arithmetic --- !query 12 schema +-- !query 11 schema struct --- !query 12 output +-- !query 11 output 2012-01-01 00:00:00 2009-11-01 00:00:00 2014-03-01 00:00:00 2014-03-01 00:00:00 2009-11-01 00:00:00 2009-11-01 00:00:00 2014-03-01 00:00:00 --- !query 13 +-- !query 12 select interval '2-2' year to month + interval '3-3' year to month, interval '2-2' year to month - interval '3-3' year to month from interval_arithmetic --- !query 13 schema +-- !query 12 schema struct<(2 years 2 months + 3 years 3 months):interval,(2 years 2 months - 3 years 3 months):interval> --- !query 13 output +-- !query 12 output 5 years 5 months -1 years -1 months --- !query 14 +-- !query 13 select '2-2' year to month + '3-3' year to month, '2-2' year to month - '3-3' year to month from interval_arithmetic --- !query 14 schema +-- !query 13 schema struct<(2 years 2 months + 3 years 3 months):interval,(2 years 2 months - 3 years 3 months):interval> --- !query 14 output +-- !query 13 output 5 years 5 months -1 years -1 months --- !query 15 +-- !query 14 select dateval, dateval - interval '99 11:22:33.123456789' day to second, @@ -203,13 +195,13 @@ select -interval '99 11:22:33.123456789' day to second + dateval, interval '99 11:22:33.123456789' day to second + dateval from interval_arithmetic --- !query 15 schema +-- !query 14 schema struct --- !query 15 output +-- !query 14 output 2012-01-01 2011-09-23 2012-04-09 2012-04-09 2011-09-23 2011-09-23 2012-04-09 --- !query 16 +-- !query 15 select dateval, dateval - '99 11:22:33.123456789' day to second, @@ -219,13 +211,13 @@ select - '99 11:22:33.123456789' day to second + dateval, '99 11:22:33.123456789' day to second + dateval from interval_arithmetic --- !query 16 schema +-- !query 15 schema struct --- !query 16 output +-- !query 15 output 2012-01-01 2011-09-23 2012-04-09 2012-04-09 2011-09-23 2011-09-23 2012-04-09 --- !query 17 +-- !query 16 select tsval, tsval - interval '99 11:22:33.123456789' day to second, @@ -235,13 +227,13 @@ select -interval '99 11:22:33.123456789' day to second + tsval, interval '99 11:22:33.123456789' day to second + tsval from interval_arithmetic --- !query 17 schema +-- !query 16 schema struct --- !query 17 output +-- !query 16 output 2012-01-01 00:00:00 2011-09-23 12:37:26.876544 2012-04-09 11:22:33.123456 2012-04-09 11:22:33.123456 2011-09-23 12:37:26.876544 2011-09-23 12:37:26.876544 2012-04-09 11:22:33.123456 --- !query 18 +-- !query 17 select tsval, tsval - '99 11:22:33.123456789' day to second, @@ -251,47 +243,47 @@ select - '99 11:22:33.123456789' day to second + tsval, '99 11:22:33.123456789' day to second + tsval from interval_arithmetic --- !query 18 schema +-- !query 17 schema struct --- !query 18 output +-- !query 17 output 2012-01-01 00:00:00 2011-09-23 12:37:26.876544 2012-04-09 11:22:33.123456 2012-04-09 11:22:33.123456 2011-09-23 12:37:26.876544 2011-09-23 12:37:26.876544 2012-04-09 11:22:33.123456 --- !query 19 +-- !query 18 select interval '99 11:22:33.123456789' day to second + interval '10 9:8:7.123456789' day to second, interval '99 11:22:33.123456789' day to second - interval '10 9:8:7.123456789' day to second from interval_arithmetic --- !query 19 schema +-- !query 18 schema struct<(99 days 11 hours 22 minutes 33.123456 seconds + 10 days 9 hours 8 minutes 7.123456 seconds):interval,(99 days 11 hours 22 minutes 33.123456 seconds - 10 days 9 hours 8 minutes 7.123456 seconds):interval> --- !query 19 output +-- !query 18 output 109 days 20 hours 30 minutes 40.246912 seconds 89 days 2 hours 14 minutes 26 seconds --- !query 20 +-- !query 19 select '99 11:22:33.123456789' day to second + '10 9:8:7.123456789' day to second, '99 11:22:33.123456789' day to second - '10 9:8:7.123456789' day to second from interval_arithmetic --- !query 20 schema +-- !query 19 schema struct<(99 days 11 hours 22 minutes 33.123456 seconds + 10 days 9 hours 8 minutes 7.123456 seconds):interval,(99 days 11 hours 22 minutes 33.123456 seconds - 10 days 9 hours 8 minutes 7.123456 seconds):interval> --- !query 20 output +-- !query 19 output 109 days 20 hours 30 minutes 40.246912 seconds 89 days 2 hours 14 minutes 26 seconds --- !query 21 +-- !query 20 select 30 day --- !query 21 schema +-- !query 20 schema struct<30 days:interval> --- !query 21 output +-- !query 20 output 30 days --- !query 22 +-- !query 21 select 30 day day --- !query 22 schema +-- !query 21 schema struct<> --- !query 22 output +-- !query 21 output org.apache.spark.sql.catalyst.parser.ParseException no viable alternative at input 'day'(line 1, pos 14) @@ -301,11 +293,11 @@ select 30 day day --------------^^^ --- !query 23 +-- !query 22 select 30 day day day --- !query 23 schema +-- !query 22 schema struct<> --- !query 23 output +-- !query 22 output org.apache.spark.sql.catalyst.parser.ParseException no viable alternative at input 'day'(line 1, pos 14) @@ -315,19 +307,19 @@ select 30 day day day --------------^^^ --- !query 24 +-- !query 23 select date '2012-01-01' - 30 day --- !query 24 schema +-- !query 23 schema struct --- !query 24 output +-- !query 23 output 2011-12-02 --- !query 25 +-- !query 24 select date '2012-01-01' - 30 day day --- !query 25 schema +-- !query 24 schema struct<> --- !query 25 output +-- !query 24 output org.apache.spark.sql.catalyst.parser.ParseException no viable alternative at input 'day'(line 1, pos 34) @@ -337,11 +329,11 @@ select date '2012-01-01' - 30 day day ----------------------------------^^^ --- !query 26 +-- !query 25 select date '2012-01-01' - 30 day day day --- !query 26 schema +-- !query 25 schema struct<> --- !query 26 output +-- !query 25 output org.apache.spark.sql.catalyst.parser.ParseException no viable alternative at input 'day'(line 1, pos 34) @@ -351,27 +343,27 @@ select date '2012-01-01' - 30 day day day ----------------------------------^^^ --- !query 27 +-- !query 26 select date '2012-01-01' + '-30' day --- !query 27 schema +-- !query 26 schema struct --- !query 27 output +-- !query 26 output 2011-12-02 --- !query 28 +-- !query 27 select date '2012-01-01' + interval '-30' day --- !query 28 schema +-- !query 27 schema struct --- !query 28 output +-- !query 27 output 2011-12-02 --- !query 29 +-- !query 28 select date '2012-01-01' + interval (-30) day --- !query 29 schema +-- !query 28 schema struct<> --- !query 29 output +-- !query 28 output org.apache.spark.sql.catalyst.parser.ParseException no viable alternative at input 'day'(line 1, pos 42) @@ -381,11 +373,11 @@ select date '2012-01-01' + interval (-30) day ------------------------------------------^^^ --- !query 30 +-- !query 29 select date '2012-01-01' + (-30) day --- !query 30 schema +-- !query 29 schema struct<> --- !query 30 output +-- !query 29 output org.apache.spark.sql.catalyst.parser.ParseException no viable alternative at input 'day'(line 1, pos 33) @@ -395,19 +387,19 @@ select date '2012-01-01' + (-30) day ---------------------------------^^^ --- !query 31 +-- !query 30 create temporary view t as select * from values (1), (2) as t(a) --- !query 31 schema +-- !query 30 schema struct<> --- !query 31 output +-- !query 30 output --- !query 32 +-- !query 31 select date '2012-01-01' + interval (a + 1) day from t --- !query 32 schema +-- !query 31 schema struct<> --- !query 32 output +-- !query 31 output org.apache.spark.sql.catalyst.parser.ParseException no viable alternative at input 'day'(line 1, pos 44) @@ -417,11 +409,11 @@ select date '2012-01-01' + interval (a + 1) day from t --------------------------------------------^^^ --- !query 33 +-- !query 32 select date '2012-01-01' + (a + 1) day from t --- !query 33 schema +-- !query 32 schema struct<> --- !query 33 output +-- !query 32 output org.apache.spark.sql.catalyst.parser.ParseException no viable alternative at input 'day'(line 1, pos 35) @@ -431,9 +423,43 @@ select date '2012-01-01' + (a + 1) day from t -----------------------------------^^^ +-- !query 33 +select 1 year to month +-- !query 33 schema +struct<> +-- !query 33 output +org.apache.spark.sql.catalyst.parser.ParseException + +The value of from-to unit must be a string(line 1, pos 7) + +== SQL == +select 1 year to month +-------^^^ + + -- !query 34 -SET spark.sql.ansi.enabled=false +select '1' year to second -- !query 34 schema -struct +struct<> -- !query 34 output -spark.sql.ansi.enabled false +org.apache.spark.sql.catalyst.parser.ParseException + +Intervals FROM year TO second are not supported.(line 1, pos 7) + +== SQL == +select '1' year to second +-------^^^ + + +-- !query 35 +select 1 year '2-1' year to month +-- !query 35 schema +struct<> +-- !query 35 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 14) + +== SQL == +select 1 year '2-1' year to month +--------------^^^ diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out new file mode 100644 index 000000000000..32a2b7258755 --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out @@ -0,0 +1,794 @@ +-- Automatically generated by SQLQueryTestSuite +-- Number of queries: 79 + + +-- !query 0 +select null, Null, nUll +-- !query 0 schema +struct +-- !query 0 output +NULL NULL NULL + + +-- !query 1 +select true, tRue, false, fALse +-- !query 1 schema +struct +-- !query 1 output +true true false false + + +-- !query 2 +select 1Y +-- !query 2 schema +struct<1:tinyint> +-- !query 2 output +1 + + +-- !query 3 +select 127Y, -128Y +-- !query 3 schema +struct<127:tinyint,-128:tinyint> +-- !query 3 output +127 -128 + + +-- !query 4 +select 128Y +-- !query 4 schema +struct<> +-- !query 4 output +org.apache.spark.sql.catalyst.parser.ParseException + +Numeric literal 128 does not fit in range [-128, 127] for type tinyint(line 1, pos 7) + +== SQL == +select 128Y +-------^^^ + + +-- !query 5 +select 1S +-- !query 5 schema +struct<1:smallint> +-- !query 5 output +1 + + +-- !query 6 +select 32767S, -32768S +-- !query 6 schema +struct<32767:smallint,-32768:smallint> +-- !query 6 output +32767 -32768 + + +-- !query 7 +select 32768S +-- !query 7 schema +struct<> +-- !query 7 output +org.apache.spark.sql.catalyst.parser.ParseException + +Numeric literal 32768 does not fit in range [-32768, 32767] for type smallint(line 1, pos 7) + +== SQL == +select 32768S +-------^^^ + + +-- !query 8 +select 1L, 2147483648L +-- !query 8 schema +struct<1:bigint,2147483648:bigint> +-- !query 8 output +1 2147483648 + + +-- !query 9 +select 9223372036854775807L, -9223372036854775808L +-- !query 9 schema +struct<9223372036854775807:bigint,-9223372036854775808:bigint> +-- !query 9 output +9223372036854775807 -9223372036854775808 + + +-- !query 10 +select 9223372036854775808L +-- !query 10 schema +struct<> +-- !query 10 output +org.apache.spark.sql.catalyst.parser.ParseException + +Numeric literal 9223372036854775808 does not fit in range [-9223372036854775808, 9223372036854775807] for type bigint(line 1, pos 7) + +== SQL == +select 9223372036854775808L +-------^^^ + + +-- !query 11 +select 1, -1 +-- !query 11 schema +struct<1:int,-1:int> +-- !query 11 output +1 -1 + + +-- !query 12 +select 2147483647, -2147483648 +-- !query 12 schema +struct<2147483647:int,-2147483648:int> +-- !query 12 output +2147483647 -2147483648 + + +-- !query 13 +select 9223372036854775807, -9223372036854775808 +-- !query 13 schema +struct<9223372036854775807:bigint,-9223372036854775808:bigint> +-- !query 13 output +9223372036854775807 -9223372036854775808 + + +-- !query 14 +select 9223372036854775808, -9223372036854775809 +-- !query 14 schema +struct<9223372036854775808:decimal(19,0),-9223372036854775809:decimal(19,0)> +-- !query 14 output +9223372036854775808 -9223372036854775809 + + +-- !query 15 +select 1234567890123456789012345678901234567890 +-- !query 15 schema +struct<> +-- !query 15 output +org.apache.spark.sql.catalyst.parser.ParseException + +decimal can only support precision up to 38 +== SQL == +select 1234567890123456789012345678901234567890 + + +-- !query 16 +select 1234567890123456789012345678901234567890.0 +-- !query 16 schema +struct<> +-- !query 16 output +org.apache.spark.sql.catalyst.parser.ParseException + +decimal can only support precision up to 38 +== SQL == +select 1234567890123456789012345678901234567890.0 + + +-- !query 17 +select 1D, 1.2D, 1e10, 1.5e5, .10D, 0.10D, .1e5, .9e+2, 0.9e+2, 900e-1, 9.e+1 +-- !query 17 schema +struct<1.0:double,1.2:double,1E+10:decimal(1,-10),1.5E+5:decimal(2,-4),0.1:double,0.1:double,1E+4:decimal(1,-4),9E+1:decimal(1,-1),9E+1:decimal(1,-1),90.0:decimal(3,1),9E+1:decimal(1,-1)> +-- !query 17 output +1.0 1.2 10000000000 150000 0.1 0.1 10000 90 90 90 90 + + +-- !query 18 +select -1D, -1.2D, -1e10, -1.5e5, -.10D, -0.10D, -.1e5 +-- !query 18 schema +struct<-1.0:double,-1.2:double,-1E+10:decimal(1,-10),-1.5E+5:decimal(2,-4),-0.1:double,-0.1:double,-1E+4:decimal(1,-4)> +-- !query 18 output +-1.0 -1.2 -10000000000 -150000 -0.1 -0.1 -10000 + + +-- !query 19 +select .e3 +-- !query 19 schema +struct<> +-- !query 19 output +org.apache.spark.sql.catalyst.parser.ParseException + +no viable alternative at input 'select .'(line 1, pos 7) + +== SQL == +select .e3 +-------^^^ + + +-- !query 20 +select 1E309, -1E309 +-- !query 20 schema +struct<1E+309:decimal(1,-309),-1E+309:decimal(1,-309)> +-- !query 20 output +1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 + + +-- !query 21 +select 0.3, -0.8, .5, -.18, 0.1111, .1111 +-- !query 21 schema +struct<0.3:decimal(1,1),-0.8:decimal(1,1),0.5:decimal(1,1),-0.18:decimal(2,2),0.1111:decimal(4,4),0.1111:decimal(4,4)> +-- !query 21 output +0.3 -0.8 0.5 -0.18 0.1111 0.1111 + + +-- !query 22 +select 123456789012345678901234567890123456789e10d, 123456789012345678901234567890123456789.1e10d +-- !query 22 schema +struct<1.2345678901234568E48:double,1.2345678901234568E48:double> +-- !query 22 output +1.2345678901234568E48 1.2345678901234568E48 + + +-- !query 23 +select "Hello Peter!", 'hello lee!' +-- !query 23 schema +struct +-- !query 23 output +Hello Peter! hello lee! + + +-- !query 24 +select 'hello' 'world', 'hello' " " 'lee' +-- !query 24 schema +struct +-- !query 24 output +helloworld hello lee + + +-- !query 25 +select "hello 'peter'" +-- !query 25 schema +struct +-- !query 25 output +hello 'peter' + + +-- !query 26 +select 'pattern%', 'no-pattern\%', 'pattern\\%', 'pattern\\\%' +-- !query 26 schema +struct +-- !query 26 output +pattern% no-pattern\% pattern\% pattern\\% + + +-- !query 27 +select '\'', '"', '\n', '\r', '\t', 'Z' +-- !query 27 schema +struct<':string,":string, +:string, :string, :string,Z:string> +-- !query 27 output +' " + Z + + +-- !query 28 +select '\110\145\154\154\157\041' +-- !query 28 schema +struct +-- !query 28 output +Hello! + + +-- !query 29 +select '\u0057\u006F\u0072\u006C\u0064\u0020\u003A\u0029' +-- !query 29 schema +struct +-- !query 29 output +World :) + + +-- !query 30 +select dAte '2016-03-12' +-- !query 30 schema +struct +-- !query 30 output +2016-03-12 + + +-- !query 31 +select date 'mar 11 2016' +-- !query 31 schema +struct<> +-- !query 31 output +org.apache.spark.sql.catalyst.parser.ParseException + +Cannot parse the DATE value: mar 11 2016(line 1, pos 7) + +== SQL == +select date 'mar 11 2016' +-------^^^ + + +-- !query 32 +select tImEstAmp '2016-03-11 20:54:00.000' +-- !query 32 schema +struct +-- !query 32 output +2016-03-11 20:54:00 + + +-- !query 33 +select timestamp '2016-33-11 20:54:00.000' +-- !query 33 schema +struct<> +-- !query 33 output +org.apache.spark.sql.catalyst.parser.ParseException + +Cannot parse the TIMESTAMP value: 2016-33-11 20:54:00.000(line 1, pos 7) + +== SQL == +select timestamp '2016-33-11 20:54:00.000' +-------^^^ + + +-- !query 34 +select interval 13.123456789 seconds, interval -13.123456789 second +-- !query 34 schema +struct<13.123456 seconds:interval,-13.123456 seconds:interval> +-- !query 34 output +13.123456 seconds -13.123456 seconds + + +-- !query 35 +select interval 1 year 2 month 3 week 4 day 5 hour 6 minute 7 seconds 8 millisecond 9 microsecond +-- !query 35 schema +struct<1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds:interval> +-- !query 35 output +1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds + + +-- !query 36 +select interval '30' year '25' month '-100' day '40' hour '80' minute '299.889987299' second +-- !query 36 schema +struct<32 years 1 months -100 days 41 hours 24 minutes 59.889987 seconds:interval> +-- !query 36 output +32 years 1 months -100 days 41 hours 24 minutes 59.889987 seconds + + +-- !query 37 +select interval '0 0:0:0.1' day to second +-- !query 37 schema +struct<0.1 seconds:interval> +-- !query 37 output +0.1 seconds + + +-- !query 38 +select interval '10-9' year to month +-- !query 38 schema +struct<10 years 9 months:interval> +-- !query 38 output +10 years 9 months + + +-- !query 39 +select interval '20 15:40:32.99899999' day to hour +-- !query 39 schema +struct<20 days 15 hours:interval> +-- !query 39 output +20 days 15 hours + + +-- !query 40 +select interval '20 15:40:32.99899999' day to minute +-- !query 40 schema +struct<20 days 15 hours 40 minutes:interval> +-- !query 40 output +20 days 15 hours 40 minutes + + +-- !query 41 +select interval '20 15:40:32.99899999' day to second +-- !query 41 schema +struct<20 days 15 hours 40 minutes 32.998999 seconds:interval> +-- !query 41 output +20 days 15 hours 40 minutes 32.998999 seconds + + +-- !query 42 +select interval '15:40:32.99899999' hour to minute +-- !query 42 schema +struct<15 hours 40 minutes:interval> +-- !query 42 output +15 hours 40 minutes + + +-- !query 43 +select interval '15:40.99899999' hour to second +-- !query 43 schema +struct<15 minutes 40.998999 seconds:interval> +-- !query 43 output +15 minutes 40.998999 seconds + + +-- !query 44 +select interval '15:40' hour to second +-- !query 44 schema +struct<15 hours 40 minutes:interval> +-- !query 44 output +15 hours 40 minutes + + +-- !query 45 +select interval '15:40:32.99899999' hour to second +-- !query 45 schema +struct<15 hours 40 minutes 32.998999 seconds:interval> +-- !query 45 output +15 hours 40 minutes 32.998999 seconds + + +-- !query 46 +select interval '20 40:32.99899999' minute to second +-- !query 46 schema +struct<20 days 40 minutes 32.998999 seconds:interval> +-- !query 46 output +20 days 40 minutes 32.998999 seconds + + +-- !query 47 +select interval '40:32.99899999' minute to second +-- !query 47 schema +struct<40 minutes 32.998999 seconds:interval> +-- !query 47 output +40 minutes 32.998999 seconds + + +-- !query 48 +select interval '40:32' minute to second +-- !query 48 schema +struct<40 minutes 32 seconds:interval> +-- !query 48 output +40 minutes 32 seconds + + +-- !query 49 +select interval 10 nanoseconds +-- !query 49 schema +struct<> +-- !query 49 output +org.apache.spark.sql.catalyst.parser.ParseException + +no viable alternative at input '10 nanoseconds'(line 1, pos 19) + +== SQL == +select interval 10 nanoseconds +-------------------^^^ + + +-- !query 50 +select GEO '(10,-6)' +-- !query 50 schema +struct<> +-- !query 50 output +org.apache.spark.sql.catalyst.parser.ParseException + +Literals of type 'GEO' are currently not supported.(line 1, pos 7) + +== SQL == +select GEO '(10,-6)' +-------^^^ + + +-- !query 51 +select 90912830918230182310293801923652346786BD, 123.0E-28BD, 123.08BD +-- !query 51 schema +struct<90912830918230182310293801923652346786:decimal(38,0),1.230E-26:decimal(29,29),123.08:decimal(5,2)> +-- !query 51 output +90912830918230182310293801923652346786 0.0000000000000000000000000123 123.08 + + +-- !query 52 +select 1.20E-38BD +-- !query 52 schema +struct<> +-- !query 52 output +org.apache.spark.sql.catalyst.parser.ParseException + +decimal can only support precision up to 38(line 1, pos 7) + +== SQL == +select 1.20E-38BD +-------^^^ + + +-- !query 53 +select x'2379ACFe' +-- !query 53 schema +struct +-- !query 53 output +#y�� + + +-- !query 54 +select X'XuZ' +-- !query 54 schema +struct<> +-- !query 54 output +org.apache.spark.sql.catalyst.parser.ParseException + +contains illegal character for hexBinary: 0XuZ(line 1, pos 7) + +== SQL == +select X'XuZ' +-------^^^ + + +-- !query 55 +SELECT 3.14, -3.14, 3.14e8, 3.14e-8, -3.14e8, -3.14e-8, 3.14e+8, 3.14E8, 3.14E-8 +-- !query 55 schema +struct<3.14:decimal(3,2),-3.14:decimal(3,2),3.14E+8:decimal(3,-6),3.14E-8:decimal(10,10),-3.14E+8:decimal(3,-6),-3.14E-8:decimal(10,10),3.14E+8:decimal(3,-6),3.14E+8:decimal(3,-6),3.14E-8:decimal(10,10)> +-- !query 55 output +3.14 -3.14 314000000 0.0000000314 -314000000 -0.0000000314 314000000 314000000 0.0000000314 + + +-- !query 56 +select map(1, interval 1 day, 2, interval 3 week) +-- !query 56 schema +struct> +-- !query 56 output +{1:1 days,2:21 days} + + +-- !query 57 +select interval 'interval 3 year 1 hour' +-- !query 57 schema +struct<3 years 1 hours:interval> +-- !query 57 output +3 years 1 hours + + +-- !query 58 +select interval '3 year 1 hour' +-- !query 58 schema +struct<3 years 1 hours:interval> +-- !query 58 output +3 years 1 hours + + +-- !query 59 +select integer '7' +-- !query 59 schema +struct<7:int> +-- !query 59 output +7 + + +-- !query 60 +select integer'7' +-- !query 60 schema +struct<7:int> +-- !query 60 output +7 + + +-- !query 61 +select integer '2147483648' +-- !query 61 schema +struct<> +-- !query 61 output +org.apache.spark.sql.catalyst.parser.ParseException + +Cannot parse the Int value: 2147483648, java.lang.NumberFormatException: For input string: "2147483648"(line 1, pos 7) + +== SQL == +select integer '2147483648' +-------^^^ + + +-- !query 62 +select interval +-- !query 62 schema +struct<> +-- !query 62 output +org.apache.spark.sql.catalyst.parser.ParseException + +at least one time unit should be given for interval literal(line 1, pos 7) + +== SQL == +select interval +-------^^^ + + +-- !query 63 +select interval 1 fake_unit +-- !query 63 schema +struct<> +-- !query 63 output +org.apache.spark.sql.catalyst.parser.ParseException + +no viable alternative at input '1 fake_unit'(line 1, pos 18) + +== SQL == +select interval 1 fake_unit +------------------^^^ + + +-- !query 64 +select interval 1 year to month +-- !query 64 schema +struct<> +-- !query 64 output +org.apache.spark.sql.catalyst.parser.ParseException + +The value of from-to unit must be a string(line 1, pos 16) + +== SQL == +select interval 1 year to month +----------------^^^ + + +-- !query 65 +select interval '1' year to second +-- !query 65 schema +struct<> +-- !query 65 output +org.apache.spark.sql.catalyst.parser.ParseException + +Intervals FROM year TO second are not supported.(line 1, pos 16) + +== SQL == +select interval '1' year to second +----------------^^^ + + +-- !query 66 +select interval '10-9' year to month '2-1' year to month +-- !query 66 schema +struct<> +-- !query 66 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) + +== SQL == +select interval '10-9' year to month '2-1' year to month +-------------------------------------^^^ + + +-- !query 67 +select interval '10-9' year to month '12:11:10' hour to second +-- !query 67 schema +struct<> +-- !query 67 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) + +== SQL == +select interval '10-9' year to month '12:11:10' hour to second +-------------------------------------^^^ + + +-- !query 68 +select interval '1 15:11' day to minute '12:11:10' hour to second +-- !query 68 schema +struct<> +-- !query 68 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 40) + +== SQL == +select interval '1 15:11' day to minute '12:11:10' hour to second +----------------------------------------^^^ + + +-- !query 69 +select interval 1 year '2-1' year to month +-- !query 69 schema +struct<> +-- !query 69 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) + +== SQL == +select interval 1 year '2-1' year to month +-----------------------^^^ + + +-- !query 70 +select interval 1 year '12:11:10' hour to second +-- !query 70 schema +struct<> +-- !query 70 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) + +== SQL == +select interval 1 year '12:11:10' hour to second +-----------------------^^^ + + +-- !query 71 +select interval '10-9' year to month '1' year +-- !query 71 schema +struct<> +-- !query 71 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) + +== SQL == +select interval '10-9' year to month '1' year +-------------------------------------^^^ + + +-- !query 72 +select interval '12:11:10' hour to second '1' year +-- !query 72 schema +struct<> +-- !query 72 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 42) + +== SQL == +select interval '12:11:10' hour to second '1' year +------------------------------------------^^^ + + +-- !query 73 +select -integer '7' +-- !query 73 schema +struct<-7:int> +-- !query 73 output +-7 + + +-- !query 74 +select -date '1999-01-01' +-- !query 74 schema +struct<> +-- !query 74 output +org.apache.spark.sql.catalyst.parser.ParseException + +Literals of type '-DATE' are currently not supported.(line 1, pos 7) + +== SQL == +select -date '1999-01-01' +-------^^^ + + +-- !query 75 +select -timestamp '1999-01-01' +-- !query 75 schema +struct<> +-- !query 75 output +org.apache.spark.sql.catalyst.parser.ParseException + +Literals of type '-TIMESTAMP' are currently not supported.(line 1, pos 7) + +== SQL == +select -timestamp '1999-01-01' +-------^^^ + + +-- !query 76 +select -x'2379ACFe' +-- !query 76 schema +struct<> +-- !query 76 output +org.apache.spark.sql.catalyst.parser.ParseException + +Literals of type '-X' are currently not supported.(line 1, pos 7) + +== SQL == +select -x'2379ACFe' +-------^^^ + + +-- !query 77 +select +integer '7' +-- !query 77 schema +struct<7:int> +-- !query 77 output +7 + + +-- !query 78 +select +interval '1 second' +-- !query 78 schema +struct<1 seconds:interval> +-- !query 78 output +1 seconds diff --git a/sql/core/src/test/resources/sql-tests/results/decimalArithmeticOperations.sql.out b/sql/core/src/test/resources/sql-tests/results/decimalArithmeticOperations.sql.out index 00e139d90f48..cbf44548b3cc 100644 --- a/sql/core/src/test/resources/sql-tests/results/decimalArithmeticOperations.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/decimalArithmeticOperations.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 54 +-- Number of queries: 40 -- !query 0 @@ -328,131 +328,8 @@ NULL -- !query 39 -set spark.sql.ansi.enabled=true --- !query 39 schema -struct --- !query 39 output -spark.sql.ansi.enabled true - - --- !query 40 -select id, a*10, b/10 from decimals_test order by id --- !query 40 schema -struct --- !query 40 output -1 1000 99.9 -2 123451.23 1234.5123 -3 1.234567891011 123.41 -4 1234567891234567890 0.1123456789123456789 - - --- !query 41 -select 10.3 * 3.0 --- !query 41 schema -struct<(CAST(10.3 AS DECIMAL(3,1)) * CAST(3.0 AS DECIMAL(3,1))):decimal(6,2)> --- !query 41 output -30.9 - - --- !query 42 -select 10.3000 * 3.0 --- !query 42 schema -struct<(CAST(10.3000 AS DECIMAL(6,4)) * CAST(3.0 AS DECIMAL(6,4))):decimal(9,5)> --- !query 42 output -30.9 - - --- !query 43 -select 10.30000 * 30.0 --- !query 43 schema -struct<(CAST(10.30000 AS DECIMAL(7,5)) * CAST(30.0 AS DECIMAL(7,5))):decimal(11,6)> --- !query 43 output -309 - - --- !query 44 -select 10.300000000000000000 * 3.000000000000000000 --- !query 44 schema -struct<(CAST(10.300000000000000000 AS DECIMAL(20,18)) * CAST(3.000000000000000000 AS DECIMAL(20,18))):decimal(38,36)> --- !query 44 output -30.9 - - --- !query 45 -select 10.300000000000000000 * 3.0000000000000000000 --- !query 45 schema -struct<> --- !query 45 output -java.lang.ArithmeticException -Decimal(expanded,30.900000000000000000000000000000000000,38,36}) cannot be represented as Decimal(38, 37). - - --- !query 46 -select (5e36 + 0.1) + 5e36 --- !query 46 schema -struct<> --- !query 46 output -java.lang.ArithmeticException -Decimal(expanded,10000000000000000000000000000000000000.1,39,1}) cannot be represented as Decimal(38, 1). - - --- !query 47 -select (-4e36 - 0.1) - 7e36 --- !query 47 schema -struct<> --- !query 47 output -java.lang.ArithmeticException -Decimal(expanded,-11000000000000000000000000000000000000.1,39,1}) cannot be represented as Decimal(38, 1). - - --- !query 48 -select 12345678901234567890.0 * 12345678901234567890.0 --- !query 48 schema -struct<> --- !query 48 output -java.lang.ArithmeticException -Decimal(expanded,1.5241578753238836750190519987501905210E+38,38,-1}) cannot be represented as Decimal(38, 2). - - --- !query 49 -select 1e35 / 0.1 --- !query 49 schema -struct<> --- !query 49 output -java.lang.ArithmeticException -Decimal(expanded,1000000000000000000000000000000000000,37,0}) cannot be represented as Decimal(38, 3). - - --- !query 50 -select 123456789123456789.1234567890 * 1.123456789123456789 --- !query 50 schema -struct<> --- !query 50 output -java.lang.ArithmeticException -Decimal(expanded,138698367904130467.65432098851562262075,38,20}) cannot be represented as Decimal(38, 28). - - --- !query 51 -select 123456789123456789.1234567890 * 1.123456789123456789 --- !query 51 schema -struct<> --- !query 51 output -java.lang.ArithmeticException -Decimal(expanded,138698367904130467.65432098851562262075,38,20}) cannot be represented as Decimal(38, 28). - - --- !query 52 -select 12345678912345.123456789123 / 0.000000012345678 --- !query 52 schema -struct<> --- !query 52 output -java.lang.ArithmeticException -Decimal(expanded,1000000073899961059796.7258663315210392,38,16}) cannot be represented as Decimal(38, 18). - - --- !query 53 drop table decimals_test --- !query 53 schema +-- !query 39 schema struct<> --- !query 53 output +-- !query 39 output diff --git a/sql/core/src/test/resources/sql-tests/results/higher-order-functions.sql.out b/sql/core/src/test/resources/sql-tests/results/higher-order-functions.sql.out index 0b78076588c1..ca1d747874c5 100644 --- a/sql/core/src/test/resources/sql-tests/results/higher-order-functions.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/higher-order-functions.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 33 +-- Number of queries: 29 -- !query 0 @@ -270,47 +270,3 @@ select transform(ys, (all, i) -> all + i) as v from values (array(32, 97)) as t( struct> -- !query 28 output [32,98] - - --- !query 29 -set spark.sql.ansi.enabled=true --- !query 29 schema -struct --- !query 29 output -spark.sql.ansi.enabled true - - --- !query 30 -select transform(ys, all -> all * all) as v from values (array(32, 97)) as t(ys) --- !query 30 schema -struct<> --- !query 30 output -org.apache.spark.sql.catalyst.parser.ParseException - -no viable alternative at input 'all'(line 1, pos 21) - -== SQL == -select transform(ys, all -> all * all) as v from values (array(32, 97)) as t(ys) ----------------------^^^ - - --- !query 31 -select transform(ys, (all, i) -> all + i) as v from values (array(32, 97)) as t(ys) --- !query 31 schema -struct<> --- !query 31 output -org.apache.spark.sql.catalyst.parser.ParseException - -no viable alternative at input 'all'(line 1, pos 22) - -== SQL == -select transform(ys, (all, i) -> all + i) as v from values (array(32, 97)) as t(ys) -----------------------^^^ - - --- !query 32 -set spark.sql.ansi.enabled=false --- !query 32 schema -struct --- !query 32 output -spark.sql.ansi.enabled false diff --git a/sql/core/src/test/resources/sql-tests/results/literals.sql.out b/sql/core/src/test/resources/sql-tests/results/literals.sql.out index 8f641e51d823..32a2b7258755 100644 --- a/sql/core/src/test/resources/sql-tests/results/literals.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/literals.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 89 +-- Number of queries: 79 -- !query 0 @@ -729,148 +729,20 @@ select interval '12:11:10' hour to second '1' year -- !query 73 -SET spark.sql.ansi.enabled=true +select -integer '7' -- !query 73 schema -struct +struct<-7:int> -- !query 73 output -spark.sql.ansi.enabled true +-7 -- !query 74 -select interval +select -date '1999-01-01' -- !query 74 schema struct<> -- !query 74 output org.apache.spark.sql.catalyst.parser.ParseException -at least one time unit should be given for interval literal(line 1, pos 7) - -== SQL == -select interval --------^^^ - - --- !query 75 -select interval 1 fake_unit --- !query 75 schema -struct<> --- !query 75 output -org.apache.spark.sql.catalyst.parser.ParseException - -no viable alternative at input '1 fake_unit'(line 1, pos 18) - -== SQL == -select interval 1 fake_unit -------------------^^^ - - --- !query 76 -select interval 1 year to month --- !query 76 schema -struct<> --- !query 76 output -org.apache.spark.sql.catalyst.parser.ParseException - -The value of from-to unit must be a string(line 1, pos 16) - -== SQL == -select interval 1 year to month -----------------^^^ - - --- !query 77 -select 1 year to month --- !query 77 schema -struct<> --- !query 77 output -org.apache.spark.sql.catalyst.parser.ParseException - -The value of from-to unit must be a string(line 1, pos 7) - -== SQL == -select 1 year to month --------^^^ - - --- !query 78 -select interval '1' year to second --- !query 78 schema -struct<> --- !query 78 output -org.apache.spark.sql.catalyst.parser.ParseException - -Intervals FROM year TO second are not supported.(line 1, pos 16) - -== SQL == -select interval '1' year to second -----------------^^^ - - --- !query 79 -select '1' year to second --- !query 79 schema -struct<> --- !query 79 output -org.apache.spark.sql.catalyst.parser.ParseException - -Intervals FROM year TO second are not supported.(line 1, pos 7) - -== SQL == -select '1' year to second --------^^^ - - --- !query 80 -select interval 1 year '2-1' year to month --- !query 80 schema -struct<> --- !query 80 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) - -== SQL == -select interval 1 year '2-1' year to month ------------------------^^^ - - --- !query 81 -select 1 year '2-1' year to month --- !query 81 schema -struct<> --- !query 81 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 14) - -== SQL == -select 1 year '2-1' year to month ---------------^^^ - - --- !query 82 -SET spark.sql.ansi.enabled=false --- !query 82 schema -struct --- !query 82 output -spark.sql.ansi.enabled false - - --- !query 83 -select -integer '7' --- !query 83 schema -struct<-7:int> --- !query 83 output --7 - - --- !query 84 -select -date '1999-01-01' --- !query 84 schema -struct<> --- !query 84 output -org.apache.spark.sql.catalyst.parser.ParseException - Literals of type '-DATE' are currently not supported.(line 1, pos 7) == SQL == @@ -878,11 +750,11 @@ select -date '1999-01-01' -------^^^ --- !query 85 +-- !query 75 select -timestamp '1999-01-01' --- !query 85 schema +-- !query 75 schema struct<> --- !query 85 output +-- !query 75 output org.apache.spark.sql.catalyst.parser.ParseException Literals of type '-TIMESTAMP' are currently not supported.(line 1, pos 7) @@ -892,11 +764,11 @@ select -timestamp '1999-01-01' -------^^^ --- !query 86 +-- !query 76 select -x'2379ACFe' --- !query 86 schema +-- !query 76 schema struct<> --- !query 86 output +-- !query 76 output org.apache.spark.sql.catalyst.parser.ParseException Literals of type '-X' are currently not supported.(line 1, pos 7) @@ -906,17 +778,17 @@ select -x'2379ACFe' -------^^^ --- !query 87 +-- !query 77 select +integer '7' --- !query 87 schema +-- !query 77 schema struct<7:int> --- !query 87 output +-- !query 77 output 7 --- !query 88 +-- !query 78 select +interval '1 second' --- !query 88 schema +-- !query 78 schema struct<1 seconds:interval> --- !query 88 output +-- !query 78 output 1 seconds diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala index 58469fca8f3f..f5693f835f13 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala @@ -65,6 +65,7 @@ import org.apache.spark.tags.ExtendedSQLTest * 1. A list of SQL queries separated by semicolon. * 2. Lines starting with -- are treated as comments and ignored. * 3. Lines starting with --SET are used to run the file with the following set of configs. + * 4. Lines starting with --import are used to load queries from another test file. * * For example: * {{{ @@ -158,7 +159,7 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { ) // Create all the test cases. - listTestCases().foreach(createScalaTestCase) + listTestCases.foreach(createScalaTestCase) /** A single SQL query's output. */ protected case class QueryOutput(sql: String, schema: String, output: String) { @@ -186,6 +187,11 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { */ protected trait PgSQLTest + /** + * traits that indicate ANSI-related tests with the ANSI mode enabled. + */ + protected trait AnsiTest + protected trait UDFTest { val udf: TestUDF } @@ -212,6 +218,10 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { resultFile: String, udf: TestUDF) extends TestCase with UDFTest with PgSQLTest + /** An ANSI-related test case. */ + protected case class AnsiTestCase( + name: String, inputFile: String, resultFile: String) extends TestCase with AnsiTest + protected def createScalaTestCase(testCase: TestCase): Unit = { if (blackList.exists(t => testCase.name.toLowerCase(Locale.ROOT).contains(t.toLowerCase(Locale.ROOT)))) { @@ -255,9 +265,21 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { val (comments, code) = input.split("\n").partition(_.trim.startsWith("--")) + // If `--import` found, load code from another test case file, then insert them + // into the head in this test. + val importedTestCaseName = comments.filter(_.startsWith("--import ")).map(_.substring(9)) + val importedCode = importedTestCaseName.flatMap { testCaseName => + listTestCases.find(_.name == testCaseName).map { testCase => + val input = fileToString(new File(testCase.inputFile)) + val (_, code) = input.split("\n").partition(_.trim.startsWith("--")) + code + } + }.flatten + // List of SQL queries to run // note: this is not a robust way to split queries using semicolon, but works for now. - val queries = code.mkString("\n").split("(?<=[^\\\\]);").map(_.trim).filter(_ != "").toSeq + val queries = (importedCode ++ code).mkString("\n").split("(?<=[^\\\\]);") + .map(_.trim).filter(_ != "").toSeq // Fix misplacement when comment is at the end of the query. .map(_.split("\n").filterNot(_.startsWith("--")).mkString("\n")).map(_.trim).filter(_ != "") @@ -325,6 +347,8 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { localSparkSession.conf.set(SQLConf.CROSS_JOINS_ENABLED.key, true) localSparkSession.conf.set(SQLConf.ANSI_ENABLED.key, true) localSparkSession.conf.set(SQLConf.DIALECT.key, SQLConf.Dialect.POSTGRESQL.toString) + case _: AnsiTest => + localSparkSession.conf.set(SQLConf.ANSI_ENABLED.key, true) case _ => } @@ -457,7 +481,7 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { line.replaceAll("#\\d+", "#x") .replaceAll( s"Location.*$clsName/", - s"Location ${notIncludedMsg}/{warehouse_dir}/") + s"Location $notIncludedMsg/{warehouse_dir}/") .replaceAll("Created By.*", s"Created By $notIncludedMsg") .replaceAll("Created Time.*", s"Created Time $notIncludedMsg") .replaceAll("Last Access.*", s"Last Access $notIncludedMsg") @@ -465,7 +489,7 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { .replaceAll("\\*\\(\\d+\\) ", "*") // remove the WholeStageCodegen codegenStageIds } - protected def listTestCases(): Seq[TestCase] = { + protected lazy val listTestCases: Seq[TestCase] = { listFilesRecursively(new File(inputFilePath)).flatMap { file => val resultFile = file.getAbsolutePath.replace(inputFilePath, goldenFilePath) + ".out" val absPath = file.getAbsolutePath @@ -484,6 +508,8 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { } } else if (file.getAbsolutePath.startsWith(s"$inputFilePath${File.separator}postgreSQL")) { PgSQLTestCase(testCaseName, absPath, resultFile) :: Nil + } else if (file.getAbsolutePath.startsWith(s"$inputFilePath${File.separator}ansi")) { + AnsiTestCase(testCaseName, absPath, resultFile) :: Nil } else { RegularTestCase(testCaseName, absPath, resultFile) :: Nil } diff --git a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala index 04b1de00ccbf..bd774eb4af83 100644 --- a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala +++ b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala @@ -231,7 +231,7 @@ class ThriftServerQueryTestSuite extends SQLQueryTestSuite { } } - override def listTestCases(): Seq[TestCase] = { + override lazy val listTestCases: Seq[TestCase] = { listFilesRecursively(new File(inputFilePath)).flatMap { file => val resultFile = file.getAbsolutePath.replace(inputFilePath, goldenFilePath) + ".out" val absPath = file.getAbsolutePath From 615347e0505296b0b292ae3f523579993b8a87be Mon Sep 17 00:00:00 2001 From: Takeshi Yamamuro Date: Wed, 13 Nov 2019 22:02:33 +0900 Subject: [PATCH 2/4] Fix --- .../ansi/decimalArithmeticOperations.sql | 4 +- .../resources/sql-tests/inputs/interval.sql | 44 ++ .../resources/sql-tests/inputs/literals.sql | 41 -- .../sql-tests/results/ansi/literals.sql.out | 406 ++---------------- .../sql-tests/results/interval.sql.out | 330 +++++++++++++- .../sql-tests/results/literals.sql.out | 406 ++---------------- .../apache/spark/sql/SQLQueryTestSuite.scala | 1 - .../ThriftServerQueryTestSuite.scala | 6 +- 8 files changed, 457 insertions(+), 781 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/ansi/decimalArithmeticOperations.sql b/sql/core/src/test/resources/sql-tests/inputs/ansi/decimalArithmeticOperations.sql index 200de766e86a..70f0d89b98e5 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/ansi/decimalArithmeticOperations.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/ansi/decimalArithmeticOperations.sql @@ -1,2 +1,4 @@ --- throw an exception instead of returning NULL, according to SQL ANSI 2011 +-- SPARK-23179: SQL ANSI 2011 states that in case of overflow during arithmetic operations, +-- an exception should be thrown instead of returning NULL. +-- This is what most of the SQL DBs do (eg. SQLServer, DB2). --import decimalArithmeticOperations.sql diff --git a/sql/core/src/test/resources/sql-tests/inputs/interval.sql b/sql/core/src/test/resources/sql-tests/inputs/interval.sql index 226c13f961a8..45e06d78002e 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/interval.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/interval.sql @@ -88,3 +88,47 @@ select justify_interval(interval '1 month -59 day 25 hour'); select justify_days(interval '1 month 59 day -25 hour'); select justify_hours(interval '1 month 59 day -25 hour'); select justify_interval(interval '1 month 59 day -25 hour'); + +-- interval +select interval 13.123456789 seconds, interval -13.123456789 second; +select interval 1 year 2 month 3 week 4 day 5 hour 6 minute 7 seconds 8 millisecond 9 microsecond; +select interval '30' year '25' month '-100' day '40' hour '80' minute '299.889987299' second; +select interval '0 0:0:0.1' day to second; +select interval '10-9' year to month; +select interval '20 15:40:32.99899999' day to hour; +select interval '20 15:40:32.99899999' day to minute; +select interval '20 15:40:32.99899999' day to second; +select interval '15:40:32.99899999' hour to minute; +select interval '15:40.99899999' hour to second; +select interval '15:40' hour to second; +select interval '15:40:32.99899999' hour to second; +select interval '20 40:32.99899999' minute to second; +select interval '40:32.99899999' minute to second; +select interval '40:32' minute to second; + +-- ns is not supported +select interval 10 nanoseconds; + +-- map + interval test +select map(1, interval 1 day, 2, interval 3 week); + +-- typed interval expression +select interval 'interval 3 year 1 hour'; +select interval '3 year 1 hour'; + +-- malformed interval literal +select interval; +select interval 1 fake_unit; +select interval 1 year to month; +select interval '1' year to second; +select interval '10-9' year to month '2-1' year to month; +select interval '10-9' year to month '12:11:10' hour to second; +select interval '1 15:11' day to minute '12:11:10' hour to second; +select interval 1 year '2-1' year to month; +select interval 1 year '12:11:10' hour to second; +select interval '10-9' year to month '1' year; +select interval '12:11:10' hour to second '1' year; + +-- awareness of the negative sign before type +select +integer '7'; +select +interval '1 second'; diff --git a/sql/core/src/test/resources/sql-tests/inputs/literals.sql b/sql/core/src/test/resources/sql-tests/inputs/literals.sql index c19d3f7055cd..475d13df2971 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/literals.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/literals.sql @@ -82,25 +82,6 @@ select tImEstAmp '2016-03-11 20:54:00.000'; -- invalid timestamp select timestamp '2016-33-11 20:54:00.000'; --- interval -select interval 13.123456789 seconds, interval -13.123456789 second; -select interval 1 year 2 month 3 week 4 day 5 hour 6 minute 7 seconds 8 millisecond 9 microsecond; -select interval '30' year '25' month '-100' day '40' hour '80' minute '299.889987299' second; -select interval '0 0:0:0.1' day to second; -select interval '10-9' year to month; -select interval '20 15:40:32.99899999' day to hour; -select interval '20 15:40:32.99899999' day to minute; -select interval '20 15:40:32.99899999' day to second; -select interval '15:40:32.99899999' hour to minute; -select interval '15:40.99899999' hour to second; -select interval '15:40' hour to second; -select interval '15:40:32.99899999' hour to second; -select interval '20 40:32.99899999' minute to second; -select interval '40:32.99899999' minute to second; -select interval '40:32' minute to second; --- ns is not supported -select interval 10 nanoseconds; - -- unsupported data type select GEO '(10,-6)'; @@ -119,35 +100,13 @@ select X'XuZ'; -- Hive literal_double test. SELECT 3.14, -3.14, 3.14e8, 3.14e-8, -3.14e8, -3.14e-8, 3.14e+8, 3.14E8, 3.14E-8; --- map + interval test -select map(1, interval 1 day, 2, interval 3 week); - --- typed interval expression -select interval 'interval 3 year 1 hour'; -select interval '3 year 1 hour'; - -- typed integer expression select integer '7'; select integer'7'; select integer '2147483648'; --- malformed interval literal -select interval; -select interval 1 fake_unit; -select interval 1 year to month; -select interval '1' year to second; -select interval '10-9' year to month '2-1' year to month; -select interval '10-9' year to month '12:11:10' hour to second; -select interval '1 15:11' day to minute '12:11:10' hour to second; -select interval 1 year '2-1' year to month; -select interval 1 year '12:11:10' hour to second; -select interval '10-9' year to month '1' year; -select interval '12:11:10' hour to second '1' year; - -- awareness of the negative sign before type select -integer '7'; select -date '1999-01-01'; select -timestamp '1999-01-01'; select -x'2379ACFe'; -select +integer '7'; -select +interval '1 second'; \ No newline at end of file diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out index 32a2b7258755..c1d08e4aa460 100644 --- a/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 79 +-- Number of queries: 47 -- !query 0 @@ -321,144 +321,10 @@ select timestamp '2016-33-11 20:54:00.000' -- !query 34 -select interval 13.123456789 seconds, interval -13.123456789 second --- !query 34 schema -struct<13.123456 seconds:interval,-13.123456 seconds:interval> --- !query 34 output -13.123456 seconds -13.123456 seconds - - --- !query 35 -select interval 1 year 2 month 3 week 4 day 5 hour 6 minute 7 seconds 8 millisecond 9 microsecond --- !query 35 schema -struct<1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds:interval> --- !query 35 output -1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds - - --- !query 36 -select interval '30' year '25' month '-100' day '40' hour '80' minute '299.889987299' second --- !query 36 schema -struct<32 years 1 months -100 days 41 hours 24 minutes 59.889987 seconds:interval> --- !query 36 output -32 years 1 months -100 days 41 hours 24 minutes 59.889987 seconds - - --- !query 37 -select interval '0 0:0:0.1' day to second --- !query 37 schema -struct<0.1 seconds:interval> --- !query 37 output -0.1 seconds - - --- !query 38 -select interval '10-9' year to month --- !query 38 schema -struct<10 years 9 months:interval> --- !query 38 output -10 years 9 months - - --- !query 39 -select interval '20 15:40:32.99899999' day to hour --- !query 39 schema -struct<20 days 15 hours:interval> --- !query 39 output -20 days 15 hours - - --- !query 40 -select interval '20 15:40:32.99899999' day to minute --- !query 40 schema -struct<20 days 15 hours 40 minutes:interval> --- !query 40 output -20 days 15 hours 40 minutes - - --- !query 41 -select interval '20 15:40:32.99899999' day to second --- !query 41 schema -struct<20 days 15 hours 40 minutes 32.998999 seconds:interval> --- !query 41 output -20 days 15 hours 40 minutes 32.998999 seconds - - --- !query 42 -select interval '15:40:32.99899999' hour to minute --- !query 42 schema -struct<15 hours 40 minutes:interval> --- !query 42 output -15 hours 40 minutes - - --- !query 43 -select interval '15:40.99899999' hour to second --- !query 43 schema -struct<15 minutes 40.998999 seconds:interval> --- !query 43 output -15 minutes 40.998999 seconds - - --- !query 44 -select interval '15:40' hour to second --- !query 44 schema -struct<15 hours 40 minutes:interval> --- !query 44 output -15 hours 40 minutes - - --- !query 45 -select interval '15:40:32.99899999' hour to second --- !query 45 schema -struct<15 hours 40 minutes 32.998999 seconds:interval> --- !query 45 output -15 hours 40 minutes 32.998999 seconds - - --- !query 46 -select interval '20 40:32.99899999' minute to second --- !query 46 schema -struct<20 days 40 minutes 32.998999 seconds:interval> --- !query 46 output -20 days 40 minutes 32.998999 seconds - - --- !query 47 -select interval '40:32.99899999' minute to second --- !query 47 schema -struct<40 minutes 32.998999 seconds:interval> --- !query 47 output -40 minutes 32.998999 seconds - - --- !query 48 -select interval '40:32' minute to second --- !query 48 schema -struct<40 minutes 32 seconds:interval> --- !query 48 output -40 minutes 32 seconds - - --- !query 49 -select interval 10 nanoseconds --- !query 49 schema -struct<> --- !query 49 output -org.apache.spark.sql.catalyst.parser.ParseException - -no viable alternative at input '10 nanoseconds'(line 1, pos 19) - -== SQL == -select interval 10 nanoseconds --------------------^^^ - - --- !query 50 select GEO '(10,-6)' --- !query 50 schema +-- !query 34 schema struct<> --- !query 50 output +-- !query 34 output org.apache.spark.sql.catalyst.parser.ParseException Literals of type 'GEO' are currently not supported.(line 1, pos 7) @@ -468,19 +334,19 @@ select GEO '(10,-6)' -------^^^ --- !query 51 +-- !query 35 select 90912830918230182310293801923652346786BD, 123.0E-28BD, 123.08BD --- !query 51 schema +-- !query 35 schema struct<90912830918230182310293801923652346786:decimal(38,0),1.230E-26:decimal(29,29),123.08:decimal(5,2)> --- !query 51 output +-- !query 35 output 90912830918230182310293801923652346786 0.0000000000000000000000000123 123.08 --- !query 52 +-- !query 36 select 1.20E-38BD --- !query 52 schema +-- !query 36 schema struct<> --- !query 52 output +-- !query 36 output org.apache.spark.sql.catalyst.parser.ParseException decimal can only support precision up to 38(line 1, pos 7) @@ -490,19 +356,19 @@ select 1.20E-38BD -------^^^ --- !query 53 +-- !query 37 select x'2379ACFe' --- !query 53 schema +-- !query 37 schema struct --- !query 53 output +-- !query 37 output #y�� --- !query 54 +-- !query 38 select X'XuZ' --- !query 54 schema +-- !query 38 schema struct<> --- !query 54 output +-- !query 38 output org.apache.spark.sql.catalyst.parser.ParseException contains illegal character for hexBinary: 0XuZ(line 1, pos 7) @@ -512,59 +378,35 @@ select X'XuZ' -------^^^ --- !query 55 +-- !query 39 SELECT 3.14, -3.14, 3.14e8, 3.14e-8, -3.14e8, -3.14e-8, 3.14e+8, 3.14E8, 3.14E-8 --- !query 55 schema +-- !query 39 schema struct<3.14:decimal(3,2),-3.14:decimal(3,2),3.14E+8:decimal(3,-6),3.14E-8:decimal(10,10),-3.14E+8:decimal(3,-6),-3.14E-8:decimal(10,10),3.14E+8:decimal(3,-6),3.14E+8:decimal(3,-6),3.14E-8:decimal(10,10)> --- !query 55 output +-- !query 39 output 3.14 -3.14 314000000 0.0000000314 -314000000 -0.0000000314 314000000 314000000 0.0000000314 --- !query 56 -select map(1, interval 1 day, 2, interval 3 week) --- !query 56 schema -struct> --- !query 56 output -{1:1 days,2:21 days} - - --- !query 57 -select interval 'interval 3 year 1 hour' --- !query 57 schema -struct<3 years 1 hours:interval> --- !query 57 output -3 years 1 hours - - --- !query 58 -select interval '3 year 1 hour' --- !query 58 schema -struct<3 years 1 hours:interval> --- !query 58 output -3 years 1 hours - - --- !query 59 +-- !query 40 select integer '7' --- !query 59 schema +-- !query 40 schema struct<7:int> --- !query 59 output +-- !query 40 output 7 --- !query 60 +-- !query 41 select integer'7' --- !query 60 schema +-- !query 41 schema struct<7:int> --- !query 60 output +-- !query 41 output 7 --- !query 61 +-- !query 42 select integer '2147483648' --- !query 61 schema +-- !query 42 schema struct<> --- !query 61 output +-- !query 42 output org.apache.spark.sql.catalyst.parser.ParseException Cannot parse the Int value: 2147483648, java.lang.NumberFormatException: For input string: "2147483648"(line 1, pos 7) @@ -574,173 +416,19 @@ select integer '2147483648' -------^^^ --- !query 62 -select interval --- !query 62 schema -struct<> --- !query 62 output -org.apache.spark.sql.catalyst.parser.ParseException - -at least one time unit should be given for interval literal(line 1, pos 7) - -== SQL == -select interval --------^^^ - - --- !query 63 -select interval 1 fake_unit --- !query 63 schema -struct<> --- !query 63 output -org.apache.spark.sql.catalyst.parser.ParseException - -no viable alternative at input '1 fake_unit'(line 1, pos 18) - -== SQL == -select interval 1 fake_unit -------------------^^^ - - --- !query 64 -select interval 1 year to month --- !query 64 schema -struct<> --- !query 64 output -org.apache.spark.sql.catalyst.parser.ParseException - -The value of from-to unit must be a string(line 1, pos 16) - -== SQL == -select interval 1 year to month -----------------^^^ - - --- !query 65 -select interval '1' year to second --- !query 65 schema -struct<> --- !query 65 output -org.apache.spark.sql.catalyst.parser.ParseException - -Intervals FROM year TO second are not supported.(line 1, pos 16) - -== SQL == -select interval '1' year to second -----------------^^^ - - --- !query 66 -select interval '10-9' year to month '2-1' year to month --- !query 66 schema -struct<> --- !query 66 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) - -== SQL == -select interval '10-9' year to month '2-1' year to month --------------------------------------^^^ - - --- !query 67 -select interval '10-9' year to month '12:11:10' hour to second --- !query 67 schema -struct<> --- !query 67 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) - -== SQL == -select interval '10-9' year to month '12:11:10' hour to second --------------------------------------^^^ - - --- !query 68 -select interval '1 15:11' day to minute '12:11:10' hour to second --- !query 68 schema -struct<> --- !query 68 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 40) - -== SQL == -select interval '1 15:11' day to minute '12:11:10' hour to second -----------------------------------------^^^ - - --- !query 69 -select interval 1 year '2-1' year to month --- !query 69 schema -struct<> --- !query 69 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) - -== SQL == -select interval 1 year '2-1' year to month ------------------------^^^ - - --- !query 70 -select interval 1 year '12:11:10' hour to second --- !query 70 schema -struct<> --- !query 70 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) - -== SQL == -select interval 1 year '12:11:10' hour to second ------------------------^^^ - - --- !query 71 -select interval '10-9' year to month '1' year --- !query 71 schema -struct<> --- !query 71 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) - -== SQL == -select interval '10-9' year to month '1' year --------------------------------------^^^ - - --- !query 72 -select interval '12:11:10' hour to second '1' year --- !query 72 schema -struct<> --- !query 72 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 42) - -== SQL == -select interval '12:11:10' hour to second '1' year -------------------------------------------^^^ - - --- !query 73 +-- !query 43 select -integer '7' --- !query 73 schema +-- !query 43 schema struct<-7:int> --- !query 73 output +-- !query 43 output -7 --- !query 74 +-- !query 44 select -date '1999-01-01' --- !query 74 schema +-- !query 44 schema struct<> --- !query 74 output +-- !query 44 output org.apache.spark.sql.catalyst.parser.ParseException Literals of type '-DATE' are currently not supported.(line 1, pos 7) @@ -750,11 +438,11 @@ select -date '1999-01-01' -------^^^ --- !query 75 +-- !query 45 select -timestamp '1999-01-01' --- !query 75 schema +-- !query 45 schema struct<> --- !query 75 output +-- !query 45 output org.apache.spark.sql.catalyst.parser.ParseException Literals of type '-TIMESTAMP' are currently not supported.(line 1, pos 7) @@ -764,11 +452,11 @@ select -timestamp '1999-01-01' -------^^^ --- !query 76 +-- !query 46 select -x'2379ACFe' --- !query 76 schema +-- !query 46 schema struct<> --- !query 76 output +-- !query 46 output org.apache.spark.sql.catalyst.parser.ParseException Literals of type '-X' are currently not supported.(line 1, pos 7) @@ -776,19 +464,3 @@ Literals of type '-X' are currently not supported.(line 1, pos 7) == SQL == select -x'2379ACFe' -------^^^ - - --- !query 77 -select +integer '7' --- !query 77 schema -struct<7:int> --- !query 77 output -7 - - --- !query 78 -select +interval '1 second' --- !query 78 schema -struct<1 seconds:interval> --- !query 78 output -1 seconds diff --git a/sql/core/src/test/resources/sql-tests/results/interval.sql.out b/sql/core/src/test/resources/sql-tests/results/interval.sql.out index 372f7d9e0b96..124ae52d9633 100644 --- a/sql/core/src/test/resources/sql-tests/results/interval.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/interval.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 57 +-- Number of queries: 89 -- !query 0 @@ -458,3 +458,331 @@ select justify_interval(interval '1 month 59 day -25 hour') struct -- !query 56 output 2 months 27 days 23 hours + + +-- !query 57 +select interval 13.123456789 seconds, interval -13.123456789 second +-- !query 57 schema +struct<13.123456 seconds:interval,-13.123456 seconds:interval> +-- !query 57 output +13.123456 seconds -13.123456 seconds + + +-- !query 58 +select interval 1 year 2 month 3 week 4 day 5 hour 6 minute 7 seconds 8 millisecond 9 microsecond +-- !query 58 schema +struct<1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds:interval> +-- !query 58 output +1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds + + +-- !query 59 +select interval '30' year '25' month '-100' day '40' hour '80' minute '299.889987299' second +-- !query 59 schema +struct<32 years 1 months -100 days 41 hours 24 minutes 59.889987 seconds:interval> +-- !query 59 output +32 years 1 months -100 days 41 hours 24 minutes 59.889987 seconds + + +-- !query 60 +select interval '0 0:0:0.1' day to second +-- !query 60 schema +struct<0.1 seconds:interval> +-- !query 60 output +0.1 seconds + + +-- !query 61 +select interval '10-9' year to month +-- !query 61 schema +struct<10 years 9 months:interval> +-- !query 61 output +10 years 9 months + + +-- !query 62 +select interval '20 15:40:32.99899999' day to hour +-- !query 62 schema +struct<20 days 15 hours:interval> +-- !query 62 output +20 days 15 hours + + +-- !query 63 +select interval '20 15:40:32.99899999' day to minute +-- !query 63 schema +struct<20 days 15 hours 40 minutes:interval> +-- !query 63 output +20 days 15 hours 40 minutes + + +-- !query 64 +select interval '20 15:40:32.99899999' day to second +-- !query 64 schema +struct<20 days 15 hours 40 minutes 32.998999 seconds:interval> +-- !query 64 output +20 days 15 hours 40 minutes 32.998999 seconds + + +-- !query 65 +select interval '15:40:32.99899999' hour to minute +-- !query 65 schema +struct<15 hours 40 minutes:interval> +-- !query 65 output +15 hours 40 minutes + + +-- !query 66 +select interval '15:40.99899999' hour to second +-- !query 66 schema +struct<15 minutes 40.998999 seconds:interval> +-- !query 66 output +15 minutes 40.998999 seconds + + +-- !query 67 +select interval '15:40' hour to second +-- !query 67 schema +struct<15 hours 40 minutes:interval> +-- !query 67 output +15 hours 40 minutes + + +-- !query 68 +select interval '15:40:32.99899999' hour to second +-- !query 68 schema +struct<15 hours 40 minutes 32.998999 seconds:interval> +-- !query 68 output +15 hours 40 minutes 32.998999 seconds + + +-- !query 69 +select interval '20 40:32.99899999' minute to second +-- !query 69 schema +struct<20 days 40 minutes 32.998999 seconds:interval> +-- !query 69 output +20 days 40 minutes 32.998999 seconds + + +-- !query 70 +select interval '40:32.99899999' minute to second +-- !query 70 schema +struct<40 minutes 32.998999 seconds:interval> +-- !query 70 output +40 minutes 32.998999 seconds + + +-- !query 71 +select interval '40:32' minute to second +-- !query 71 schema +struct<40 minutes 32 seconds:interval> +-- !query 71 output +40 minutes 32 seconds + + +-- !query 72 +select interval 10 nanoseconds +-- !query 72 schema +struct<> +-- !query 72 output +org.apache.spark.sql.catalyst.parser.ParseException + +no viable alternative at input '10 nanoseconds'(line 1, pos 19) + +== SQL == +select interval 10 nanoseconds +-------------------^^^ + + +-- !query 73 +select map(1, interval 1 day, 2, interval 3 week) +-- !query 73 schema +struct> +-- !query 73 output +{1:1 days,2:21 days} + + +-- !query 74 +select interval 'interval 3 year 1 hour' +-- !query 74 schema +struct<3 years 1 hours:interval> +-- !query 74 output +3 years 1 hours + + +-- !query 75 +select interval '3 year 1 hour' +-- !query 75 schema +struct<3 years 1 hours:interval> +-- !query 75 output +3 years 1 hours + + +-- !query 76 +select interval +-- !query 76 schema +struct<> +-- !query 76 output +org.apache.spark.sql.catalyst.parser.ParseException + +at least one time unit should be given for interval literal(line 1, pos 7) + +== SQL == +select interval +-------^^^ + + +-- !query 77 +select interval 1 fake_unit +-- !query 77 schema +struct<> +-- !query 77 output +org.apache.spark.sql.catalyst.parser.ParseException + +no viable alternative at input '1 fake_unit'(line 1, pos 18) + +== SQL == +select interval 1 fake_unit +------------------^^^ + + +-- !query 78 +select interval 1 year to month +-- !query 78 schema +struct<> +-- !query 78 output +org.apache.spark.sql.catalyst.parser.ParseException + +The value of from-to unit must be a string(line 1, pos 16) + +== SQL == +select interval 1 year to month +----------------^^^ + + +-- !query 79 +select interval '1' year to second +-- !query 79 schema +struct<> +-- !query 79 output +org.apache.spark.sql.catalyst.parser.ParseException + +Intervals FROM year TO second are not supported.(line 1, pos 16) + +== SQL == +select interval '1' year to second +----------------^^^ + + +-- !query 80 +select interval '10-9' year to month '2-1' year to month +-- !query 80 schema +struct<> +-- !query 80 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) + +== SQL == +select interval '10-9' year to month '2-1' year to month +-------------------------------------^^^ + + +-- !query 81 +select interval '10-9' year to month '12:11:10' hour to second +-- !query 81 schema +struct<> +-- !query 81 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) + +== SQL == +select interval '10-9' year to month '12:11:10' hour to second +-------------------------------------^^^ + + +-- !query 82 +select interval '1 15:11' day to minute '12:11:10' hour to second +-- !query 82 schema +struct<> +-- !query 82 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 40) + +== SQL == +select interval '1 15:11' day to minute '12:11:10' hour to second +----------------------------------------^^^ + + +-- !query 83 +select interval 1 year '2-1' year to month +-- !query 83 schema +struct<> +-- !query 83 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) + +== SQL == +select interval 1 year '2-1' year to month +-----------------------^^^ + + +-- !query 84 +select interval 1 year '12:11:10' hour to second +-- !query 84 schema +struct<> +-- !query 84 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) + +== SQL == +select interval 1 year '12:11:10' hour to second +-----------------------^^^ + + +-- !query 85 +select interval '10-9' year to month '1' year +-- !query 85 schema +struct<> +-- !query 85 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) + +== SQL == +select interval '10-9' year to month '1' year +-------------------------------------^^^ + + +-- !query 86 +select interval '12:11:10' hour to second '1' year +-- !query 86 schema +struct<> +-- !query 86 output +org.apache.spark.sql.catalyst.parser.ParseException + +Can only have a single from-to unit in the interval literal syntax(line 1, pos 42) + +== SQL == +select interval '12:11:10' hour to second '1' year +------------------------------------------^^^ + + +-- !query 87 +select +integer '7' +-- !query 87 schema +struct<7:int> +-- !query 87 output +7 + + +-- !query 88 +select +interval '1 second' +-- !query 88 schema +struct<1 seconds:interval> +-- !query 88 output +1 seconds diff --git a/sql/core/src/test/resources/sql-tests/results/literals.sql.out b/sql/core/src/test/resources/sql-tests/results/literals.sql.out index 32a2b7258755..c1d08e4aa460 100644 --- a/sql/core/src/test/resources/sql-tests/results/literals.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/literals.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 79 +-- Number of queries: 47 -- !query 0 @@ -321,144 +321,10 @@ select timestamp '2016-33-11 20:54:00.000' -- !query 34 -select interval 13.123456789 seconds, interval -13.123456789 second --- !query 34 schema -struct<13.123456 seconds:interval,-13.123456 seconds:interval> --- !query 34 output -13.123456 seconds -13.123456 seconds - - --- !query 35 -select interval 1 year 2 month 3 week 4 day 5 hour 6 minute 7 seconds 8 millisecond 9 microsecond --- !query 35 schema -struct<1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds:interval> --- !query 35 output -1 years 2 months 25 days 5 hours 6 minutes 7.008009 seconds - - --- !query 36 -select interval '30' year '25' month '-100' day '40' hour '80' minute '299.889987299' second --- !query 36 schema -struct<32 years 1 months -100 days 41 hours 24 minutes 59.889987 seconds:interval> --- !query 36 output -32 years 1 months -100 days 41 hours 24 minutes 59.889987 seconds - - --- !query 37 -select interval '0 0:0:0.1' day to second --- !query 37 schema -struct<0.1 seconds:interval> --- !query 37 output -0.1 seconds - - --- !query 38 -select interval '10-9' year to month --- !query 38 schema -struct<10 years 9 months:interval> --- !query 38 output -10 years 9 months - - --- !query 39 -select interval '20 15:40:32.99899999' day to hour --- !query 39 schema -struct<20 days 15 hours:interval> --- !query 39 output -20 days 15 hours - - --- !query 40 -select interval '20 15:40:32.99899999' day to minute --- !query 40 schema -struct<20 days 15 hours 40 minutes:interval> --- !query 40 output -20 days 15 hours 40 minutes - - --- !query 41 -select interval '20 15:40:32.99899999' day to second --- !query 41 schema -struct<20 days 15 hours 40 minutes 32.998999 seconds:interval> --- !query 41 output -20 days 15 hours 40 minutes 32.998999 seconds - - --- !query 42 -select interval '15:40:32.99899999' hour to minute --- !query 42 schema -struct<15 hours 40 minutes:interval> --- !query 42 output -15 hours 40 minutes - - --- !query 43 -select interval '15:40.99899999' hour to second --- !query 43 schema -struct<15 minutes 40.998999 seconds:interval> --- !query 43 output -15 minutes 40.998999 seconds - - --- !query 44 -select interval '15:40' hour to second --- !query 44 schema -struct<15 hours 40 minutes:interval> --- !query 44 output -15 hours 40 minutes - - --- !query 45 -select interval '15:40:32.99899999' hour to second --- !query 45 schema -struct<15 hours 40 minutes 32.998999 seconds:interval> --- !query 45 output -15 hours 40 minutes 32.998999 seconds - - --- !query 46 -select interval '20 40:32.99899999' minute to second --- !query 46 schema -struct<20 days 40 minutes 32.998999 seconds:interval> --- !query 46 output -20 days 40 minutes 32.998999 seconds - - --- !query 47 -select interval '40:32.99899999' minute to second --- !query 47 schema -struct<40 minutes 32.998999 seconds:interval> --- !query 47 output -40 minutes 32.998999 seconds - - --- !query 48 -select interval '40:32' minute to second --- !query 48 schema -struct<40 minutes 32 seconds:interval> --- !query 48 output -40 minutes 32 seconds - - --- !query 49 -select interval 10 nanoseconds --- !query 49 schema -struct<> --- !query 49 output -org.apache.spark.sql.catalyst.parser.ParseException - -no viable alternative at input '10 nanoseconds'(line 1, pos 19) - -== SQL == -select interval 10 nanoseconds --------------------^^^ - - --- !query 50 select GEO '(10,-6)' --- !query 50 schema +-- !query 34 schema struct<> --- !query 50 output +-- !query 34 output org.apache.spark.sql.catalyst.parser.ParseException Literals of type 'GEO' are currently not supported.(line 1, pos 7) @@ -468,19 +334,19 @@ select GEO '(10,-6)' -------^^^ --- !query 51 +-- !query 35 select 90912830918230182310293801923652346786BD, 123.0E-28BD, 123.08BD --- !query 51 schema +-- !query 35 schema struct<90912830918230182310293801923652346786:decimal(38,0),1.230E-26:decimal(29,29),123.08:decimal(5,2)> --- !query 51 output +-- !query 35 output 90912830918230182310293801923652346786 0.0000000000000000000000000123 123.08 --- !query 52 +-- !query 36 select 1.20E-38BD --- !query 52 schema +-- !query 36 schema struct<> --- !query 52 output +-- !query 36 output org.apache.spark.sql.catalyst.parser.ParseException decimal can only support precision up to 38(line 1, pos 7) @@ -490,19 +356,19 @@ select 1.20E-38BD -------^^^ --- !query 53 +-- !query 37 select x'2379ACFe' --- !query 53 schema +-- !query 37 schema struct --- !query 53 output +-- !query 37 output #y�� --- !query 54 +-- !query 38 select X'XuZ' --- !query 54 schema +-- !query 38 schema struct<> --- !query 54 output +-- !query 38 output org.apache.spark.sql.catalyst.parser.ParseException contains illegal character for hexBinary: 0XuZ(line 1, pos 7) @@ -512,59 +378,35 @@ select X'XuZ' -------^^^ --- !query 55 +-- !query 39 SELECT 3.14, -3.14, 3.14e8, 3.14e-8, -3.14e8, -3.14e-8, 3.14e+8, 3.14E8, 3.14E-8 --- !query 55 schema +-- !query 39 schema struct<3.14:decimal(3,2),-3.14:decimal(3,2),3.14E+8:decimal(3,-6),3.14E-8:decimal(10,10),-3.14E+8:decimal(3,-6),-3.14E-8:decimal(10,10),3.14E+8:decimal(3,-6),3.14E+8:decimal(3,-6),3.14E-8:decimal(10,10)> --- !query 55 output +-- !query 39 output 3.14 -3.14 314000000 0.0000000314 -314000000 -0.0000000314 314000000 314000000 0.0000000314 --- !query 56 -select map(1, interval 1 day, 2, interval 3 week) --- !query 56 schema -struct> --- !query 56 output -{1:1 days,2:21 days} - - --- !query 57 -select interval 'interval 3 year 1 hour' --- !query 57 schema -struct<3 years 1 hours:interval> --- !query 57 output -3 years 1 hours - - --- !query 58 -select interval '3 year 1 hour' --- !query 58 schema -struct<3 years 1 hours:interval> --- !query 58 output -3 years 1 hours - - --- !query 59 +-- !query 40 select integer '7' --- !query 59 schema +-- !query 40 schema struct<7:int> --- !query 59 output +-- !query 40 output 7 --- !query 60 +-- !query 41 select integer'7' --- !query 60 schema +-- !query 41 schema struct<7:int> --- !query 60 output +-- !query 41 output 7 --- !query 61 +-- !query 42 select integer '2147483648' --- !query 61 schema +-- !query 42 schema struct<> --- !query 61 output +-- !query 42 output org.apache.spark.sql.catalyst.parser.ParseException Cannot parse the Int value: 2147483648, java.lang.NumberFormatException: For input string: "2147483648"(line 1, pos 7) @@ -574,173 +416,19 @@ select integer '2147483648' -------^^^ --- !query 62 -select interval --- !query 62 schema -struct<> --- !query 62 output -org.apache.spark.sql.catalyst.parser.ParseException - -at least one time unit should be given for interval literal(line 1, pos 7) - -== SQL == -select interval --------^^^ - - --- !query 63 -select interval 1 fake_unit --- !query 63 schema -struct<> --- !query 63 output -org.apache.spark.sql.catalyst.parser.ParseException - -no viable alternative at input '1 fake_unit'(line 1, pos 18) - -== SQL == -select interval 1 fake_unit -------------------^^^ - - --- !query 64 -select interval 1 year to month --- !query 64 schema -struct<> --- !query 64 output -org.apache.spark.sql.catalyst.parser.ParseException - -The value of from-to unit must be a string(line 1, pos 16) - -== SQL == -select interval 1 year to month -----------------^^^ - - --- !query 65 -select interval '1' year to second --- !query 65 schema -struct<> --- !query 65 output -org.apache.spark.sql.catalyst.parser.ParseException - -Intervals FROM year TO second are not supported.(line 1, pos 16) - -== SQL == -select interval '1' year to second -----------------^^^ - - --- !query 66 -select interval '10-9' year to month '2-1' year to month --- !query 66 schema -struct<> --- !query 66 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) - -== SQL == -select interval '10-9' year to month '2-1' year to month --------------------------------------^^^ - - --- !query 67 -select interval '10-9' year to month '12:11:10' hour to second --- !query 67 schema -struct<> --- !query 67 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) - -== SQL == -select interval '10-9' year to month '12:11:10' hour to second --------------------------------------^^^ - - --- !query 68 -select interval '1 15:11' day to minute '12:11:10' hour to second --- !query 68 schema -struct<> --- !query 68 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 40) - -== SQL == -select interval '1 15:11' day to minute '12:11:10' hour to second -----------------------------------------^^^ - - --- !query 69 -select interval 1 year '2-1' year to month --- !query 69 schema -struct<> --- !query 69 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) - -== SQL == -select interval 1 year '2-1' year to month ------------------------^^^ - - --- !query 70 -select interval 1 year '12:11:10' hour to second --- !query 70 schema -struct<> --- !query 70 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 23) - -== SQL == -select interval 1 year '12:11:10' hour to second ------------------------^^^ - - --- !query 71 -select interval '10-9' year to month '1' year --- !query 71 schema -struct<> --- !query 71 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 37) - -== SQL == -select interval '10-9' year to month '1' year --------------------------------------^^^ - - --- !query 72 -select interval '12:11:10' hour to second '1' year --- !query 72 schema -struct<> --- !query 72 output -org.apache.spark.sql.catalyst.parser.ParseException - -Can only have a single from-to unit in the interval literal syntax(line 1, pos 42) - -== SQL == -select interval '12:11:10' hour to second '1' year -------------------------------------------^^^ - - --- !query 73 +-- !query 43 select -integer '7' --- !query 73 schema +-- !query 43 schema struct<-7:int> --- !query 73 output +-- !query 43 output -7 --- !query 74 +-- !query 44 select -date '1999-01-01' --- !query 74 schema +-- !query 44 schema struct<> --- !query 74 output +-- !query 44 output org.apache.spark.sql.catalyst.parser.ParseException Literals of type '-DATE' are currently not supported.(line 1, pos 7) @@ -750,11 +438,11 @@ select -date '1999-01-01' -------^^^ --- !query 75 +-- !query 45 select -timestamp '1999-01-01' --- !query 75 schema +-- !query 45 schema struct<> --- !query 75 output +-- !query 45 output org.apache.spark.sql.catalyst.parser.ParseException Literals of type '-TIMESTAMP' are currently not supported.(line 1, pos 7) @@ -764,11 +452,11 @@ select -timestamp '1999-01-01' -------^^^ --- !query 76 +-- !query 46 select -x'2379ACFe' --- !query 76 schema +-- !query 46 schema struct<> --- !query 76 output +-- !query 46 output org.apache.spark.sql.catalyst.parser.ParseException Literals of type '-X' are currently not supported.(line 1, pos 7) @@ -776,19 +464,3 @@ Literals of type '-X' are currently not supported.(line 1, pos 7) == SQL == select -x'2379ACFe' -------^^^ - - --- !query 77 -select +integer '7' --- !query 77 schema -struct<7:int> --- !query 77 output -7 - - --- !query 78 -select +interval '1 second' --- !query 78 schema -struct<1 seconds:interval> --- !query 78 output -1 seconds diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala index f5693f835f13..739d61f590cb 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala @@ -344,7 +344,6 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { // vol used by boolean.sql and case.sql. localSparkSession.udf.register("vol", (s: String) => s) // PostgreSQL enabled cartesian product by default. - localSparkSession.conf.set(SQLConf.CROSS_JOINS_ENABLED.key, true) localSparkSession.conf.set(SQLConf.ANSI_ENABLED.key, true) localSparkSession.conf.set(SQLConf.DIALECT.key, SQLConf.Dialect.POSTGRESQL.toString) case _: AnsiTest => diff --git a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala index bd774eb4af83..493535be5075 100644 --- a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala +++ b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala @@ -27,12 +27,11 @@ import scala.util.control.NonFatal import org.apache.commons.lang3.exception.ExceptionUtils import org.apache.hadoop.hive.conf.HiveConf.ConfVars -import org.apache.spark.{SparkConf, SparkException} +import org.apache.spark.SparkException import org.apache.spark.sql.SQLQueryTestSuite import org.apache.spark.sql.catalyst.analysis.NoSuchTableException import org.apache.spark.sql.catalyst.util.fileToString import org.apache.spark.sql.execution.HiveResult -import org.apache.spark.sql.hive.HiveUtils import org.apache.spark.sql.internal.SQLConf import org.apache.spark.sql.types._ @@ -109,9 +108,10 @@ class ThriftServerQueryTestSuite extends SQLQueryTestSuite { testCase match { case _: PgSQLTest => // PostgreSQL enabled cartesian product by default. - statement.execute(s"SET ${SQLConf.CROSS_JOINS_ENABLED.key} = true") statement.execute(s"SET ${SQLConf.ANSI_ENABLED.key} = true") statement.execute(s"SET ${SQLConf.DIALECT.key} = ${SQLConf.Dialect.POSTGRESQL.toString}") + case _: AnsiTest => + statement.execute(s"SET ${SQLConf.ANSI_ENABLED.key} = true") case _ => } From 93051fcab621994ed0c9c78b2eb9a460990665ab Mon Sep 17 00:00:00 2001 From: Takeshi Yamamuro Date: Wed, 13 Nov 2019 22:53:18 +0900 Subject: [PATCH 3/4] Fix --- .../test/resources/sql-tests/inputs/interval.sql | 3 +-- .../test/resources/sql-tests/inputs/literals.sql | 3 ++- .../resources/sql-tests/results/interval.sql.out | 14 +++----------- .../org/apache/spark/sql/SQLQueryTestSuite.scala | 1 - .../thriftserver/ThriftServerQueryTestSuite.scala | 3 ++- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/interval.sql b/sql/core/src/test/resources/sql-tests/inputs/interval.sql index 45e06d78002e..b5c3416d0fc6 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/interval.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/interval.sql @@ -129,6 +129,5 @@ select interval 1 year '12:11:10' hour to second; select interval '10-9' year to month '1' year; select interval '12:11:10' hour to second '1' year; --- awareness of the negative sign before type -select +integer '7'; +-- awareness of the positive sign before interval type select +interval '1 second'; diff --git a/sql/core/src/test/resources/sql-tests/inputs/literals.sql b/sql/core/src/test/resources/sql-tests/inputs/literals.sql index 475d13df2971..d1dff7bc9468 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/literals.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/literals.sql @@ -105,8 +105,9 @@ select integer '7'; select integer'7'; select integer '2147483648'; --- awareness of the negative sign before type +-- awareness of the negative/positive sign before type select -integer '7'; select -date '1999-01-01'; select -timestamp '1999-01-01'; select -x'2379ACFe'; +select +integer '7'; diff --git a/sql/core/src/test/resources/sql-tests/results/interval.sql.out b/sql/core/src/test/resources/sql-tests/results/interval.sql.out index 124ae52d9633..91dd72dfa492 100644 --- a/sql/core/src/test/resources/sql-tests/results/interval.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/interval.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 89 +-- Number of queries: 88 -- !query 0 @@ -773,16 +773,8 @@ select interval '12:11:10' hour to second '1' year -- !query 87 -select +integer '7' --- !query 87 schema -struct<7:int> --- !query 87 output -7 - - --- !query 88 select +interval '1 second' --- !query 88 schema +-- !query 87 schema struct<1 seconds:interval> --- !query 88 output +-- !query 87 output 1 seconds diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala index 739d61f590cb..2ce50dd73a13 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala @@ -343,7 +343,6 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { localSparkSession.udf.register("boolne", (b1: Boolean, b2: Boolean) => b1 != b2) // vol used by boolean.sql and case.sql. localSparkSession.udf.register("vol", (s: String) => s) - // PostgreSQL enabled cartesian product by default. localSparkSession.conf.set(SQLConf.ANSI_ENABLED.key, true) localSparkSession.conf.set(SQLConf.DIALECT.key, SQLConf.Dialect.POSTGRESQL.toString) case _: AnsiTest => diff --git a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala index 493535be5075..67193e8de16f 100644 --- a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala +++ b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala @@ -107,7 +107,6 @@ class ThriftServerQueryTestSuite extends SQLQueryTestSuite { testCase match { case _: PgSQLTest => - // PostgreSQL enabled cartesian product by default. statement.execute(s"SET ${SQLConf.ANSI_ENABLED.key} = true") statement.execute(s"SET ${SQLConf.DIALECT.key} = ${SQLConf.Dialect.POSTGRESQL.toString}") case _: AnsiTest => @@ -241,6 +240,8 @@ class ThriftServerQueryTestSuite extends SQLQueryTestSuite { Seq.empty } else if (file.getAbsolutePath.startsWith(s"$inputFilePath${File.separator}postgreSQL")) { PgSQLTestCase(testCaseName, absPath, resultFile) :: Nil + } else if (file.getAbsolutePath.startsWith(s"$inputFilePath${File.separator}ansi")) { + AnsiTestCase(testCaseName, absPath, resultFile) :: Nil } else { RegularTestCase(testCaseName, absPath, resultFile) :: Nil } From ab0730be8b017be319c6cbc7828dfdea39625617 Mon Sep 17 00:00:00 2001 From: Takeshi Yamamuro Date: Thu, 14 Nov 2019 10:19:45 +0900 Subject: [PATCH 4/4] Fix --- .../ansi/decimalArithmeticOperations.sql | 30 +- .../ansi/decimalArithmeticOperations.sql.out | 307 +++--------------- .../sql-tests/results/ansi/literals.sql.out | 10 +- .../sql-tests/results/literals.sql.out | 10 +- 4 files changed, 96 insertions(+), 261 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/ansi/decimalArithmeticOperations.sql b/sql/core/src/test/resources/sql-tests/inputs/ansi/decimalArithmeticOperations.sql index 70f0d89b98e5..0de4e2b91e7e 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/ansi/decimalArithmeticOperations.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/ansi/decimalArithmeticOperations.sql @@ -1,4 +1,32 @@ -- SPARK-23179: SQL ANSI 2011 states that in case of overflow during arithmetic operations, -- an exception should be thrown instead of returning NULL. -- This is what most of the SQL DBs do (eg. SQLServer, DB2). ---import decimalArithmeticOperations.sql + +-- tests for decimals handling in operations +create table decimals_test(id int, a decimal(38,18), b decimal(38,18)) using parquet; + +insert into decimals_test values(1, 100.0, 999.0), (2, 12345.123, 12345.123), + (3, 0.1234567891011, 1234.1), (4, 123456789123456789.0, 1.123456789123456789); + +-- test operations between decimals and constants +select id, a*10, b/10 from decimals_test order by id; + +-- test operations on constants +select 10.3 * 3.0; +select 10.3000 * 3.0; +select 10.30000 * 30.0; +select 10.300000000000000000 * 3.000000000000000000; +select 10.300000000000000000 * 3.0000000000000000000; + +-- arithmetic operations causing an overflow throw exception +select (5e36 + 0.1) + 5e36; +select (-4e36 - 0.1) - 7e36; +select 12345678901234567890.0 * 12345678901234567890.0; +select 1e35 / 0.1; + +-- arithmetic operations causing a precision loss throw exception +select 123456789123456789.1234567890 * 1.123456789123456789; +select 123456789123456789.1234567890 * 1.123456789123456789; +select 12345678912345.123456789123 / 0.000000012345678; + +drop table decimals_test; diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/decimalArithmeticOperations.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/decimalArithmeticOperations.sql.out index 9da6d0958527..e12f409f6d47 100644 --- a/sql/core/src/test/resources/sql-tests/results/ansi/decimalArithmeticOperations.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/ansi/decimalArithmeticOperations.sql.out @@ -1,9 +1,9 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 40 +-- Number of queries: 16 -- !query 0 -CREATE TEMPORARY VIEW t AS SELECT 1.0 as a, 0.0 as b +create table decimals_test(id int, a decimal(38,18), b decimal(38,18)) using parquet -- !query 0 schema struct<> -- !query 0 output @@ -11,337 +11,128 @@ struct<> -- !query 1 -select a / b from t --- !query 1 schema -struct<(CAST(a AS DECIMAL(2,1)) / CAST(b AS DECIMAL(2,1))):decimal(8,6)> --- !query 1 output -NULL - - --- !query 2 -select a % b from t --- !query 2 schema -struct<(CAST(a AS DECIMAL(2,1)) % CAST(b AS DECIMAL(2,1))):decimal(1,1)> --- !query 2 output -NULL - - --- !query 3 -select pmod(a, b) from t --- !query 3 schema -struct --- !query 3 output -NULL - - --- !query 4 -create table decimals_test(id int, a decimal(38,18), b decimal(38,18)) using parquet --- !query 4 schema -struct<> --- !query 4 output - - - --- !query 5 insert into decimals_test values(1, 100.0, 999.0), (2, 12345.123, 12345.123), (3, 0.1234567891011, 1234.1), (4, 123456789123456789.0, 1.123456789123456789) --- !query 5 schema +-- !query 1 schema struct<> --- !query 5 output - - +-- !query 1 output --- !query 6 -select id, a+b, a-b, a*b, a/b from decimals_test order by id --- !query 6 schema -struct --- !query 6 output -1 1099 -899 99900 0.1001 -2 24690.246 0 152402061.885129 1 -3 1234.2234567891011 -1233.9765432108989 152.358023 0.0001 -4 123456789123456790.12345678912345679 123456789123456787.87654321087654321 138698367904130467.515623 109890109097814272.043109 --- !query 7 +-- !query 2 select id, a*10, b/10 from decimals_test order by id --- !query 7 schema +-- !query 2 schema struct --- !query 7 output +-- !query 2 output 1 1000 99.9 2 123451.23 1234.5123 3 1.234567891011 123.41 4 1234567891234567890 0.112345678912345679 --- !query 8 +-- !query 3 select 10.3 * 3.0 --- !query 8 schema +-- !query 3 schema struct<(CAST(10.3 AS DECIMAL(3,1)) * CAST(3.0 AS DECIMAL(3,1))):decimal(6,2)> --- !query 8 output +-- !query 3 output 30.9 --- !query 9 +-- !query 4 select 10.3000 * 3.0 --- !query 9 schema +-- !query 4 schema struct<(CAST(10.3000 AS DECIMAL(6,4)) * CAST(3.0 AS DECIMAL(6,4))):decimal(9,5)> --- !query 9 output +-- !query 4 output 30.9 --- !query 10 +-- !query 5 select 10.30000 * 30.0 --- !query 10 schema +-- !query 5 schema struct<(CAST(10.30000 AS DECIMAL(7,5)) * CAST(30.0 AS DECIMAL(7,5))):decimal(11,6)> --- !query 10 output +-- !query 5 output 309 --- !query 11 +-- !query 6 select 10.300000000000000000 * 3.000000000000000000 --- !query 11 schema +-- !query 6 schema struct<(CAST(10.300000000000000000 AS DECIMAL(20,18)) * CAST(3.000000000000000000 AS DECIMAL(20,18))):decimal(38,34)> --- !query 11 output +-- !query 6 output 30.9 --- !query 12 +-- !query 7 select 10.300000000000000000 * 3.0000000000000000000 --- !query 12 schema +-- !query 7 schema struct<(CAST(10.300000000000000000 AS DECIMAL(21,19)) * CAST(3.0000000000000000000 AS DECIMAL(21,19))):decimal(38,34)> --- !query 12 output +-- !query 7 output 30.9 --- !query 13 -select 2.35E10 * 1.0 --- !query 13 schema -struct<(CAST(2.35E+10 AS DECIMAL(12,1)) * CAST(1.0 AS DECIMAL(12,1))):decimal(6,-7)> --- !query 13 output -23500000000 - - --- !query 14 +-- !query 8 select (5e36 + 0.1) + 5e36 --- !query 14 schema +-- !query 8 schema struct<> --- !query 14 output +-- !query 8 output java.lang.ArithmeticException Decimal(expanded,10000000000000000000000000000000000000.1,39,1}) cannot be represented as Decimal(38, 1). --- !query 15 +-- !query 9 select (-4e36 - 0.1) - 7e36 --- !query 15 schema +-- !query 9 schema struct<> --- !query 15 output +-- !query 9 output java.lang.ArithmeticException Decimal(expanded,-11000000000000000000000000000000000000.1,39,1}) cannot be represented as Decimal(38, 1). --- !query 16 +-- !query 10 select 12345678901234567890.0 * 12345678901234567890.0 --- !query 16 schema +-- !query 10 schema struct<> --- !query 16 output +-- !query 10 output java.lang.ArithmeticException Decimal(expanded,1.5241578753238836750190519987501905210E+38,38,-1}) cannot be represented as Decimal(38, 2). --- !query 17 +-- !query 11 select 1e35 / 0.1 --- !query 17 schema +-- !query 11 schema struct<> --- !query 17 output +-- !query 11 output java.lang.ArithmeticException Decimal(expanded,1000000000000000000000000000000000000,37,0}) cannot be represented as Decimal(38, 6). --- !query 18 -select 1.2345678901234567890E30 * 1.2345678901234567890E25 --- !query 18 schema -struct<> --- !query 18 output -java.lang.ArithmeticException -Decimal(expanded,1.5241578753238836750190519987501905210E+55,38,-18}) cannot be represented as Decimal(38, -17). - - --- !query 19 -select 12345678912345678912345678912.1234567 + 9999999999999999999999999999999.12345 --- !query 19 schema -struct<(CAST(12345678912345678912345678912.1234567 AS DECIMAL(38,6)) + CAST(9999999999999999999999999999999.12345 AS DECIMAL(38,6))):decimal(38,6)> --- !query 19 output -10012345678912345678912345678911.246907 +-- !query 12 +select 123456789123456789.1234567890 * 1.123456789123456789 +-- !query 12 schema +struct<(CAST(123456789123456789.1234567890 AS DECIMAL(36,18)) * CAST(1.123456789123456789 AS DECIMAL(36,18))):decimal(38,18)> +-- !query 12 output +138698367904130467.654320988515622621 --- !query 20 +-- !query 13 select 123456789123456789.1234567890 * 1.123456789123456789 --- !query 20 schema +-- !query 13 schema struct<(CAST(123456789123456789.1234567890 AS DECIMAL(36,18)) * CAST(1.123456789123456789 AS DECIMAL(36,18))):decimal(38,18)> --- !query 20 output +-- !query 13 output 138698367904130467.654320988515622621 --- !query 21 +-- !query 14 select 12345678912345.123456789123 / 0.000000012345678 --- !query 21 schema +-- !query 14 schema struct<(CAST(12345678912345.123456789123 AS DECIMAL(29,15)) / CAST(1.2345678E-8 AS DECIMAL(29,15))):decimal(38,9)> --- !query 21 output +-- !query 14 output 1000000073899961059796.725866332 --- !query 22 -set spark.sql.decimalOperations.allowPrecisionLoss=false --- !query 22 schema -struct --- !query 22 output -spark.sql.decimalOperations.allowPrecisionLoss false - - --- !query 23 -select id, a+b, a-b, a*b, a/b from decimals_test order by id --- !query 23 schema -struct<> --- !query 23 output -java.lang.ArithmeticException -Decimal(expanded,99900.000000000000000000000000000000000,38,33}) cannot be represented as Decimal(38, 36). - - --- !query 24 -select id, a*10, b/10 from decimals_test order by id --- !query 24 schema -struct --- !query 24 output -1 1000 99.9 -2 123451.23 1234.5123 -3 1.234567891011 123.41 -4 1234567891234567890 0.1123456789123456789 - - --- !query 25 -select 10.3 * 3.0 --- !query 25 schema -struct<(CAST(10.3 AS DECIMAL(3,1)) * CAST(3.0 AS DECIMAL(3,1))):decimal(6,2)> --- !query 25 output -30.9 - - --- !query 26 -select 10.3000 * 3.0 --- !query 26 schema -struct<(CAST(10.3000 AS DECIMAL(6,4)) * CAST(3.0 AS DECIMAL(6,4))):decimal(9,5)> --- !query 26 output -30.9 - - --- !query 27 -select 10.30000 * 30.0 --- !query 27 schema -struct<(CAST(10.30000 AS DECIMAL(7,5)) * CAST(30.0 AS DECIMAL(7,5))):decimal(11,6)> --- !query 27 output -309 - - --- !query 28 -select 10.300000000000000000 * 3.000000000000000000 --- !query 28 schema -struct<(CAST(10.300000000000000000 AS DECIMAL(20,18)) * CAST(3.000000000000000000 AS DECIMAL(20,18))):decimal(38,36)> --- !query 28 output -30.9 - - --- !query 29 -select 10.300000000000000000 * 3.0000000000000000000 --- !query 29 schema -struct<> --- !query 29 output -java.lang.ArithmeticException -Decimal(expanded,30.900000000000000000000000000000000000,38,36}) cannot be represented as Decimal(38, 37). - - --- !query 30 -select 2.35E10 * 1.0 --- !query 30 schema -struct<(CAST(2.35E+10 AS DECIMAL(12,1)) * CAST(1.0 AS DECIMAL(12,1))):decimal(6,-7)> --- !query 30 output -23500000000 - - --- !query 31 -select (5e36 + 0.1) + 5e36 --- !query 31 schema -struct<> --- !query 31 output -java.lang.ArithmeticException -Decimal(expanded,10000000000000000000000000000000000000.1,39,1}) cannot be represented as Decimal(38, 1). - - --- !query 32 -select (-4e36 - 0.1) - 7e36 --- !query 32 schema -struct<> --- !query 32 output -java.lang.ArithmeticException -Decimal(expanded,-11000000000000000000000000000000000000.1,39,1}) cannot be represented as Decimal(38, 1). - - --- !query 33 -select 12345678901234567890.0 * 12345678901234567890.0 --- !query 33 schema -struct<> --- !query 33 output -java.lang.ArithmeticException -Decimal(expanded,1.5241578753238836750190519987501905210E+38,38,-1}) cannot be represented as Decimal(38, 2). - - --- !query 34 -select 1e35 / 0.1 --- !query 34 schema -struct<> --- !query 34 output -java.lang.ArithmeticException -Decimal(expanded,1000000000000000000000000000000000000,37,0}) cannot be represented as Decimal(38, 3). - - --- !query 35 -select 1.2345678901234567890E30 * 1.2345678901234567890E25 --- !query 35 schema -struct<> --- !query 35 output -java.lang.ArithmeticException -Decimal(expanded,1.5241578753238836750190519987501905210E+55,38,-18}) cannot be represented as Decimal(38, -17). - - --- !query 36 -select 12345678912345678912345678912.1234567 + 9999999999999999999999999999999.12345 --- !query 36 schema -struct<> --- !query 36 output -java.lang.ArithmeticException -Decimal(expanded,10012345678912345678912345678911.2469067,39,7}) cannot be represented as Decimal(38, 7). - - --- !query 37 -select 123456789123456789.1234567890 * 1.123456789123456789 --- !query 37 schema -struct<> --- !query 37 output -java.lang.ArithmeticException -Decimal(expanded,138698367904130467.65432098851562262075,38,20}) cannot be represented as Decimal(38, 28). - - --- !query 38 -select 12345678912345.123456789123 / 0.000000012345678 --- !query 38 schema -struct<> --- !query 38 output -java.lang.ArithmeticException -Decimal(expanded,1000000073899961059796.7258663315210392,38,16}) cannot be represented as Decimal(38, 18). - - --- !query 39 +-- !query 15 drop table decimals_test --- !query 39 schema +-- !query 15 schema struct<> --- !query 39 output +-- !query 15 output diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out index c1d08e4aa460..e43e88c8c72a 100644 --- a/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/ansi/literals.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 47 +-- Number of queries: 48 -- !query 0 @@ -464,3 +464,11 @@ Literals of type '-X' are currently not supported.(line 1, pos 7) == SQL == select -x'2379ACFe' -------^^^ + + +-- !query 47 +select +integer '7' +-- !query 47 schema +struct<7:int> +-- !query 47 output +7 diff --git a/sql/core/src/test/resources/sql-tests/results/literals.sql.out b/sql/core/src/test/resources/sql-tests/results/literals.sql.out index c1d08e4aa460..e43e88c8c72a 100644 --- a/sql/core/src/test/resources/sql-tests/results/literals.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/literals.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 47 +-- Number of queries: 48 -- !query 0 @@ -464,3 +464,11 @@ Literals of type '-X' are currently not supported.(line 1, pos 7) == SQL == select -x'2379ACFe' -------^^^ + + +-- !query 47 +select +integer '7' +-- !query 47 schema +struct<7:int> +-- !query 47 output +7