From 54129115924e9fe8d61f48d61737c723c9ebe92f Mon Sep 17 00:00:00 2001 From: avogar Date: Fri, 28 Oct 2022 17:43:07 +0000 Subject: [PATCH 1/7] Add documentation for 'format' table function --- .../sql-reference/table-functions/format.md | 75 +++++++++++++++++++ .../sql-reference/table-functions/format.md | 1 + .../sql-reference/table-functions/format,md | 1 + 3 files changed, 77 insertions(+) create mode 100644 docs/en/sql-reference/table-functions/format.md create mode 120000 docs/ru/sql-reference/table-functions/format.md create mode 120000 docs/zh/sql-reference/table-functions/format,md diff --git a/docs/en/sql-reference/table-functions/format.md b/docs/en/sql-reference/table-functions/format.md new file mode 100644 index 00000000000..bc0ada9795b --- /dev/null +++ b/docs/en/sql-reference/table-functions/format.md @@ -0,0 +1,75 @@ +--- +slug: /en/sql-reference/table-functions/format +sidebar_position: 56 +sidebar_label: format +--- + +# format + +Extracts table structure from data and parse it according to specified input format. + +**Syntax** + +``` sql +format(format_name, data) +``` + +**Parameters** + +- `format_name` — The [format](../../interfaces/formats.md#formats) of the data. +- `data` — String literal containing data in specified format + +**Returned value** + +A table with data parsed from `data` argument according specified format and extracted schema. + +**Examples** + +**Query:** +``` sql +:) select * from format(JSONEachRow, +$$ +{"a": "Hello", "b": 111} +{"a": "World", "b": 123} +{"a": "Hello", "b": 112} +{"a": "World", "b": 124} +$$) +``` + +**Result:** + +```text +┌───b─┬─a─────┐ +│ 111 │ Hello │ +│ 123 │ World │ +│ 112 │ Hello │ +│ 124 │ World │ +└─────┴───────┘ +``` + +**Query:** +```sql + +:) desc format(JSONEachRow, +$$ +{"a": "Hello", "b": 111} +{"a": "World", "b": 123} +{"a": "Hello", "b": 112} +{"a": "World", "b": 124} +$$) +``` + +**Result:** + +```text +┌─name─┬─type──────────────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┐ +│ b │ Nullable(Float64) │ │ │ │ │ │ +│ a │ Nullable(String) │ │ │ │ │ │ +└──────┴───────────────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┘ +``` + +**See Also** + +- [Formats](../../interfaces/formats.md) + +[Original article](https://clickhouse.com/docs/en/sql-reference/table-functions/format) diff --git a/docs/ru/sql-reference/table-functions/format.md b/docs/ru/sql-reference/table-functions/format.md new file mode 120000 index 00000000000..cc5e3a5a142 --- /dev/null +++ b/docs/ru/sql-reference/table-functions/format.md @@ -0,0 +1 @@ +../../../en/sql-reference/table-functions/format.md \ No newline at end of file diff --git a/docs/zh/sql-reference/table-functions/format,md b/docs/zh/sql-reference/table-functions/format,md new file mode 120000 index 00000000000..cc5e3a5a142 --- /dev/null +++ b/docs/zh/sql-reference/table-functions/format,md @@ -0,0 +1 @@ +../../../en/sql-reference/table-functions/format.md \ No newline at end of file From c7031569b66671a1f8eeda5b3a78c0cb7de5d651 Mon Sep 17 00:00:00 2001 From: avogar Date: Fri, 28 Oct 2022 21:58:34 +0000 Subject: [PATCH 2/7] Fix typo --- docs/zh/sql-reference/table-functions/{format,md => format.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/zh/sql-reference/table-functions/{format,md => format.md} (100%) diff --git a/docs/zh/sql-reference/table-functions/format,md b/docs/zh/sql-reference/table-functions/format.md similarity index 100% rename from docs/zh/sql-reference/table-functions/format,md rename to docs/zh/sql-reference/table-functions/format.md From 800e789ac44292cd59823fd0a736fc6110b27d11 Mon Sep 17 00:00:00 2001 From: Alexander Gololobov <440544+davenger@users.noreply.github.com> Date: Sat, 29 Oct 2022 09:26:16 +0200 Subject: [PATCH 3/7] Small fix --- docs/en/sql-reference/table-functions/format.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/sql-reference/table-functions/format.md b/docs/en/sql-reference/table-functions/format.md index bc0ada9795b..da287c77283 100644 --- a/docs/en/sql-reference/table-functions/format.md +++ b/docs/en/sql-reference/table-functions/format.md @@ -6,7 +6,7 @@ sidebar_label: format # format -Extracts table structure from data and parse it according to specified input format. +Extracts table structure from data and parses it according to specified input format. **Syntax** From 95e64310a611e4c01ca6376bc8ab8c9480268a8f Mon Sep 17 00:00:00 2001 From: Kruglov Pavel <48961922+Avogar@users.noreply.github.com> Date: Tue, 1 Nov 2022 14:06:45 +0100 Subject: [PATCH 4/7] Update format.md --- docs/en/sql-reference/table-functions/format.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/sql-reference/table-functions/format.md b/docs/en/sql-reference/table-functions/format.md index da287c77283..4d1488ea640 100644 --- a/docs/en/sql-reference/table-functions/format.md +++ b/docs/en/sql-reference/table-functions/format.md @@ -17,7 +17,7 @@ format(format_name, data) **Parameters** - `format_name` — The [format](../../interfaces/formats.md#formats) of the data. -- `data` — String literal containing data in specified format +- `data` — String literal or constant expression that returns a string containing data in specified format **Returned value** From 9d9bca3dbba9ce0d413ae9da85808eb31549fa13 Mon Sep 17 00:00:00 2001 From: avogar Date: Tue, 1 Nov 2022 14:08:34 +0000 Subject: [PATCH 5/7] Add embedded documentation --- src/TableFunctions/TableFunctionFormat.cpp | 67 +++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/src/TableFunctions/TableFunctionFormat.cpp b/src/TableFunctions/TableFunctionFormat.cpp index 9f239adb538..15a82044dab 100644 --- a/src/TableFunctions/TableFunctionFormat.cpp +++ b/src/TableFunctions/TableFunctionFormat.cpp @@ -89,9 +89,72 @@ StoragePtr TableFunctionFormat::executeImpl(const ASTPtr & /*ast_function*/, Con return res; } +static const Documentation format_table_function_documentation = +{ + R"( +Extracts table structure from data and parses it according to specified input format. +Syntax: `format(format_name, data)`. +Parameters: + - `format_name` - the format of the data. + - `data ` - String literal or constant expression that returns a string containing data in specified format. +Returned value: A table with data parsed from `data` argument according specified format and extracted schema. +)", + Documentation::Examples + { + { + "First example", + R"( +Query: +``` +:) select * from format(JSONEachRow, +$$ +{"a": "Hello", "b": 111} +{"a": "World", "b": 123} +{"a": "Hello", "b": 112} +{"a": "World", "b": 124} +$$) +``` + +Result: +``` +┌───b─┬─a─────┐ +│ 111 │ Hello │ +│ 123 │ World │ +│ 112 │ Hello │ +│ 124 │ World │ +└─────┴───────┘ +``` +)" + }, + { + "Second example", + R"( +Query: +``` +:) desc format(JSONEachRow, +$$ +{"a": "Hello", "b": 111} +{"a": "World", "b": 123} +{"a": "Hello", "b": 112} +{"a": "World", "b": 124} +$$) +``` + +Result: +``` +┌─name─┬─type──────────────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┐ +│ b │ Nullable(Float64) │ │ │ │ │ │ +│ a │ Nullable(String) │ │ │ │ │ │ +└──────┴───────────────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┘ +``` +)" + }, + }, + Documentation::Categories{"format", "table-functions"} +}; + void registerTableFunctionFormat(TableFunctionFactory & factory) { - factory.registerFunction({}, TableFunctionFactory::CaseInsensitive); + factory.registerFunction(format_table_function_documentation, TableFunctionFactory::CaseInsensitive); } - } From ca708dd4b6d52e0f29f163c017f49b8d4761ce09 Mon Sep 17 00:00:00 2001 From: Kruglov Pavel <48961922+Avogar@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:25:09 +0100 Subject: [PATCH 6/7] Fix test --- .../02414_all_new_table_functions_must_be_documented.reference | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/queries/0_stateless/02414_all_new_table_functions_must_be_documented.reference b/tests/queries/0_stateless/02414_all_new_table_functions_must_be_documented.reference index bb8c8c2228a..2277e19cf25 100644 --- a/tests/queries/0_stateless/02414_all_new_table_functions_must_be_documented.reference +++ b/tests/queries/0_stateless/02414_all_new_table_functions_must_be_documented.reference @@ -3,7 +3,6 @@ clusterAllReplicas dictionary executable file -format generateRandom input jdbc From 831abbaff94e3efadc5d816b999d304cc961a3f7 Mon Sep 17 00:00:00 2001 From: Kruglov Pavel <48961922+Avogar@users.noreply.github.com> Date: Mon, 14 Nov 2022 17:29:30 +0100 Subject: [PATCH 7/7] Fix build --- src/TableFunctions/TableFunctionFormat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TableFunctions/TableFunctionFormat.cpp b/src/TableFunctions/TableFunctionFormat.cpp index 15a82044dab..b15b350f00b 100644 --- a/src/TableFunctions/TableFunctionFormat.cpp +++ b/src/TableFunctions/TableFunctionFormat.cpp @@ -155,6 +155,6 @@ Result: void registerTableFunctionFormat(TableFunctionFactory & factory) { - factory.registerFunction(format_table_function_documentation, TableFunctionFactory::CaseInsensitive); + factory.registerFunction({format_table_function_documentation, false}, TableFunctionFactory::CaseInsensitive); } }