diff --git a/dask_sql/physical/rel/custom/tables.py b/dask_sql/physical/rel/custom/tables.py index 8ec1a2009..e6cc16477 100644 --- a/dask_sql/physical/rel/custom/tables.py +++ b/dask_sql/physical/rel/custom/tables.py @@ -29,7 +29,12 @@ class ShowTablesPlugin(BaseRelPlugin): def convert( self, sql: "org.apache.calcite.sql.SqlNode", context: "dask_sql.Context" ) -> DataContainer: - schema = str(sql.getSchema()).split(".")[-1] + schema = sql.getSchema() + if schema is not None: + schema = str(schema).split(".")[-1] + else: + schema = context.DEFAULT_SCHEMA_NAME + if schema not in context.schema: raise AttributeError(f"Schema {schema} is not defined.") diff --git a/planner/src/main/codegen/includes/show.ftl b/planner/src/main/codegen/includes/show.ftl index 1f36b5806..b30dd5cb0 100644 --- a/planner/src/main/codegen/includes/show.ftl +++ b/planner/src/main/codegen/includes/show.ftl @@ -22,11 +22,13 @@ SqlNode SqlShowSchemas() : SqlNode SqlShowTables() : { final Span s; - final SqlIdentifier schema; + SqlIdentifier schema = null; } { - { s = span(); } - schema = SimpleIdentifier() + { s = span(); } + ( + schema = SimpleIdentifier() + )? { return new SqlShowTables(s.end(this), schema); } diff --git a/planner/src/main/java/com/dask/sql/parser/SqlShowTables.java b/planner/src/main/java/com/dask/sql/parser/SqlShowTables.java index 5f7301f45..89c22d771 100644 --- a/planner/src/main/java/com/dask/sql/parser/SqlShowTables.java +++ b/planner/src/main/java/com/dask/sql/parser/SqlShowTables.java @@ -7,6 +7,7 @@ import org.apache.calcite.sql.parser.SqlParserPos; public class SqlShowTables extends SqlDescribeSchema { + public SqlShowTables(SqlParserPos pos, SqlIdentifier schemaName) { super(pos, schemaName); } @@ -15,6 +16,8 @@ public SqlShowTables(SqlParserPos pos, SqlIdentifier schemaName) { public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { writer.keyword("SHOW"); writer.keyword("TABLES"); - this.getSchema().unparse(writer, leftPrec, rightPrec); + if (this.getSchema() != null) { + this.getSchema().unparse(writer, leftPrec, rightPrec); + } } } diff --git a/tests/integration/test_show.py b/tests/integration/test_show.py index 893c91738..6e2af33d1 100644 --- a/tests/integration/test_show.py +++ b/tests/integration/test_show.py @@ -2,6 +2,8 @@ import pytest from pandas.testing import assert_frame_equal +from dask_sql import Context + try: import cudf except ImportError: @@ -95,3 +97,14 @@ def test_wrong_input(c): c.sql(f'SHOW COLUMNS FROM "{c.schema_name}"."table"') with pytest.raises(AttributeError): c.sql('SHOW TABLES FROM "wrong"') + + +def test_show_tables_no_schema(c): + c = Context() + + df = pd.DataFrame({"id": [0, 1]}) + c.create_table("test", df) + + actual_df = c.sql("show tables").compute() + expected_df = pd.DataFrame({"Table": ["test"]}) + assert_frame_equal(actual_df, expected_df)