You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{"arr", "Array for which to calculate differences between adjacent elements. [`Array(T)`](/sql-reference/data-types/array)."},
177
+
};
178
+
FunctionDocumentation::ReturnedValue returned_value = "Returns an array of differences between adjacent array elements. [`UInt*`](/sql-reference/data-types/int-uint#integer-ranges), [`Int*`](/sql-reference/data-types/int-uint#integer-ranges), [`Float*`](/sql-reference/data-types/float).";
Copy file name to clipboardExpand all lines: src/Functions/array/arrayEnumerateDense.cpp
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,17 @@ class FunctionArrayEnumerateDense : public FunctionArrayEnumerateExtended<Functi
16
16
17
17
REGISTER_FUNCTION(ArrayEnumerateDense)
18
18
{
19
+
FunctionDocumentation::Description description = "Returns an array of the same size as the source array, indicating where each element first appears in the source array.";
{"arr", "The array to enumerate. [`Array(T)`](/sql-reference/data-types/array)."}
23
+
};
24
+
FunctionDocumentation::ReturnedValue returned_value = "Returns an array of the same size as `arr`, indicating where each element first appears in the source array. [`Array(T)`](/sql-reference/data-types/array).";
Copy file name to clipboardExpand all lines: src/Functions/array/arrayEnumerateDenseRanked.cpp
+39Lines changed: 39 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,45 @@ class FunctionArrayEnumerateDenseRanked : public FunctionArrayEnumerateRankedExt
16
16
17
17
REGISTER_FUNCTION(ArrayEnumerateDenseRanked)
18
18
{
19
+
FunctionDocumentation::Description description = "Returns an array the same size as the source array, indicating where each element first appears in the source array. It allows for enumeration of a multidimensional array with the ability to specify how deep to look inside the array.";
{"clear_depth", "Enumerate elements at the specified level separately. Positive [Integer](../data-types/int-uint.md) less than or equal to `max_arr_depth`."},
23
+
{"arr", "N-dimensional array to enumerate. [`Array(T)`](/sql-reference/data-types/array)."},
24
+
{"max_array_depth", "The maximum effective depth. Positive [(U)Int*](../data-types/int-uint.md) less than or equal to the depth of `arr`."},
25
+
};
26
+
FunctionDocumentation::ReturnedValue returned_value = "Returns an array denoting where each element first appears in the source array. [Array](/sql-reference/data-types/array).";
27
+
FunctionDocumentation::Examples examples = {
28
+
{"Basic usage", R"(
29
+
With `clear_depth=1` and `max_array_depth=1`, the result is identical to what [arrayEnumerateDense](#arrayenumeratedense) would give.
In this example, `arrayEnumerateDenseRanked` is used to obtain an array indicating, for each element of the multidimensional array, what its position is among elements of the same value.
37
+
For the first row of the passed array,`[10,10,30,20]`, the corresponding first row of the result is `[1,1,2,3]`, indicating that `10` is the first number encountered in position 1 and 2, `30` the second number encountered in position 3 and `20` is the third number encountered in position 4.
38
+
For the second row, `[40, 50, 10, 30]`, the corresponding second row of the result is `[4,5,1,2]`, indicating that `40` and `50` are the fourth and fifth numbers encountered in position 1 and 2 of that row, that another `10` (the first encountered number) is in position 3 and `30` (the second number encountered) is in the last position.
FunctionDocumentation::Description intersect_description = "Takes multiple arrays and returns an array with elements which are present in all source arrays. The result contains only unique values.";
FunctionDocumentation::Arguments intersect_argument = {{"arrN", "N arrays from which to make the new array. [`Array(T)`](/sql-reference/data-types/array)."}};
772
+
FunctionDocumentation::ReturnedValue intersect_returned_value = "Returns an array with distinct elements that are present in all N arrays. [`Array(T)`](/sql-reference/data-types/array).";
FunctionDocumentation::Description union_description = "Takes multiple arrays and returns an array which contains all elements that are present in one of the source arrays.The result contains only unique values.";
FunctionDocumentation::Arguments union_argument = {{"arrN", "N arrays from which to make the new array. [`Array(T)`](/sql-reference/data-types/array)."}};
791
+
FunctionDocumentation::ReturnedValue union_returned_value = "Returns an array with distinct elements from the source arrays. [`Array(T)`](/sql-reference/data-types/array).";
FunctionDocumentation::Description symdiff_description = R"(Takes multiple arrays and returns an array with elements that are not present in all source arrays. The result contains only unique values.
809
+
810
+
:::note
811
+
The symmetric difference of _more than two sets_ is [mathematically defined](https://en.wikipedia.org/wiki/Symmetric_difference#n-ary_symmetric_difference)
812
+
as the set of all input elements which occur in an odd number of input sets.
813
+
In contrast, function `arraySymmetricDifference` simply returns the set of input elements which do not occur in all input sets.
FunctionDocumentation::Arguments symdiff_argument = {{"arrN", "N arrays from which to make the new array. [`Array(T)`](/sql-reference/data-types/array)."}};
818
+
FunctionDocumentation::ReturnedValue symdiff_returned_value = "Returns an array of distinct elements not present in all source arrays. [`Array(T)`](/sql-reference/data-types/array).";
{"arr", "An array to unfold. [`Array(T)`](/sql-reference/data-types/array)."}
91
+
};
92
+
FunctionDocumentation::ReturnedValue returned_value = "Returns a set of rows unfolded from `arr`.";
93
+
FunctionDocumentation::Examples examples = {
94
+
{"Basic usage", R"(SELECT arrayJoin([1, 2, 3] AS src) AS dst, 'Hello', src)", R"(
95
+
┌─dst─┬─\'Hello\'─┬─src─────┐
96
+
│ 1 │ Hello │ [1,2,3] │
97
+
│ 2 │ Hello │ [1,2,3] │
98
+
│ 3 │ Hello │ [1,2,3] │
99
+
└─────┴───────────┴─────────┘
100
+
)"},
101
+
{"arrayJoin affects all sections of the query", R"(
102
+
The `arrayJoin` function affects all sections of the query, including the `WHERE` section. Notice the result 2, even though the subquery returned 1 row.
103
+
104
+
```sql
105
+
SELECT sum(1) AS impressions
106
+
FROM
107
+
(
108
+
SELECT ['Istanbul', 'Berlin', 'Bobruisk'] AS cities
109
+
)
110
+
WHERE arrayJoin(cities) IN ['Istanbul', 'Berlin'];
111
+
```
112
+
)", R"(
113
+
┌─impressions─┐
114
+
│ 2 │
115
+
└─────────────┘
116
+
)"},
117
+
{"Using multiple arrayJoin functions", R"(
118
+
A query can use multiple `arrayJoin` functions. In this case, the transformation is performed multiple times and the rows are multiplied.
119
+
120
+
```sql
121
+
SELECT
122
+
sum(1) AS impressions,
123
+
arrayJoin(cities) AS city,
124
+
arrayJoin(browsers) AS browser
125
+
FROM
126
+
(
127
+
SELECT
128
+
['Istanbul', 'Berlin', 'Bobruisk'] AS cities,
129
+
['Firefox', 'Chrome', 'Chrome'] AS browsers
130
+
)
131
+
GROUP BY
132
+
2,
133
+
3
134
+
```
135
+
)", R"(
136
+
┌─impressions─┬─city─────┬─browser─┐
137
+
│ 2 │ Istanbul │ Chrome │
138
+
│ 1 │ Istanbul │ Firefox │
139
+
│ 2 │ Berlin │ Chrome │
140
+
│ 1 │ Berlin │ Firefox │
141
+
│ 2 │ Bobruisk │ Chrome │
142
+
│ 1 │ Bobruisk │ Firefox │
143
+
└─────────────┴──────────┴─────────┘
144
+
)"
145
+
},
146
+
{"Unexpected results due to optimizations", R"(
147
+
Using multiple `arrayJoin` with the same expression may not produce the expected result due to optimizations.
148
+
For these cases, consider modifying the repeated array expression with extra operations that do not affect join result.
149
+
e.g. `arrayJoin(arraySort(arr))`, `arrayJoin(arrayConcat(arr, []))`
150
+
151
+
```sql
152
+
SELECT
153
+
arrayJoin(dice) as first_throw,
154
+
/* arrayJoin(dice) as second_throw */ -- is technically correct, but will annihilate result set
155
+
arrayJoin(arrayConcat(dice, [])) as second_throw -- intentionally changed expression to force re-evaluation
156
+
FROM (
157
+
SELECT [1, 2, 3, 4, 5, 6] as dice
158
+
);
159
+
```
160
+
)", R"(
161
+
┌─first_throw─┬─second_throw─┐
162
+
│ 1 │ 1 │
163
+
│ 1 │ 2 │
164
+
│ 1 │ 3 │
165
+
│ 1 │ 4 │
166
+
│ 1 │ 5 │
167
+
│ 1 │ 6 │
168
+
│ 2 │ 1 │
169
+
│ 2 │ 2 │
170
+
│ 2 │ 3 │
171
+
│ 2 │ 4 │
172
+
│ 2 │ 5 │
173
+
│ 2 │ 6 │
174
+
│ 3 │ 1 │
175
+
│ 3 │ 2 │
176
+
│ 3 │ 3 │
177
+
│ 3 │ 4 │
178
+
│ 3 │ 5 │
179
+
│ 3 │ 6 │
180
+
│ 4 │ 1 │
181
+
│ 4 │ 2 │
182
+
│ 4 │ 3 │
183
+
│ 4 │ 4 │
184
+
│ 4 │ 5 │
185
+
│ 4 │ 6 │
186
+
│ 5 │ 1 │
187
+
│ 5 │ 2 │
188
+
│ 5 │ 3 │
189
+
│ 5 │ 4 │
190
+
│ 5 │ 5 │
191
+
│ 5 │ 6 │
192
+
│ 6 │ 1 │
193
+
│ 6 │ 2 │
194
+
│ 6 │ 3 │
195
+
│ 6 │ 4 │
196
+
│ 6 │ 5 │
197
+
│ 6 │ 6 │
198
+
└─────────────┴──────────────┘
199
+
)"
200
+
},
201
+
{"Using the ARRAY JOIN syntax", R"(
202
+
Note the [`ARRAY JOIN`](../statements/select/array-join.md) syntax in the `SELECT` query below, which provides broader possibilities.
203
+
`ARRAY JOIN` allows you to convert multiple arrays with the same number of elements at a time.
204
+
205
+
```sql
206
+
SELECT
207
+
sum(1) AS impressions,
208
+
city,
209
+
browser
210
+
FROM
211
+
(
212
+
SELECT
213
+
['Istanbul', 'Berlin', 'Bobruisk'] AS cities,
214
+
['Firefox', 'Chrome', 'Chrome'] AS browsers
215
+
)
216
+
ARRAY JOIN
217
+
cities AS city,
218
+
browsers AS browser
219
+
GROUP BY
220
+
2,
221
+
3
222
+
```
223
+
)", R"(
224
+
┌─impressions─┬─city─────┬─browser─┐
225
+
│ 1 │ Istanbul │ Firefox │
226
+
│ 1 │ Berlin │ Chrome │
227
+
│ 1 │ Bobruisk │ Chrome │
228
+
└─────────────┴──────────┴─────────┘
229
+
)"
230
+
},
231
+
{"Using Tuple", R"(
232
+
You can also use [Tuple](../data-types/tuple.md):
233
+
234
+
```sql
235
+
SELECT
236
+
sum(1) AS impressions,
237
+
(arrayJoin(arrayZip(cities, browsers)) AS t).1 AS city,
0 commit comments