array_with_constant

array_with_constant

description

Syntax

  1. ARRAY<T> array_with_constant(n, T)
  2. ARRAY<T> array_repeat(T, n)

get array of constants with n length, array_repeat has the same function as array_with_constant and is used to be compatible with the hive syntax format

example

  1. mysql> select array_with_constant(2, "hello"), array_repeat("hello", 2);
  2. +---------------------------------+--------------------------+
  3. | array_with_constant(2, 'hello') | array_repeat('hello', 2) |
  4. +---------------------------------+--------------------------+
  5. | ['hello', 'hello'] | ['hello', 'hello'] |
  6. +---------------------------------+--------------------------+
  7. 1 row in set (0.04 sec)
  8. mysql> select array_with_constant(3, 12345), array_repeat(12345, 3);
  9. +-------------------------------+------------------------+
  10. | array_with_constant(3, 12345) | array_repeat(12345, 3) |
  11. +-------------------------------+------------------------+
  12. | [12345, 12345, 12345] | [12345, 12345, 12345] |
  13. +-------------------------------+------------------------+
  14. 1 row in set (0.01 sec)
  15. mysql> select array_with_constant(3, null), array_repeat(null, 3);
  16. +------------------------------+-----------------------+
  17. | array_with_constant(3, NULL) | array_repeat(NULL, 3) |
  18. +------------------------------+-----------------------+
  19. | [NULL, NULL, NULL] | [NULL, NULL, NULL] |
  20. +------------------------------+-----------------------+
  21. 1 row in set (0.01 sec)
  22. mysql> select array_with_constant(null, 3), array_repeat(3, null);
  23. +------------------------------+-----------------------+
  24. | array_with_constant(NULL, 3) | array_repeat(3, NULL) |
  25. +------------------------------+-----------------------+
  26. | [] | [] |
  27. +------------------------------+-----------------------+
  28. 1 row in set (0.01 sec)

keywords

ARRAY,WITH_CONSTANT,ARRAY_WITH_CONSTANT,ARRAY_REPEAT