Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Mar 30, 2021

Rationale

Accessing the list of tables via select * from information_schema.tables (introduced in #9818) is a lot to type

See the doc for background: https://docs.google.com/document/d/12cpZUSNPqVH9Z0BBx6O8REu7TFqL-NPPAYCUPpDls1k/edit#

Proposal

Add support for SHOW TABLES command.

Commentary

This is different than both postgres (which uses \d in psql for this purpose), and MySQL (which uses DESCRIBE).

I could be convinced that we should not add SHOW TABLES at all (and just stay with select * from information_schema.tables but I wanted to add the proposal)

Example Use

Setup:

echo "1,Foo,44.9" > /tmp/table.csv
echo "2,Bar,22.1" >> /tmp/table.csv
cargo run --bin datafusion-cli

Then run :

CREATE EXTERNAL TABLE t(a int, b varchar, c float)
STORED AS CSV
LOCATION '/tmp/table.csv';

> show tables;
+---------------+--------------------+------------+------------+
| table_catalog | table_schema       | table_name | table_type |
+---------------+--------------------+------------+------------+
| datafusion    | public             | t          | BASE TABLE |
| datafusion    | information_schema | tables     | VIEW       |
+---------------+--------------------+------------+------------+
2 row in set. Query took 0 seconds.

@nevi-me nevi-me changed the title ARROW-12108: Implement SHOW TABLES ARROW-12108: [Rust] [DataFusion] Implement SHOW TABLES Mar 30, 2021
@github-actions
Copy link

@alamb
Copy link
Contributor Author

alamb commented Mar 31, 2021

FYI @Dandandan @returnString @andygrove -- what do you think about adding support for SHOW TABLES?

Copy link
Member

@andygrove andygrove 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. Thanks @alamb

Copy link
Member

@jorgecarleitao jorgecarleitao left a comment

Choose a reason for hiding this comment

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

:shipit: ! Nice and sweet. Also, great coverage 👍

@returnString
Copy link
Contributor

Great stuff - I think it's super useful as an accessible way to view the catalog structure outside of GUI tooling :)

@alamb alamb closed this in 9a37f35 Mar 31, 2021
@alamb
Copy link
Contributor Author

alamb commented Mar 31, 2021

Thanks all!

alamb added a commit that referenced this pull request Apr 6, 2021
# Rationale
Accessing the list of columns via `select * from information_schema.columns` (introduced in #9840) is a lot to type

See the doc for background: https://docs.google.com/document/d/12cpZUSNPqVH9Z0BBx6O8REu7TFqL-NPPAYCUPpDls1k/edit#

This is a sister PR to `SHOW TABLES` here:  #9847

# Proposal

Add support for `SHOW COLUMNS FROM <table>` command.

Following the MySQL syntax supported by sqlparser: https://dev.mysql.com/doc/refman/8.0/en/show-columns.html

# Example Use

Setup:
```
echo "1,Foo,44.9" > /tmp/table.csv
echo "2,Bar,22.1" >> /tmp/table.csv
cargo run --bin datafusion-cli
```

Then run :

```
> CREATE EXTERNAL TABLE t(a int, b varchar, c float)
STORED AS CSV
LOCATION '/tmp/table.csv';

 0 rows in set. Query took 0 seconds.

> show columns from t;
+---------------+--------------+------------+-------------+-----------+-------------+
| table_catalog | table_schema | table_name | column_name | data_type | is_nullable |
+---------------+--------------+------------+-------------+-----------+-------------+
| datafusion    | public       | t          | a           | Int32     | NO          |
| datafusion    | public       | t          | b           | Utf8      | NO          |
| datafusion    | public       | t          | c           | Float32   | NO          |
+---------------+--------------+------------+-------------+-----------+-------------+
3 row in set. Query took 0 seconds.
```

# Commentary

Note that the identifiers are case sensitive (which is a more general
problem that affects all name resolution, not just `SHOW COLUMNS`). Ideally this should also work:

```
> show columns from T;
Plan("Unknown relation for SHOW COLUMNS: T")

> select * from T;
Plan("Table or CTE with name \'T\' not found")
```

Closes #9866 from alamb/alamb/show_columns

Authored-by: Andrew Lamb <[email protected]>
Signed-off-by: Andrew Lamb <[email protected]>
pachadotdev pushed a commit to pachadotdev/arrow that referenced this pull request Apr 6, 2021
# Rationale
Accessing the list of columns via `select * from information_schema.columns` (introduced in apache#9840) is a lot to type

See the doc for background: https://docs.google.com/document/d/12cpZUSNPqVH9Z0BBx6O8REu7TFqL-NPPAYCUPpDls1k/edit#

This is a sister PR to `SHOW TABLES` here:  apache#9847

# Proposal

Add support for `SHOW COLUMNS FROM <table>` command.

Following the MySQL syntax supported by sqlparser: https://dev.mysql.com/doc/refman/8.0/en/show-columns.html

# Example Use

Setup:
```
echo "1,Foo,44.9" > /tmp/table.csv
echo "2,Bar,22.1" >> /tmp/table.csv
cargo run --bin datafusion-cli
```

Then run :

```
> CREATE EXTERNAL TABLE t(a int, b varchar, c float)
STORED AS CSV
LOCATION '/tmp/table.csv';

 0 rows in set. Query took 0 seconds.

> show columns from t;
+---------------+--------------+------------+-------------+-----------+-------------+
| table_catalog | table_schema | table_name | column_name | data_type | is_nullable |
+---------------+--------------+------------+-------------+-----------+-------------+
| datafusion    | public       | t          | a           | Int32     | NO          |
| datafusion    | public       | t          | b           | Utf8      | NO          |
| datafusion    | public       | t          | c           | Float32   | NO          |
+---------------+--------------+------------+-------------+-----------+-------------+
3 row in set. Query took 0 seconds.
```

# Commentary

Note that the identifiers are case sensitive (which is a more general
problem that affects all name resolution, not just `SHOW COLUMNS`). Ideally this should also work:

```
> show columns from T;
Plan("Unknown relation for SHOW COLUMNS: T")

> select * from T;
Plan("Table or CTE with name \'T\' not found")
```

Closes apache#9866 from alamb/alamb/show_columns

Authored-by: Andrew Lamb <[email protected]>
Signed-off-by: Andrew Lamb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants