array_compact

SinceVersion 1.2.0

array_compact

description

从数组中删除连续的重复元素,结果值的顺序由源数组中的顺序决定。

Syntax

Array<T> array_compact(arr)

Arguments

arr — 需要处理的数组.

Returned value

不存在连续重复元素的数组.

Type: Array.

notice

只支持在向量化引擎中使用。

example

  1. select array_compact([1, 2, 3, 3, null, null, 4, 4]);
  2. +----------------------------------------------------+
  3. | array_compact(ARRAY(1, 2, 3, 3, NULL, NULL, 4, 4)) |
  4. +----------------------------------------------------+
  5. | [1, 2, 3, NULL, 4] |
  6. +----------------------------------------------------+
  7. select array_compact(['aaa','aaa','bbb','ccc','ccccc',null, null,'dddd']);
  8. +-------------------------------------------------------------------------------+
  9. | array_compact(ARRAY('aaa', 'aaa', 'bbb', 'ccc', 'ccccc', NULL, NULL, 'dddd')) |
  10. +-------------------------------------------------------------------------------+
  11. | ['aaa', 'bbb', 'ccc', 'ccccc', NULL, 'dddd'] |
  12. +-------------------------------------------------------------------------------+
  13. select array_compact(['2015-03-13','2015-03-13']);
  14. +--------------------------------------------------+
  15. | array_compact(ARRAY('2015-03-13', '2015-03-13')) |
  16. +--------------------------------------------------+
  17. | ['2015-03-13'] |
  18. +--------------------------------------------------+

keywords

ARRAY,COMPACT,ARRAY_COMPACT