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

Support DESCRIBE <table> to show table schemas #2606

Closed
alamb opened this issue May 24, 2022 · 2 comments · Fixed by #2642
Closed

Support DESCRIBE <table> to show table schemas #2606

alamb opened this issue May 24, 2022 · 2 comments · Fixed by #2642
Assignees
Labels
datafusion Changes in the datafusion crate enhancement New feature or request good first issue Good for newcomers

Comments

@alamb
Copy link
Contributor

alamb commented May 24, 2022

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
DataFusion mostly follows postgres when it comes to compatibility. However, it also supports some usability features from mysql, notably SHOW TABLES;

It would be nice to also get basic schema information (column names, types) about a table using DESCRIBE <TABLE>

Describe the solution you'd like

I would like to run this sequence of commands and get a nicely formatted output other than an error:

❯ create table foo as select * from (values (1), (3), (2), (10), (8));
+---------+
| column1 |
+---------+
| 1       |
| 3       |
| 2       |
| 10      |
| 8       |
+---------+
5 rows in set. Query took 0.005 seconds.
❯ show tables;
+---------------+--------------------+------------+------------+
| table_catalog | table_schema       | table_name | table_type |
+---------------+--------------------+------------+------------+
| datafusion    | public             | foo        | BASE TABLE |
| datafusion    | information_schema | tables     | VIEW       |
| datafusion    | information_schema | columns    | VIEW       |
+---------------+--------------------+------------+------------+
3 rows in set. Query took 0.001 seconds.
❯ describe foo;
NotImplemented("Unsupported SQL statement: ExplainTable { describe_alias: true, table_name: ObjectName([Ident { value: \"foo\", quote_style: None }]) }")

Here is what mysql does (the table definition is different than the example above):

mysql> describe foo;
+-------+---------------+------+-----+---------+-------+
| Field | Type          | Null | Key | Default | Extra |
+-------+---------------+------+-----+---------+-------+
| bar   | set('a','b')  | YES  |     | NULL    |       |
| baz   | enum('a','b') | YES  |     | NULL    |       |
+-------+---------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

Note that the information is accesable via information_schema so this ticket would just plumbing it all together:

select * from information_schema.columns;
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+-------------------------+---------------+--------------------+---------------+
| table_catalog | table_schema | table_name | column_name | ordinal_position | column_default | is_nullable | data_type | character_maximum_length | character_octet_length | numeric_precision | numeric_precision_radix | numeric_scale | datetime_precision | interval_type |
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+-------------------------+---------------+--------------------+---------------+
| datafusion    | public       | foo        | column1     | 0                |                | YES         | Int64     |                          |                        |                   |                         |               |                    |               |
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+-------------------------+---------------+--------------------+---------------+
1 row in set. Query took 0.004 seconds.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@alamb alamb added enhancement New feature or request good first issue Good for newcomers datafusion Changes in the datafusion crate labels May 24, 2022
@alamb alamb changed the title Support DESCRIBE <table> Support DESCRIBE <table> to show table schemas May 24, 2022
@LiuYuHui
Copy link
Contributor

Hi @alamb, can I work on this? I want to learn the implementation of datafusion by implementing this.

@xudong963
Copy link
Member

Hi @alamb, can I work on this? I want to learn the implementation of datafusion by implementing this.

Feel free to pick it, fighting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datafusion Changes in the datafusion crate enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants