forked from apache/datafusion-comet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_distinct.sql
More file actions
179 lines (136 loc) · 5.12 KB
/
array_distinct.sql
File metadata and controls
179 lines (136 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.
-- ConfigMatrix: parquet.enable.dictionary=false,true
-- ===== INT arrays =====
statement
CREATE TABLE test_array_distinct_int(arr array<int>) USING parquet
statement
INSERT INTO test_array_distinct_int VALUES
(array(1, 2, 2, 3, 3)),
(array()),
(NULL),
(array(NULL, 1, NULL, 2)),
(array(1)),
(array(NULL, NULL, NULL)),
(array(-2147483648, 2147483647, -2147483648, 0)),
(array(0, -1, -1, 0, 1))
-- column argument
query spark_answer_only
SELECT array_distinct(arr) FROM test_array_distinct_int
-- literal arguments
query spark_answer_only
SELECT array_distinct(array(1, 2, 2, 3, 3))
-- all NULLs
query spark_answer_only
SELECT array_distinct(array(CAST(NULL AS INT), CAST(NULL AS INT)))
-- NULL input
query spark_answer_only
SELECT array_distinct(CAST(NULL AS array<int>))
-- boundary values
query spark_answer_only
SELECT array_distinct(array(-2147483648, 2147483647, -2147483648, 2147483647, 0))
-- ===== LONG arrays =====
statement
CREATE TABLE test_array_distinct_long(arr array<bigint>) USING parquet
statement
INSERT INTO test_array_distinct_long VALUES
(array(1, 2, 2, 3, 3)),
(NULL),
(array(NULL, 1, NULL, 2)),
(array(-9223372036854775808, 9223372036854775807, -9223372036854775808))
query spark_answer_only
SELECT array_distinct(arr) FROM test_array_distinct_long
-- boundary values
query spark_answer_only
SELECT array_distinct(array(CAST(-9223372036854775808 AS BIGINT), CAST(9223372036854775807 AS BIGINT), CAST(-9223372036854775808 AS BIGINT)))
-- ===== STRING arrays =====
statement
CREATE TABLE test_array_distinct_string(arr array<string>) USING parquet
statement
INSERT INTO test_array_distinct_string VALUES
(array('b', 'a', 'a', 'c', 'b')),
(array('')),
(NULL),
(array(NULL, 'a', NULL, 'a')),
(array('', '', NULL, '')),
(array('hello', 'world', 'hello'))
query spark_answer_only
SELECT array_distinct(arr) FROM test_array_distinct_string
-- empty string and NULL distinction
query spark_answer_only
SELECT array_distinct(array('', NULL, '', NULL, 'a'))
-- ===== BOOLEAN arrays =====
statement
CREATE TABLE test_array_distinct_bool(arr array<boolean>) USING parquet
statement
INSERT INTO test_array_distinct_bool VALUES
(array(true, false, false, true)),
(array(true, true)),
(NULL),
(array(NULL, true, NULL, false))
query spark_answer_only
SELECT array_distinct(arr) FROM test_array_distinct_bool
-- ===== DOUBLE arrays =====
statement
CREATE TABLE test_array_distinct_double(arr array<double>) USING parquet
statement
INSERT INTO test_array_distinct_double VALUES
(array(1.123, 0.1234, 1.121, 1.123, 0.1234)),
(NULL),
(array(NULL, 1.0, NULL, 2.0))
query spark_answer_only
SELECT array_distinct(arr) FROM test_array_distinct_double
-- NaN deduplication
query spark_answer_only
SELECT array_distinct(array(CAST('NaN' AS DOUBLE), CAST('NaN' AS DOUBLE), 1.0, 1.0))
-- NaN with NULL
query spark_answer_only
SELECT array_distinct(array(CAST('NaN' AS DOUBLE), NULL, CAST('NaN' AS DOUBLE), NULL, 1.0))
-- Infinity
query spark_answer_only
SELECT array_distinct(array(CAST('Infinity' AS DOUBLE), CAST('-Infinity' AS DOUBLE), CAST('Infinity' AS DOUBLE), 0.0))
-- negative zero
query spark_answer_only
SELECT array_distinct(array(0.0, -0.0, 1.0))
-- ===== FLOAT arrays =====
statement
CREATE TABLE test_array_distinct_float(arr array<float>) USING parquet
statement
INSERT INTO test_array_distinct_float VALUES
(array(CAST(1.123 AS FLOAT), CAST(0.1234 AS FLOAT), CAST(1.121 AS FLOAT), CAST(1.123 AS FLOAT))),
(NULL),
(array(CAST(NULL AS FLOAT), CAST(1.0 AS FLOAT), CAST(NULL AS FLOAT)))
query spark_answer_only
SELECT array_distinct(arr) FROM test_array_distinct_float
-- Float NaN deduplication
query spark_answer_only
SELECT array_distinct(array(CAST('NaN' AS FLOAT), CAST('NaN' AS FLOAT), CAST(1.0 AS FLOAT)))
-- ===== DECIMAL arrays =====
statement
CREATE TABLE test_array_distinct_decimal(arr array<decimal(10,2)>) USING parquet
statement
INSERT INTO test_array_distinct_decimal VALUES
(array(1.10, 2.20, 1.10, 3.30)),
(NULL),
(array(NULL, 1.10, NULL, 1.10))
query spark_answer_only
SELECT array_distinct(arr) FROM test_array_distinct_decimal
-- ===== Nested array (array of arrays) =====
query spark_answer_only
SELECT array_distinct(array(array(1, 2), array(3, 4), array(1, 2), array(3, 4)))
query spark_answer_only
SELECT array_distinct(array(array(1, 2), CAST(NULL AS array<int>), array(1, 2), CAST(NULL AS array<int>)))