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

fix(mssql): allow temp=None #10289

Merged
merged 2 commits into from
Oct 9, 2024
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
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)