Skip to content

Commit

Permalink
fix(mssql): allow temp=None (#10289)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored Oct 9, 2024
1 parent 7d98330 commit ea1c179
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ibis/backends/mssql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def create_table(
*,
schema: sch.SchemaLike | None = None,
database: str | None = None,
temp: bool = False,
temp: bool | None = None,
overwrite: bool = False,
) -> ir.Table:
"""Create a new table.
Expand Down Expand Up @@ -682,7 +682,7 @@ def create_table(
raw_table = sg.table(temp_name, catalog=catalog, db=db, quoted=False)
target = sge.Schema(
this=sg.table(
"#" * temp + temp_name, catalog=catalog, db=db, quoted=quoted
"#" * bool(temp) + temp_name, catalog=catalog, db=db, quoted=quoted
),
expressions=schema.to_sqlglot(self.dialect),
)
Expand All @@ -701,7 +701,7 @@ def create_table(
# for the subsequent `Insert`, so we need to shove a `#` in
# front of the table identifier.
_table = sg.table(
"##" * temp + temp_name,
"##" * bool(temp) + temp_name,
catalog=catalog,
db=db,
quoted=self.compiler.quoted,
Expand Down
35 changes: 35 additions & 0 deletions ibis/backends/mssql/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
MSSQL_PYODBC_DRIVER,
MSSQL_USER,
)
from ibis.backends.tests.errors import PyODBCProgrammingError
from ibis.util import gen_name

RAW_DB_TYPES = [
# Exact numbers
Expand Down Expand Up @@ -259,3 +261,36 @@ def test_dot_sql_with_unnamed_columns(con):

df = expr.execute()
assert len(df) == 1


@pytest.mark.parametrize(
"temp",
[
param(
True,
marks=pytest.mark.xfail(
raises=PyODBCProgrammingError,
reason="dropping temp tables isn't implemented",
),
),
False,
None,
],
ids=[
"temp",
"no-temp",
"no-temp-none",
],
)
def test_create_temp_table(con, temp):
t = con.create_table(
name := gen_name("mssql_delete_me"),
schema={"a": "int"},
temp=temp,
)
try:
assert int(t.count().execute()) == 0
assert t.schema() == ibis.schema({"a": "int"})
assert t.columns == ("a",)
finally:
con.drop_table(name)

0 comments on commit ea1c179

Please sign in to comment.