-
Notifications
You must be signed in to change notification settings - Fork 3.8k
basic docs for nested column query functions #12922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
clintropolis
merged 8 commits into
apache:master
from
clintropolis:nested-column-basic-docs
Aug 20, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fc77f4e
basic docs for nested column query functions
clintropolis 742de2a
fix terminal input accidentally typed in editor
clintropolis 7700e1a
Merge remote-tracking branch 'upstream/master' into nested-column-bas…
clintropolis 758ed62
review adjustments
clintropolis fc98b83
meh
clintropolis a84166c
more better
clintropolis bf3f2b6
more better
clintropolis 393512f
spelling
clintropolis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| --- | ||
| id: sql-json-functions | ||
| title: "SQL JSON functions" | ||
| sidebar_label: "JSON functions" | ||
| --- | ||
|
|
||
| <!-- | ||
| ~ Licensed to the Apache Software Foundation (ASF) under one | ||
| ~ or more contributor license agreements. See the NOTICE file | ||
| ~ distributed with this work for additional information | ||
| ~ regarding copyright ownership. The ASF licenses this file | ||
| ~ to you under the Apache License, Version 2.0 (the | ||
| ~ "License"); you may not use this file except in compliance | ||
| ~ with the License. You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, | ||
| ~ software distributed under the License is distributed on an | ||
| ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| ~ KIND, either express or implied. See the License for the | ||
| ~ specific language governing permissions and limitations | ||
| ~ under the License. | ||
| --> | ||
|
|
||
| <!-- | ||
| The format of the tables that describe the functions and operators | ||
| should not be changed without updating the script create-sql-docs | ||
| in web-console/script/create-sql-docs, because the script detects | ||
| patterns in this markdown file and parse it to TypeScript file for web console | ||
| --> | ||
|
|
||
| Druid supports nested columns, which provide optimized storage and indexes for nested data structures. Use | ||
| the following JSON functions to extract, transform, and create `COMPLEX<json>` values. | ||
|
|
||
| | Function | Notes | | ||
| | --- | --- | | ||
| |`JSON_KEYS(expr, path)`| Returns an array of field names from `expr` at the specified `path`.| | ||
| |`JSON_OBJECT(KEY expr1 VALUE expr2[, KEY expr3 VALUE expr4, ...])` | Constructs a new `COMPLEX<json>` object. The `KEY` expressions must evaluate to string types. The `VALUE` expressions can be composed of any input type, including other `COMPLEX<json>` values. `JSON_OBJECT` can accept colon-separated key-value pairs. The following syntax is equivalent: `JSON_OBJECT(expr1:expr2[, expr3:expr4, ...])`.| | ||
| |`JSON_PATHS(expr)`| Returns an array of all paths which refer to literal values in `expr` in JSONPath format. | | ||
| |`JSON_QUERY(expr, path)`| Extracts a `COMPLEX<json>` value from `expr`, at the specified `path`. | | ||
| |`JSON_VALUE(expr, path [RETURNING sqlType])`| Extracts a literal value from `expr` at the specified `path`. If you specify `RETURNING` and an SQL type name (such as `VARCHAR`, `BIGINT`, `DOUBLE`, etc) the function plans the query using the suggested type. Otherwise, it attempts to infer the type based on the context. If it can't infer the type, it defaults to `VARCHAR`.| | ||
| |`PARSE_JSON(expr)`|Parses `expr` into a `COMPLEX<json>` object. This operator deserializes JSON values when processing them, translating stringified JSON into a nested structure. If the input is not a `VARCHAR` or it is invalid JSON, this function will result in an error.| | ||
| |`TRY_PARSE_JSON(expr)`|Parses `expr` into a `COMPLEX<json>` object. This operator deserializes JSON values when processing them, translating stringified JSON into a nested structure. If the input is not a `VARCHAR` or it is invalid JSON, this function will result in a `NULL` value.| | ||
| |`TO_JSON_STRING(expr)`|Serializes `expr` into a JSON string.| | ||
|
|
||
| ### JSONPath syntax | ||
|
|
||
| Druid supports a subset of the [JSONPath syntax](https://github.com/json-path/JsonPath/blob/master/README.md) operators, primarily limited to extracting individual values from nested data structures. | ||
|
|
||
| |Operator|Description| | ||
| | --- | --- | | ||
| |`$`| Root element. All JSONPath expressions start with this operator. | | ||
| |`.<name>`| Child element in dot notation. | | ||
| |`['<name>']`| Child element in bracket notation. | | ||
| |`[<number>]`| Array index. | | ||
|
|
||
| Consider the following example input JSON: | ||
|
|
||
| ```json | ||
| {"x":1, "y":[1, 2, 3]} | ||
| ``` | ||
|
|
||
| - To return the entire JSON object:<br> | ||
| `$` -> `{"x":1, "y":[1, 2, 3]}` | ||
| - To return the value of the key "x":<br> | ||
| `$.x` -> `1` | ||
| - For a key that contains an array, to return the entire array:<br> | ||
| `$['y']` -> `[1, 2, 3]` | ||
| - For a key that contains an array, to return an item in the array:<br> | ||
| `$.y[1]` -> `2` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.