Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dask_sql/physical/rel/custom/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down
8 changes: 5 additions & 3 deletions planner/src/main/codegen/includes/show.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ SqlNode SqlShowSchemas() :
SqlNode SqlShowTables() :
{
final Span s;
final SqlIdentifier schema;
SqlIdentifier schema = null;
}
{
<SHOW> { s = span(); } <TABLES> <FROM>
schema = SimpleIdentifier()
<SHOW> { s = span(); } <TABLES>
(
<FROM> schema = SimpleIdentifier()
)?
{
return new SqlShowTables(s.end(this), schema);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
}
}
13 changes: 13 additions & 0 deletions tests/integration/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pytest
from pandas.testing import assert_frame_equal

from dask_sql import Context

try:
import cudf
except ImportError:
Expand Down Expand Up @@ -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)