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): ensure that dot-sql can be executed when column names are not provided #10028

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions ibis/backends/mssql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ def _get_schema_using_query(self, query: str) -> sch.Schema:
elif newtyp.is_timestamp():
newtyp = newtyp.copy(scale=scale)

if name is None:
name = util.gen_name("col")

schema[name] = newtyp

return sch.Schema(schema)
Expand Down
24 changes: 24 additions & 0 deletions ibis/backends/mssql/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,27 @@ def test_from_url():
)
result = new_con.sql("SELECT 1 AS [a]").to_pandas().a.iat[0]
assert result == 1


def test_dot_sql_with_unnamed_columns(con):
cpcloud marked this conversation as resolved.
Show resolved Hide resolved
expr = con.sql(
"SELECT CAST('2024-01-01 00:00:00' AS DATETIMEOFFSET), 'a' + 'b', 1 AS [col42]"
)

schema = expr.schema()
names = schema.names

assert len(names) == 3

assert names[0].startswith("ibis_col")
assert names[1].startswith("ibis_col")
assert names[2] == "col42"

assert schema.types == (
dt.Timestamp(timezone="UTC", scale=7),
dt.String(nullable=False),
dt.Int32(nullable=False),
)

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