diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-07-11 19:40:59 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-07-11 19:40:59 -0400 |
| commit | 2aae37f93b413176d683259e0bc712728af931db (patch) | |
| tree | 8b46b2b4e60998a3131040be32c66a6d54cd93b3 | |
| parent | ca52e87268fec966f6005b1e4aa30206ae895e9e (diff) | |
| download | sqlalchemy-2aae37f93b413176d683259e0bc712728af931db.tar.gz | |
represent tablesample.sampling as FunctionElement in all cases
Fixed regression where the :func:`_sql.tablesample` construct would fail to
be executable when constructed given a floating-point sampling value not
embedded within a SQL function.
Fixes: #6735
Change-Id: I557bcd4bdbffc4329ad69d5659ba99b1c8deb554
| -rw-r--r-- | doc/build/changelog/unreleased_14/6735.rst | 7 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 12 | ||||
| -rw-r--r-- | test/sql/test_compare.py | 1 |
3 files changed, 14 insertions, 6 deletions
diff --git a/doc/build/changelog/unreleased_14/6735.rst b/doc/build/changelog/unreleased_14/6735.rst new file mode 100644 index 000000000..9e8a3f29c --- /dev/null +++ b/doc/build/changelog/unreleased_14/6735.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, sql, regression + :tickets: 6735 + + Fixed regression where the :func:`_sql.tablesample` construct would fail to + be executable when constructed given a floating-point sampling value not + embedded within a SQL function. diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 235c74ea7..42cb6e5ae 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -1970,18 +1970,18 @@ class TableSample(AliasedReturnsRows): sampling, name=name, seed=seed ) + @util.preload_module("sqlalchemy.sql.functions") def _init(self, selectable, sampling, name=None, seed=None): + functions = util.preloaded.sql_functions + if not isinstance(sampling, functions.Function): + sampling = functions.func.system(sampling) + self.sampling = sampling self.seed = seed super(TableSample, self)._init(selectable, name=name) - @util.preload_module("sqlalchemy.sql.functions") def _get_method(self): - functions = util.preloaded.sql_functions - if isinstance(self.sampling, functions.Function): - return self.sampling - else: - return functions.func.system(self.sampling) + return self.sampling class CTE( diff --git a/test/sql/test_compare.py b/test/sql/test_compare.py index e96a47553..365ed52b2 100644 --- a/test/sql/test_compare.py +++ b/test/sql/test_compare.py @@ -504,6 +504,7 @@ class CoreFixtures(object): .union_all(select(table_a.c.b)), select(table_a.c.a).lateral(), select(table_a.c.a).lateral(name="bar"), + table_a.tablesample(0.75), table_a.tablesample(func.bernoulli(1)), table_a.tablesample(func.bernoulli(1), seed=func.random()), table_a.tablesample(func.bernoulli(1), seed=func.other_random()), |
