From 61dc09a296b35efad428415f4df74fff58585015 Mon Sep 17 00:00:00 2001 From: Weijun-H Date: Sun, 4 Aug 2024 10:52:25 +0800 Subject: [PATCH 1/2] doc: Add support for `map` and `make_map` functions --- .../source/user-guide/sql/scalar_functions.md | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/docs/source/user-guide/sql/scalar_functions.md b/docs/source/user-guide/sql/scalar_functions.md index 561824772af8c..bbecabd4a9291 100644 --- a/docs/source/user-guide/sql/scalar_functions.md +++ b/docs/source/user-guide/sql/scalar_functions.md @@ -3636,6 +3636,65 @@ Unwraps struct fields into columns. +-----------------------+-----------------------+ ``` +## Map Functions + +- [map](#map) +- [make_map](#make_map) + +### `map` + +Returns an Arrow map with the specified key-value pairs. + +``` +map(key, value) +``` + +#### Arguments + +- **key**: Expression to be used for key. + Can be a constant, column, or function, any combination of arithmetic or + string operators, or a named expression of previous listed. +- **value**: Expression to be used for value. + Can be a constant, column, or function, any combination of arithmetic or + string operators, or a named expression of previous listed. + +#### Example + +``` +SELECT MAP(['POST', 'HEAD', 'PATCH'], [41, 33, null]); +---- +{POST: 41, HEAD: 33, PATCH: } + +SELECT MAP([[1,2], [3,4]], ['a', 'b']); +---- +{[1, 2]: a, [3, 4]: b} +``` + +### `make_map` + +Returns an Arrow map with the specified key-value pairs. + +``` +make_map(key_1, value_1, ..., key_n, value_n) +``` + +#### Arguments + +- **key_n**: Expression to be used for key. + Can be a constant, column, or function, any combination of arithmetic or + string operators, or a named expression of previous listed. +- **value_n**: Expression to be used for value. + Can be a constant, column, or function, any combination of arithmetic or + string operators, or a named expression of previous listed. + +#### Example + +``` +SELECT MAKE_MAP('POST', 41, 'HEAD', 33, 'PATCH', null); +---- +{POST: 41, HEAD: 33, PATCH: } +``` + ## Hashing Functions - [digest](#digest) From 8cabdc58ffc303702f7e344fcdc69f9929a55d2c Mon Sep 17 00:00:00 2001 From: Weijun-H Date: Mon, 5 Aug 2024 10:29:23 +0800 Subject: [PATCH 2/2] chore: Add example for MAP --- docs/source/user-guide/sql/scalar_functions.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/source/user-guide/sql/scalar_functions.md b/docs/source/user-guide/sql/scalar_functions.md index bbecabd4a9291..c7490df04983e 100644 --- a/docs/source/user-guide/sql/scalar_functions.md +++ b/docs/source/user-guide/sql/scalar_functions.md @@ -3647,6 +3647,7 @@ Returns an Arrow map with the specified key-value pairs. ``` map(key, value) +map(key: value) ``` #### Arguments @@ -3668,6 +3669,10 @@ SELECT MAP(['POST', 'HEAD', 'PATCH'], [41, 33, null]); SELECT MAP([[1,2], [3,4]], ['a', 'b']); ---- {[1, 2]: a, [3, 4]: b} + +SELECT MAP { 'a': 1, 'b': 2 }; +---- +{a: 1, b: 2} ``` ### `make_map`