Skip to content

Conversation

@djanderson
Copy link
Contributor

@djanderson djanderson commented Oct 23, 2025

Which issue does this PR close?

Rationale for this change

https://discord.com/channels/885562378132000778/1430237388474552380/1430618776751313018

What changes are included in this PR?

cargo run -q --bin datafusion-cli
DataFusion CLI v50.3.0
> DESCRIBE SELECT 1;
+-------------+-----------+-------------+
| column_name | data_type | is_nullable |
+-------------+-----------+-------------+
| Int64(1)    | Int64     | NO          |
+-------------+-----------+-------------+
1 row(s) fetched.
Elapsed 0.022 seconds.

Are these changes tested?

No, looking for feedback on approach first... happy to add a test.

Yes.

Are there any user-facing changes?

Yes, it changes to behavior of DESCRIBE SELECT from explaining the physical plan (EXPLAIN) to describing the schema of the query (like DESCRIBE table).

@github-actions github-actions bot added the sql SQL Planner label Oct 23, 2025
Copy link
Contributor

@adriangb adriangb left a comment

Choose a reason for hiding this comment

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

Amazing! Could you just add some tests for both the working case and the error case? Maybe also with something slightly more interesting than SELECT 1;

@djanderson
Copy link
Contributor Author

Amazing! Could you just add some tests for both the working case and the error case? Maybe also with something slightly more interesting than SELECT 1;

For sure. Is the NotImplemented error the route we want to take if the statement isn't a Query? If so, I'll add a few tests next.

@adriangb
Copy link
Contributor

Amazing! Could you just add some tests for both the working case and the error case? Maybe also with something slightly more interesting than SELECT 1;

For sure. Is the NotImplemented error the route we want to take if the statement isn't a Query? If so, I'll add a few tests next.

Yes I just don't know when that would be hit, it would be good to have an example of when that code path gets hit for future reference.

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 @djanderson and @adriangb

Since this is a behavior change I think, we probably need to

  1. Add a note in the upgrade guide
  2. Add some test coverage (.slt style)

1. simple describe select 1
2. a more complex query against table data
3. ensure that describing a non-query statement errors
@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Oct 25, 2025
@adriangb
Copy link
Contributor

Thank you for adding tests! I think the only thing missing is an entry in https://github.com/apache/datafusion/blob/main/docs/source/library-user-guide/upgrading.md

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Oct 26, 2025
@djanderson
Copy link
Contributor Author

djanderson commented Oct 26, 2025

@adriangb , done! But, as I was double checking currently documented behavior, I came upon https://datafusion.apache.org/user-guide/sql/ddl.html#describe, and I wasn't quite sure if a quick example about DESCRIBE query would fit appropriately within the DDL section?

@comphead
Copy link
Contributor

I would suggest to use a tree schema representation which was added recently #17459

because it supports nested types, outputting plain table for nested types like in this PR might be confusing

Also better follow the "<feature> not supported" not_impl_err message
convention used in this file, and significantly improve readability of
error by not debug printing the statement.
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.

This is great -- thank you @djanderson , @comphead and @adriangb

@alamb alamb added the api change Changes the API exposed to users of the crate label Oct 26, 2025
@alamb alamb changed the title Implement DESCRIBE SELECT Implement DESCRIBE SELECT to show schema rather than EXPLAIN plan Oct 26, 2025
@alamb alamb added this pull request to the merge queue Oct 26, 2025
Merged via the queue into apache:main with commit e2516e2 Oct 26, 2025
30 checks passed
@djanderson
Copy link
Contributor Author

I would suggest to use a tree schema representation which was added recently #17459

because it supports nested types, outputting plain table for nested types like in this PR might be confusing

@comphead, If you have an idea of how you'd like this approached, feel free to drop some notes in an issue and assign me! I looked into it a bit last night and couldn't figure out how to trivially make that change. Would it require a new DescribeQuery logical plan type so that queries and tables can have different describe output formats downstream?

@djanderson djanderson deleted the describe-select branch October 26, 2025 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api change Changes the API exposed to users of the crate documentation Improvements or additions to documentation sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make DESCRIBE SELECT 1; work

4 participants