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

[Feature] support describe file #4995

Merged
merged 1 commit into from
Jan 24, 2023
Merged

Conversation

xiaoyong-z
Copy link
Contributor

To know the columns/types in a file, users has to create an external table, and describe the table. Sometimes the infer schema is wrong for creating table, to make it right, user need to drop the table, and recreate a table with the specify schema. To solve this problem, we add describe file interface in datafusion-clie, With the Describe File, user can know the infer schema is wrong before creating the table.

Syntax:
Describe file_path,

Example:
DESCRIBE 'tests/data/aggregate_simple_pipe.csv';

Return:
column_name data_type is_nullable
c1 Float32 NO
c2 Float64 NO
c3 Boolean NO

Signed-off-by: xyz a997647204@gmail.com

Which issue does this PR close?

Closes #4913

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels Jan 20, 2023
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 @xiaoyong-z -- this looks like a good start. I would like to see the implementation for describe file be the same as describe table if possible, and I have left some comments to that effect.

datafusion/core/src/datasource/listing/table.rs Outdated Show resolved Hide resolved
CREATE external table aggregate_simple(c1 real, c2 double, c3 boolean) STORED as CSV WITH HEADER ROW LOCATION 'tests/data/aggregate_simple.csv';

query C1
DESCRIBE aggregate_simple;
Copy link
Contributor

Choose a reason for hiding this comment

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

This test works on master -- I don't think it needs the changes in this PR

(arrow_dev) alamb@MacBook-Pro-8:~/Software/arrow-datafusion/datafusion/core$ datafusion-cli
DataFusion CLI v16.0.0
❯ CREATE external table aggregate_simple(c1 real, c2 double, c3 boolean) STORED as CSV WITH HEADER ROW LOCATION 'tests/data/aggregate_simple.csv';
0 rows in set. Query took 0.005 seconds.
❯ 
DESCRIBE aggregate_simple;
+-------------+-----------+-------------+
| column_name | data_type | is_nullable |
+-------------+-----------+-------------+
| c1          | Float32   | NO          |
| c2          | Float64   | NO          |
| c3          | Boolean   | NO          |
+-------------+-----------+-------------+
3 rows in set. Query took 0.002 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.

there is no sqllogictests to test describe, so i add some tests here, now i unify the describe table and describe file, and i think it's necessary to add some tests to this.

datafusion/sql/src/statement.rs Outdated Show resolved Hide resolved
datafusion/expr/src/logical_plan/plan.rs Outdated Show resolved Hide resolved
To know the columns/types in a file, users has to create an external table, and describe the table.
Sometimes the infer schema is wrong for creating table, to make it right, user need to drop the table, and recreate a table with the specify schema.
To solve this problem, we add describe file interface in datafusion-clie, With the Describe File, user can know the infer schema is wrong before creating the table.

Syntax:
Describe file_path,

Example:
DESCRIBE 'tests/data/aggregate_simple_pipe.csv';

Return:
column_name data_type is_nullable
c1 Float32 NO
c2 Float64 NO
c3 Boolean NO

Signed-off-by: xyz <a997647204@gmail.com>
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 makes sense to me -- thank you @xiaoyong-z ❤️

@alamb alamb merged commit ab00bc1 into apache:master Jan 24, 2023
@ursabot
Copy link

ursabot commented Jan 24, 2023

Benchmark runs are scheduled for baseline = 9f498bb and contender = ab00bc1. ab00bc1 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules sql SQL Planner sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Describe FILE in datafusion-cli
3 participants