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(deps): update dependency sqlglot to >=23.4,<25.18 #9935

Merged
merged 6 commits into from
Aug 29, 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
10 changes: 10 additions & 0 deletions ibis/backends/sql/compilers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,16 @@
# generate the SQL string
return parsed.sql(dialect)

def _make_sample_backwards_compatible(self, *, sample, parent):
# sample was changed to be owned by the table being sampled in 25.17.0
#
# this is a small workaround for backwards compatibility
if "this" in sample.__class__.arg_types:
sample.args["this"] = parent

Check warning on line 1645 in ibis/backends/sql/compilers/base.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/sql/compilers/base.py#L1645

Added line #L1645 was not covered by tests
else:
parent.args["sample"] = sample
return sg.select(STAR).from_(parent)


# `__init_subclass__` is uncalled for subclasses - we manually call it here to
# autogenerate the base class implementations as well.
Expand Down
4 changes: 2 additions & 2 deletions ibis/backends/sql/compilers/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ def visit_Sample(
self, op, *, parent, fraction: float, method: str, seed: int | None, **_
):
sample = sge.TableSample(
this=parent,
method="bernoulli" if method == "row" else "system",
percent=sge.convert(fraction * 100.0),
seed=None if seed is None else sge.convert(seed),
)
return sg.select(STAR).from_(sample)

return self._make_sample_backwards_compatible(sample=sample, parent=parent)

def visit_ArraySlice(self, op, *, arg, start, stop):
arg_length = self.f.len(arg)
Expand Down
8 changes: 8 additions & 0 deletions ibis/backends/sql/compilers/oracle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import string

import sqlglot as sg
import sqlglot.expressions as sge
import toolz
Expand Down Expand Up @@ -490,5 +492,11 @@ def visit_DateDelta(self, op, *, left, right, part):
)
return left - right

def visit_RStrip(self, op, *, arg):
return self.f.anon.rtrim(arg, string.whitespace)

def visit_LStrip(self, op, *, arg):
return self.f.anon.ltrim(arg, string.whitespace)


compiler = OracleCompiler()
7 changes: 2 additions & 5 deletions ibis/backends/sql/compilers/pyspark.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,8 @@ def visit_Sample(
raise com.UnsupportedOperationError(
"PySpark backend does not support sampling with seed."
)
sample = sge.TableSample(
this=parent,
percent=sge.convert(fraction * 100.0),
)
return sg.select(STAR).from_(sample)
sample = sge.TableSample(percent=sge.convert(int(fraction * 100.0)))
return self._make_sample_backwards_compatible(sample=sample, parent=parent)

def visit_WindowBoundary(self, op, *, value, preceding):
if isinstance(op.value, ops.Literal) and op.value.value == 0:
Expand Down
3 changes: 1 addition & 2 deletions ibis/backends/sql/compilers/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,12 +761,11 @@
self, op, *, parent, fraction: float, method: str, seed: int | None, **_
):
sample = sge.TableSample(
this=parent,
method="bernoulli" if method == "row" else "system",
percent=sge.convert(fraction * 100.0),
seed=None if seed is None else sge.convert(seed),
)
return sg.select(STAR).from_(sample)
return self._make_sample_backwards_compatible(sample=sample, parent=parent)

Check warning on line 768 in ibis/backends/sql/compilers/snowflake.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/sql/compilers/snowflake.py#L768

Added line #L768 was not covered by tests

def visit_ArrayMap(self, op, *, arg, param, body):
return self.f.transform(arg, sge.Lambda(this=body, expressions=[param]))
Expand Down
5 changes: 2 additions & 3 deletions ibis/backends/sql/compilers/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,16 @@ def _minimize_spec(start, end, spec):
def visit_Sample(
self, op, *, parent, fraction: float, method: str, seed: int | None, **_
):
if op.seed is not None:
if seed is not None:
raise com.UnsupportedOperationError(
"`Table.sample` with a random seed is unsupported"
)
sample = sge.TableSample(
this=parent,
method="bernoulli" if method == "row" else "system",
percent=sge.convert(fraction * 100.0),
seed=None if seed is None else sge.convert(seed),
)
return sg.select(STAR).from_(sample)
return self._make_sample_backwards_compatible(sample=sample, parent=parent)

def visit_Correlation(self, op, *, left, right, how, where):
if how == "sample":
Expand Down
1 change: 1 addition & 0 deletions ibis/backends/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,7 @@ def test_dynamic_table_slice_with_computed_offset(backend):
),
],
)
@pytest.mark.xfail_version(pyspark=["sqlglot==25.17.0"])
def test_sample(backend, method):
t = backend.functional_alltypes.filter(_.int_col >= 2)

Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ atpublic = ">=2.3,<6"
parsy = ">=2,<3"
python-dateutil = ">=2.8.2,<3"
pytz = ">=2022.7"
sqlglot = ">=23.4,<25.17"
sqlglot = ">=23.4,<25.18"
toolz = ">=0.11,<1"
typing-extensions = ">=4.3.0,<5"
numpy = { version = ">=1.23.2,<3", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ sortedcontainers==2.4.0 ; python_version >= "3.10" and python_version < "4.0"
soupsieve==2.6 ; python_version >= "3.10" and python_version < "3.13"
sphobjinv==2.3.1.1 ; python_version >= "3.10" and python_version < "3.13"
sqlalchemy==2.0.32 ; python_version >= "3.10" and python_version < "3.13"
sqlglot==25.16.1 ; python_version >= "3.10" and python_version < "4.0"
sqlglot==25.17.0 ; python_version >= "3.10" and python_version < "4.0"
stack-data==0.6.3 ; python_version >= "3.10" and python_version < "4.0"
statsmodels==0.14.2 ; python_version >= "3.10" and python_version < "3.13"
tabulate==0.9.0 ; python_version >= "3.10" and python_version < "3.13"
Expand Down