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

Docs: Add unnest to SQL Reference #10839

Merged
merged 5 commits into from
Jun 11, 2024

Conversation

gloomweaver
Copy link
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you so much @gloomweaver -- this is great. I have another suggestion for documenting unnest for structs as well.

| 5 |
+------------------------------------------------------------------+
```

Copy link
Contributor

Choose a reason for hiding this comment

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

unnest also works for structs. Can you possibly add this example too?

> create table foo as values (named_struct('a', 5, 'b', 'a string'));
0 row(s) fetched.
Elapsed 0.008 seconds.

> select * from foo;
+---------------------+
| column1             |
+---------------------+
| {a: 5, b: a string} |
+---------------------+
1 row(s) fetched.
Elapsed 0.003 seconds.

> select unnest(column1) from foo;
+-----------------------+-----------------------+
| unnest(foo.column1).a | unnest(foo.column1).b |
+-----------------------+-----------------------+
| 5                     | a string              |
+-----------------------+-----------------------+
1 row(s) fetched.
Elapsed 0.003 seconds.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could merge this PR as is, as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sure. This should be in Struct Functions right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also love to add a range example

select unnest(range(0, 100000))

Copy link
Contributor

@alamb alamb Jun 11, 2024

Choose a reason for hiding this comment

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

Yeah, sure. This should be in Struct Functions right?

I think that would make sense.

FWIW here is an example:

DataFusion CLI v39.0.0
> select unnest(range(0, 10));
+-----------------------------------+
| unnest(range(Int64(0),Int64(10))) |
+-----------------------------------+
| 0                                 |
| 1                                 |
| 2                                 |
| 3                                 |
| 4                                 |
| 5                                 |
| 6                                 |
| 7                                 |
| 8                                 |
| 9                                 |
+-----------------------------------+
10 row(s) fetched.
Elapsed 0.054 seconds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added docs for struct unnest and example this range for array.
Couldn't link to it because of the name.
Is there a way to assign custom id to a block with sphinx? Tried labels, didn't work, so named it unnest (struct).

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to assign custom id to a block with sphinx? Tried labels, didn't work, so named it unnest (struct).

I am not sure to be honest

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

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

love it, thanks @gloomweaver

@comphead
Copy link
Contributor

@gloomweaver please run the prettier locally, it will reformat the MD files a little bit

@comphead
Copy link
Contributor

  # if you encounter error, rerun the command below and commit the changes
  #
  # ignore subproject CHANGELOG.md because they are machine generated
  npx [email protected] --write \
    '{datafusion,datafusion-cli,datafusion-examples,dev,docs}/**/*.md' \
    '!datafusion/CHANGELOG.md' \
    README.md \
    CONTRIBUTING.md

@alamb
Copy link
Contributor

alamb commented Jun 11, 2024

I took the liberty of running prettier locally to save @gloomweaver the trouble of installing it locally

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks so much @gloomweaver and @comphead

@@ -3480,6 +3524,34 @@ select named_struct('field_a', a, 'field_b', b) from t;
Can be a constant, column, or function, and any combination of arithmetic or
string operators.


### `unnest (struct)`
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@alamb alamb merged commit d84d75a into apache:main Jun 11, 2024
4 checks passed
@alamb
Copy link
Contributor

alamb commented Jun 11, 2024

Thanks again @gloomweaver and @comphead

@gloomweaver gloomweaver deleted the add-unnest-to-sql-reference branch June 11, 2024 21:36
findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
* Add unnest to SQL Reference

* Add unnest docs for struct, add additional example for unnest array

* unnest -> unnest (struct)

* prettier

---------

Co-authored-by: Andrew Lamb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants