狂甩酷拽吊炸天
分类: LINUX
2019-08-14 17:53:12
array_distinct(array
SELECT array_distinct(array(1, 2, 3, null, 3));
[1,2,3,null]
|
array_intersect(array
SELECT array_intersect(array(1, 2, 3), array(1, 3, 5));
[1,3]
|
array_union(array
SELECT array_union(array(1, 2, 3), array(1, 3, 5));
[1,2,3,5]
|
array_except(array
SELECT array_except(array(1, 2, 3), array(1, 3, 5));
[2]
|
array_join(array
SELECT array_join(array('hello', 'world'), ' ');
hello world
SELECT array_join(array('hello', null ,'world'), ' ');
hello world
SELECT array_join(array('hello', null ,'world'), ' ', ',');
hello , world
|
array_max(array
SELECT array_max(array(1, 20, null, 3));
20
|
array_min(array
SELECT array_max(array(1, 20, null, 3));
1
|
array_position(array
SELECT array_position(array(3, 2, 1), 1);
3
|
array_remove(array
SELECT array_remove(array(1, 2, 3, null, 3), 3);
[1,2,null]
|
arrays_overlap(array
SELECT arrays_overlap(array(1, 2, 3), array(3, 4, 5));
true
|
array_sort(array
SELECT array_sort(array('b', 'd', null, 'c', 'a'));
["a","b","c","d",null]
|
concat(String, ...): String / concat(array
SELECT concat('Spark', 'SQL');
SparkSQL
SELECT concat(array(1, 2, 3), array(4, 5), array(6));
[1,2,3,4,5,6]
|
flatten(array
SELECT flatten(array(array(1, 2), array(3, 4)));
[1,2,3,4]
|
array_repeat(T, Int): array
SELECT array_repeat('123', 2);
["123","123"]
|
reverse(String): String / reverse(array
SELECT reverse('Spark SQL');
LQS krapS
SELECT reverse(array(2, 1, 4, 3));
[3,4,1,2]
|
sequence(T, T[, T]): array
SELECT sequence(1, 5);
[1,2,3,4,5]
SELECT sequence(5, 1);
[5,4,3,2,1]
SELECT sequence(to_date('2018-01-01'), to_date('2018-03-01'), interval 1 month);
["2018-01-01","2018-02-01","2018-03-01"]
|
shuffle(array
SELECT shuffle(array(1, 20, 3, 5));
[3,5,1,20]
SELECT shuffle(array(1, 20, null, 3));
[null,3,20,1]
|
slice(array
SELECT slice(array(1, 2, 3, 4), 2, 2);
[2,3]
SELECT slice(array(1, 2, 3, 4), -2, 2);
[3,4]
|
array_zip(array
SELECT arrays_zip(array(1, 2, 3), array(2, 3, 4));
[{"0":1,"1":2},{"0":2,"1":3},{"0":3,"1":4}]
SELECT arrays_zip(array(1, 2), array(2, 3), array(3, 4));
[{"0":1,"1":2,"2":3},{"0":2,"1":3,"2":4}]
|
map_form_arrays(array
SELECT map_from_arrays(array(1.0, 3.0), array('2', '4'));
{"1.0":"2","3.0":"4"}
|
map_from_entries(array
SELECT map_from_entries(array(struct(1, 'a'), struct(2, 'b')));
{"1":"a","2":"b"}
|
map_concat(map
SELECT map_concat(map(1, 'a', 2, 'b'), map(2, 'c', 3, 'd'));
{"1":"a","2":"c","3":"d"}
|
element_at(array
SELECT element_at(array(1, 2, 3), 2);
2
SELECT element_at(map(1, 'a', 2, 'b'), 2);
b
|
cardinality(array
SELECT cardinality(array('b', 'd', 'c', 'a'));
4
|
transform(array
SELECT transform(array(1, 2, 3), x -> x + 1);
[2,3,4]
SELECT transform(array(1, 2, 3), (x, i) -> x + i);
[1,3,5]
|
filter(array
SELECT filter(array(1, 2, 3), x -> x % 2 == 1);
[1,3]
|
aggregate(array
SELECT aggregate(array(1, 2, 3), 0, (acc, x) -> acc + x);
6
SELECT aggregate(array(1, 2, 3), 0, (acc, x) -> acc + x, acc -> acc * 10);
60
|
exists(array
SELECT exists(array(1, 2, 3), x -> x % 2 == 0);
true
|
zip_with(array
SELECT zip_with(array(1, 2, 3), array('a', 'b', 'c'), (x, y) -> (y, x));
[{"y":"a","x":1},{"y":"b","x":2},{"y":"c","x":3}]
SELECT zip_with(array(1, 2), array(3, 4), (x, y) -> x + y);
[4,6]
SELECT zip_with(array('a', 'b', 'c'), array('d', 'e', 'f'), (x, y) -> concat(x, y));
["ad","be","cf"]
|