Skip to content
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

(WIP) Add docs for json_table #20338

Closed
wants to merge 1 commit into from
Closed

Conversation

mosabua
Copy link
Member

@mosabua mosabua commented Jan 10, 2024

Description

Not even really started .. just getting my thoughts together. Currently I plan to add this to the json functions page .. and maybe also link from the table functions page .. will see how it goes.

Will rely on specs, tests, and help from @kasiafi and @martint .. but not yet.

Additional context and related issues

Release notes

(x) This is not user-visible or is docs only, and no release notes are required.

@cla-bot cla-bot bot added the cla-signed label Jan 10, 2024
@github-actions github-actions bot added the docs label Jan 10, 2024
@mosabua mosabua changed the title Add docs for json_table (WIP) Add docs for json_table Jan 15, 2024
)
```


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One example which i put together:

trino> SELECT
    ->   *
    -> FROM
    ->   json_table (
    ->     '[{"id":1,"name":"Africa","wikiDataId":"Q15"},{"id":2,"name":"Americas","wikiDataId":"Q828"},{"id":3,"name":"Asia","wikiDataId":"Q48"},{"id":4,"name":"Europe","wikiDataId":"Q51"}]',
    ->     'lax $' COLUMNS (
    ->         NESTED PATH 'lax $[*]' AS nested_path COLUMNS (
    ->             id integer path 'lax $[*].id',
    ->             name varchar path 'lax $[*].name',
    ->             wiki_data_id varchar path 'lax $[*]."wikiDataId"')));
 ID |   NAME   | WIKI_DATA_ID 
----+----------+--------------
  1 | Africa   | Q15          
  2 | Americas | Q828         
  3 | Asia     | Q48          
  4 | Europe   | Q51          
(4 rows)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the [*] in $[*].id, $[*].name and '$[*].wikiDataId, since the elements of the top-level array are not arrays. It happens to work because you're using lax`, which does some conversions automatically and is more lenient. This would be the proper form:

SELECT
  *
FROM
  json_table (
	'[{"id":1,"name":"Africa","wikiDataId":"Q15"},{"id":2,"name":"Americas","wikiDataId":"Q828"},{"id":3,"name":"Asia","wikiDataId":"Q48"},{"id":4,"name":"Europe","wikiDataId":"Q51"}]',
	'strict $' COLUMNS (
		NESTED PATH 'strict $[*]' AS nested_path COLUMNS (
			id integer path 'strict $.id',
			name varchar path 'strict $.name',
			wiki_data_id varchar path 'strict $."wikiDataId"')));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @findinpath and @martint .. I barely started but I will look at the various test cases and such to create some examples as well as details the different sections of the table function.

@mosabua mosabua added the stale-ignore Use this label on PRs that should be ignored by the stale bot so they are not flagged or closed. label Apr 11, 2024
@mosabua mosabua closed this Nov 27, 2024
@mosabua
Copy link
Member Author

mosabua commented Nov 27, 2024

Replaced by PR from @michaeleby1

@mosabua mosabua deleted the json_table branch November 27, 2024 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed docs stale-ignore Use this label on PRs that should be ignored by the stale bot so they are not flagged or closed.
Development

Successfully merging this pull request may close these issues.

3 participants