Skip to content

Conversation

@LiuYuHui
Copy link
Contributor

Which issue does this PR close?

Closes #2606.

Rationale for this change

What changes are included in this PR?

When the user executes the DESCRIBE <table>, the output will be the following.

❯ 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.013 seconds.
❯ describe foo;
+-------------+-----------+-------------+
| column_name | data_type | is_nullable |
+-------------+-----------+-------------+
| column1     | Int64     | YES         |
+-------------+-----------+-------------+
1 row in set. Query took 0.016 seconds.

Are there any user-facing changes?

Does this PR break compatibility with Ballista?

@github-actions github-actions bot added datafusion sql SQL Planner labels May 29, 2022
Copy link
Contributor

@liukun4515 liukun4515 left a comment

Choose a reason for hiding this comment

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

LGTM

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 for the contribution @LiuYuHui ! This is a great start.

I tried it out locally and it doesn't seem to work quite right yet:

(arrow_dev) alamb@MacBook-Pro-6:~/Software/arrow-datafusion/datafusion-cli$ cargo run
...
DataFusion CLI v8.0.0
❯ CREATE OR REPLACE TABLE y AS VALUES (1,2),(3,4);
+---------+---------+
| column1 | column2 |
+---------+---------+
| 1       | 2       |
| 3       | 4       |
+---------+---------+
2 rows in set. Query took 0.062 seconds.
❯ describe table;
0 rows in set. Query took 0.032 seconds.
❯ describe table y;  🤔 Invalid statement: sql parser error: Expected end of statement, found: y

Also, can you please add a test (perhaps you can use he example above).

It might be nice to add a test here:
https://github.com/LiuYuHui/arrow-datafusion/blob/describe_table/datafusion/core/tests/sql/information_schema.rs#L223

which you can run with a command like cargo test --test sql_integration

@LiuYuHui
Copy link
Contributor Author

Hi @alamb, thanks for your review, currently this PR only implements describe table_name, the describe table table_name is not implemented, this is why your test case has an error, should I also implement the describe table table_name?

@alamb
Copy link
Contributor

alamb commented May 30, 2022

Hi @alamb, thanks for your review, currently this PR only implements describe table_name, the describe table table_name is not implemented, this is why your test case has an error, should I also implement the describe table table_name?

🤦 -- no sorry @LiuYuHui I was mistaken on the syntax of describe -- no need to implement describe table foo

I tried the correct syntax and it works great 👍

❯ describe y;
+-------------+-----------+-------------+
| column_name | data_type | is_nullable |
+-------------+-----------+-------------+
| column1     | Int64     | YES         |
| column2     | Int64     | YES         |
+-------------+-----------+-------------+
2 rows in set. Query took 0.006 seconds.

However, I do think this PR needs a test.

Also, would it be possible to generate an error if the table didn't exist?

For example, mysql does the following for a non existent table:

mysql> describe ff;
ERROR 1146 (42S02): Table 'foo.ff' doesn't exist

But this PR returns an empty row:

❯ describe table;
0 rows in set. Query took 0.020 seconds.

@github-actions github-actions bot added the core Core DataFusion crate label May 31, 2022
@LiuYuHui
Copy link
Contributor Author

@alamb, I have fixed the nonexistent table case and added the test, please take a look.

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 PR looks great now @LiuYuHui -- thank you very much

I tried it out locally too and 👍

@alamb alamb merged commit be57cf6 into apache:master May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support DESCRIBE <table> to show table schemas

4 participants