aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/test/resources/sql-tests/inputs
diff options
context:
space:
mode:
Diffstat (limited to 'sql/core/src/test/resources/sql-tests/inputs')
-rw-r--r--sql/core/src/test/resources/sql-tests/inputs/arithmetic.sql26
-rw-r--r--sql/core/src/test/resources/sql-tests/inputs/group-by-ordinal.sql50
-rw-r--r--sql/core/src/test/resources/sql-tests/inputs/order-by-ordinal.sql36
3 files changed, 112 insertions, 0 deletions
diff --git a/sql/core/src/test/resources/sql-tests/inputs/arithmetic.sql b/sql/core/src/test/resources/sql-tests/inputs/arithmetic.sql
new file mode 100644
index 0000000000..cbe40410cd
--- /dev/null
+++ b/sql/core/src/test/resources/sql-tests/inputs/arithmetic.sql
@@ -0,0 +1,26 @@
+
+-- unary minus and plus
+select -100;
+select +230;
+select -5.2;
+select +6.8e0;
+select -key, +key from testdata where key = 2;
+select -(key + 1), - key + 1, +(key + 5) from testdata where key = 1;
+select -max(key), +max(key) from testdata;
+select - (-10);
+select + (-key) from testdata where key = 32;
+select - (+max(key)) from testdata;
+select - - 3;
+select - + 20;
+select + + 100;
+select - - max(key) from testdata;
+select + - key from testdata where key = 33;
+
+-- other arithmetics
+select 1 + 2;
+select 1 - 2;
+select 2 * 5;
+select 5 / 2;
+select 5 div 2;
+select 5 % 3;
+select pmod(-7, 3);
diff --git a/sql/core/src/test/resources/sql-tests/inputs/group-by-ordinal.sql b/sql/core/src/test/resources/sql-tests/inputs/group-by-ordinal.sql
new file mode 100644
index 0000000000..36b469c617
--- /dev/null
+++ b/sql/core/src/test/resources/sql-tests/inputs/group-by-ordinal.sql
@@ -0,0 +1,50 @@
+-- group by ordinal positions
+
+create temporary view data as select * from values
+ (1, 1),
+ (1, 2),
+ (2, 1),
+ (2, 2),
+ (3, 1),
+ (3, 2)
+ as data(a, b);
+
+-- basic case
+select a, sum(b) from data group by 1;
+
+-- constant case
+select 1, 2, sum(b) from data group by 1, 2;
+
+-- duplicate group by column
+select a, 1, sum(b) from data group by a, 1;
+select a, 1, sum(b) from data group by 1, 2;
+
+-- group by a non-aggregate expression's ordinal
+select a, b + 2, count(2) from data group by a, 2;
+
+-- with alias
+select a as aa, b + 2 as bb, count(2) from data group by 1, 2;
+
+-- foldable non-literal: this should be the same as no grouping.
+select sum(b) from data group by 1 + 0;
+
+-- negative cases: ordinal out of range
+select a, b from data group by -1;
+select a, b from data group by 0;
+select a, b from data group by 3;
+
+-- negative case: position is an aggregate expression
+select a, b, sum(b) from data group by 3;
+select a, b, sum(b) + 2 from data group by 3;
+
+-- negative case: nondeterministic expression
+select a, rand(0), sum(b) from data group by a, 2;
+
+-- negative case: star
+select * from data group by a, b, 1;
+
+-- turn of group by ordinal
+set spark.sql.groupByOrdinal=false;
+
+-- can now group by negative literal
+select sum(b) from data group by -1;
diff --git a/sql/core/src/test/resources/sql-tests/inputs/order-by-ordinal.sql b/sql/core/src/test/resources/sql-tests/inputs/order-by-ordinal.sql
new file mode 100644
index 0000000000..8d733e77fa
--- /dev/null
+++ b/sql/core/src/test/resources/sql-tests/inputs/order-by-ordinal.sql
@@ -0,0 +1,36 @@
+-- order by and sort by ordinal positions
+
+create temporary view data as select * from values
+ (1, 1),
+ (1, 2),
+ (2, 1),
+ (2, 2),
+ (3, 1),
+ (3, 2)
+ as data(a, b);
+
+select * from data order by 1 desc;
+
+-- mix ordinal and column name
+select * from data order by 1 desc, b desc;
+
+-- order by multiple ordinals
+select * from data order by 1 desc, 2 desc;
+
+-- 1 + 0 is considered a constant (not an ordinal) and thus ignored
+select * from data order by 1 + 0 desc, b desc;
+
+-- negative cases: ordinal position out of range
+select * from data order by 0;
+select * from data order by -1;
+select * from data order by 3;
+
+-- sort by ordinal
+select * from data sort by 1 desc;
+
+-- turn off order by ordinal
+set spark.sql.orderByOrdinal=false;
+
+-- 0 is now a valid literal
+select * from data order by 0;
+select * from data sort by 0;