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

CREATE EXTERNAL TABLE from CSV creates a table with no columns if there is just a header row #3263

Closed
andygrove opened this issue Aug 25, 2022 · 4 comments · Fixed by #3272
Closed
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@andygrove
Copy link
Member

Describe the bug

CREATE EXTERNAL TABLE from CSV creates a table with no columns if there is just a header row.

To Reproduce

Create test file:

echo "station_id,date,val,type" > weather.csv

In datafusion-cli:

CREATE EXTERNAL TABLE weather STORED AS CSV WITH HEADER ROW LOCATION 'weather.csv';

Table is created:

❯ show tables;
+---------------+--------------------+------------+------------+
| table_catalog | table_schema       | table_name | table_type |
+---------------+--------------------+------------+------------+
| datafusion    | public             | weather    | BASE TABLE |
| datafusion    | information_schema | tables     | VIEW       |
| datafusion    | information_schema | views      | VIEW       |
| datafusion    | information_schema | columns    | VIEW       |
+---------------+--------------------+------------+------------+

But it has no columns:

❯ 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 |
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+-------------------------+---------------+--------------------+---------------+
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+-------------------------+---------------+--------------------+---------------+

Works fine if there is data:

❯ 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       | weather    | station_id  | 0                |                | NO          | Int64     |                          |                        |                   |                         |               |                    |               |
| datafusion    | public       | weather    | date        | 1                |                | NO          | Date32    |                          |                        |                   |                         |               |                    |               |
| datafusion    | public       | weather    | val         | 2                |                | NO          | Int64     |                          |                        |                   |                         |               |                    |               |
| datafusion    | public       | weather    | type        | 3                |                | NO          | Utf8      |                          | 2147483647             |                   |                         |               |                    |               |
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+-------------------------+---------------+--------------------+---------------+

Expected behavior
See above

Additional context
None

@andygrove andygrove added bug Something isn't working good first issue Good for newcomers labels Aug 25, 2022
@comphead
Copy link
Contributor

@andygrove I'll take it

@sadilet
Copy link

sadilet commented Aug 26, 2022

@comphead Hey, sorry, I didn't see your comment yesterday. I've started investigating this as soon as this issue got out, next time will notify about that and avoid such cases.

@comphead
Copy link
Contributor

@sadilet :) looks like we submitted PRs the same time.
@andygrove you can take any you like.

@sadilet
Copy link

sadilet commented Aug 26, 2022

@comphead Your code has tests. It makes sense to close my PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
3 participants