Skip to content

Commit 75569f4

Browse files
authored
Bug: removes a compliance test that fails and replaces with unit test (googleapis#1110)
* removes a compliance test that fails and replaces with unit test * Update tests/unit/test_select.py * Update tests/unit/test_select.py * Update tests/unit/test_select.py
1 parent f9324e3 commit 75569f4

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

tests/sqlalchemy_dialect_compliance/test_dialect_compliance.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
QuotedNameArgumentTest,
4848
SimpleUpdateDeleteTest as _SimpleUpdateDeleteTest,
4949
TimestampMicrosecondsTest as _TimestampMicrosecondsTest,
50+
WindowFunctionTest,
5051
)
5152

5253
from sqlalchemy.testing.suite.test_types import (
@@ -636,3 +637,6 @@ def test_no_results_for_non_returning_insert(cls):
636637
del LongNameBlowoutTest # Requires features (indexes, primary keys, etc., that BigQuery doesn't have.
637638
del PostCompileParamsTest # BQ adds backticks to bind parameters, causing failure of tests TODO: fix this?
638639
del QuotedNameArgumentTest # Quotes aren't allowed in BigQuery table names.
640+
del (
641+
WindowFunctionTest.test_window_rows_between
642+
) # test expects BQ to return sorted results

tests/unit/test_select.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,53 @@ def test_visit_mod_binary(faux_conn):
507507
expected = "MOD(`table`.`foo`, %(foo_1:INT64)s)"
508508

509509
assert result == expected
510+
511+
512+
def test_window_rows_between(faux_conn):
513+
"""This is a replacement for the
514+
'test_window_rows_between'
515+
test in sqlalchemy's suite of compliance tests.
516+
517+
Their test is expecting things in sorted order and BQ
518+
doesn't return sorted results the way they expect so that
519+
test fails.
520+
521+
Note: that test only appears in:
522+
sqlalchemy/lib/sqlalchemy/testing/suite/test_select.py
523+
in version 2.0.32. It appears as though that test will be
524+
replaced with a similar but new test called:
525+
'test_window_rows_between_w_caching'
526+
due to the fact the rows are part of the cache key right now and
527+
not handled as binds. This is related to sqlalchemy Issue #11515
528+
529+
It is expected the new test will also have the same sorting failure.
530+
"""
531+
532+
table = setup_table(
533+
faux_conn,
534+
"table",
535+
sqlalchemy.Column("id", sqlalchemy.String),
536+
sqlalchemy.Column("col1", sqlalchemy.Integer),
537+
sqlalchemy.Column("col2", sqlalchemy.Integer),
538+
)
539+
540+
stmt = sqlalchemy.select(
541+
sqlalchemy.func.max(table.c.col2).over(
542+
order_by=[table.c.col1],
543+
rows=(-5, 0),
544+
)
545+
)
546+
547+
sql = stmt.compile(
548+
dialect=faux_conn.dialect,
549+
compile_kwargs={"literal_binds": True},
550+
)
551+
552+
result = str(sql)
553+
expected = (
554+
"SELECT max(`table`.`col2`) "
555+
"OVER (ORDER BY `table`.`col1` "
556+
"ROWS BETWEEN 5 PRECEDING AND CURRENT ROW) AS `anon_1` \n" # newline character required here to match
557+
"FROM `table`"
558+
)
559+
assert result == expected

0 commit comments

Comments
 (0)