Skip to content

Commit 4f5d5a5

Browse files
committed
remove system_time
1 parent eb4aa00 commit 4f5d5a5

File tree

24 files changed

+141
-129
lines changed

24 files changed

+141
-129
lines changed

packages/bigframes/tests/unit/core/compile/sqlglot/tpch/conftest.py

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,21 @@
1313
# limitations under the License.
1414

1515
import datetime
16+
import functools
1617
import unittest.mock as mock
1718

1819
import pytest
1920
from google.cloud import bigquery
2021

2122
import bigframes.testing.mocks as mocks
23+
from bigframes.testing import compiler_session
2224

2325
freezegun = pytest.importorskip("freezegun")
2426

27+
PROJECT_NAME = "bigframes-dev-perf"
28+
DATASET_NAME = "tpch_0001t"
29+
LOCATION_NAME = "test-region"
30+
2531
TPCH_SCHEMAS = {
2632
"LINEITEM": [
2733
bigquery.SchemaField("L_ORDERKEY", "INTEGER", mode="REQUIRED"),
@@ -103,48 +109,55 @@
103109
}
104110

105111

112+
def _create_mock_bqclient():
113+
"""Helper function to create a compiler session."""
114+
115+
bqclient = mock.create_autospec(bigquery.Client, instance=True)
116+
bqclient.project = DATASET_NAME
117+
bqclient.location = LOCATION_NAME
118+
table_create_time = datetime.datetime.now()
119+
120+
def get_table_mock(table_ref):
121+
if isinstance(table_ref, str):
122+
table_ref = bigquery.TableReference.from_string(table_ref)
123+
124+
table_id = table_ref.table_id
125+
schema = TPCH_SCHEMAS.get(table_id, [])
126+
127+
table = mock.create_autospec(bigquery.Table, instance=True)
128+
table._properties = {}
129+
type(table).created = mock.PropertyMock(return_value=table_create_time)
130+
type(table).location = mock.PropertyMock(return_value=LOCATION_NAME)
131+
type(table).schema = mock.PropertyMock(return_value=schema)
132+
type(table).project = table_ref.project
133+
type(table).dataset_id = table_ref.dataset_id
134+
type(table).table_id = table_id
135+
type(table).num_rows = mock.PropertyMock(return_value=1000000000)
136+
return table
137+
138+
bqclient.get_table.side_effect = get_table_mock
139+
return bqclient
140+
141+
106142
@pytest.fixture(scope="session")
107143
def tpch_session():
108-
from bigframes.testing import compiler_session
109-
110144
anonymous_dataset = bigquery.DatasetReference.from_string(
111-
"bigframes-dev-perf.tpch_0001t"
145+
f"{PROJECT_NAME}.{DATASET_NAME}"
112146
)
113-
location = "us-central1"
114-
115-
with freezegun.freeze_time("2026-04-05 18:00:00"):
116-
session = mocks.create_bigquery_session(
117-
anonymous_dataset=anonymous_dataset,
118-
location=location,
119-
)
120-
121-
def get_table_mock(table_ref):
122-
if isinstance(table_ref, str):
123-
table_ref = bigquery.TableReference.from_string(table_ref)
124-
125-
table_id = table_ref.table_id
126-
schema = TPCH_SCHEMAS.get(table_id, [])
127-
128-
table = mock.create_autospec(bigquery.Table, instance=True)
129-
table._properties = {}
130-
# mocks.create_bigquery_session's CURRENT_TIMESTAMP() returns offset-naive datetime.now()
131-
# So we should also use offset-naive here to avoid comparison errors.
132-
now = datetime.datetime.now()
133-
type(table).schema = mock.PropertyMock(return_value=schema)
134-
type(table).project = table_ref.project
135-
type(table).dataset_id = table_ref.dataset_id
136-
type(table).table_id = table_id
137-
type(table).num_rows = mock.PropertyMock(return_value=1000000)
138-
type(table).num_bytes = mock.PropertyMock(return_value=1000000)
139-
type(table).location = mock.PropertyMock(return_value=location)
140-
type(table).table_type = mock.PropertyMock(return_value="TABLE")
141-
type(table).created = mock.PropertyMock(return_value=now)
142-
type(table).modified = mock.PropertyMock(return_value=now)
143-
type(table).range_partitioning = mock.PropertyMock(return_value=None)
144-
type(table).time_partitioning = mock.PropertyMock(return_value=None)
145-
type(table).clustering_fields = mock.PropertyMock(return_value=None)
146-
return table
147-
148-
session.bqclient.get_table.side_effect = get_table_mock
149-
session._executor = compiler_session.SQLCompilerExecutor()
150-
return session
147+
session = mocks.create_bigquery_session(
148+
bqclient=_create_mock_bqclient(),
149+
anonymous_dataset=anonymous_dataset,
150+
)
151+
152+
# Disable snapshotting for TPC-H tests to keep snapshots clean
153+
original_read_gbq_table = session._loader.read_gbq_table
154+
155+
@functools.wraps(original_read_gbq_table)
156+
def read_gbq_table_no_snapshot(*args, **kwargs):
157+
kwargs["enable_snapshot"] = False
158+
return original_read_gbq_table(*args, **kwargs)
159+
160+
session._loader.read_gbq_table = read_gbq_table_no_snapshot
161+
162+
session._executor = compiler_session.SQLCompilerExecutor()
163+
return session

packages/bigframes/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/1/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ WITH `bfcte_0` AS (
3838
) * (
3939
1.0 + `L_TAX`
4040
) AS `bfcol_47`
41-
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
41+
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_0`
4242
WHERE
4343
`L_SHIPDATE` <= CAST('1998-09-02' AS DATE)
4444
), `bfcte_1` AS (

packages/bigframes/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/10/out.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ WITH `bfcte_0` AS (
22
SELECT
33
`N_NATIONKEY` AS `bfcol_0`,
44
`N_NAME` AS `bfcol_1`
5-
FROM `bigframes-dev-perf`.`tpch_0001t`.`NATION` AS `bft_3` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
5+
FROM `bigframes-dev-perf`.`tpch_0001t`.`NATION` AS `bft_3`
66
), `bfcte_1` AS (
77
SELECT
88
`L_ORDERKEY` AS `bfcol_2`,
99
`L_EXTENDEDPRICE` AS `bfcol_3`,
1010
`L_DISCOUNT` AS `bfcol_4`,
1111
`L_RETURNFLAG` AS `bfcol_5`
12-
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
12+
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_2`
1313
), `bfcte_2` AS (
1414
SELECT
1515
`O_ORDERKEY` AS `bfcol_6`,
1616
`O_CUSTKEY` AS `bfcol_7`,
1717
`O_ORDERDATE` AS `bfcol_8`
18-
FROM `bigframes-dev-perf`.`tpch_0001t`.`ORDERS` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
18+
FROM `bigframes-dev-perf`.`tpch_0001t`.`ORDERS` AS `bft_1`
1919
), `bfcte_3` AS (
2020
SELECT
2121
`C_CUSTKEY` AS `bfcol_9`,
@@ -25,7 +25,7 @@ WITH `bfcte_0` AS (
2525
`C_PHONE` AS `bfcol_13`,
2626
`C_ACCTBAL` AS `bfcol_14`,
2727
`C_COMMENT` AS `bfcol_15`
28-
FROM `bigframes-dev-perf`.`tpch_0001t`.`CUSTOMER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
28+
FROM `bigframes-dev-perf`.`tpch_0001t`.`CUSTOMER` AS `bft_0`
2929
), `bfcte_4` AS (
3030
SELECT
3131
`bfcol_9` AS `bfcol_16`,

packages/bigframes/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/11/out.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ WITH `bfcte_0` AS (
77
`PS_SUPPKEY` AS `bfcol_0`,
88
`PS_AVAILQTY` AS `bfcol_1`,
99
`PS_SUPPLYCOST` AS `bfcol_2`
10-
FROM `bigframes-dev-perf`.`tpch_0001t`.`PARTSUPP` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
10+
FROM `bigframes-dev-perf`.`tpch_0001t`.`PARTSUPP` AS `bft_2`
1111
), `bfcte_2` AS (
1212
SELECT
1313
`PS_PARTKEY` AS `bfcol_10`,
1414
`PS_SUPPKEY` AS `bfcol_11`,
1515
`PS_AVAILQTY` AS `bfcol_12`,
1616
`PS_SUPPLYCOST` AS `bfcol_13`
17-
FROM `bigframes-dev-perf`.`tpch_0001t`.`PARTSUPP` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
17+
FROM `bigframes-dev-perf`.`tpch_0001t`.`PARTSUPP` AS `bft_2`
1818
), `bfcte_3` AS (
1919
SELECT
2020
`S_SUPPKEY` AS `bfcol_3`,
2121
`S_NATIONKEY` AS `bfcol_4`
22-
FROM `bigframes-dev-perf`.`tpch_0001t`.`SUPPLIER` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
22+
FROM `bigframes-dev-perf`.`tpch_0001t`.`SUPPLIER` AS `bft_1`
2323
), `bfcte_4` AS (
2424
SELECT
2525
`N_NATIONKEY` AS `bfcol_18`
26-
FROM `bigframes-dev-perf`.`tpch_0001t`.`NATION` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
26+
FROM `bigframes-dev-perf`.`tpch_0001t`.`NATION` AS `bft_0`
2727
WHERE
2828
`N_NAME` = 'GERMANY'
2929
), `bfcte_5` AS (

packages/bigframes/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/12/out.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ WITH `bfcte_0` AS (
55
`L_COMMITDATE` AS `bfcol_2`,
66
`L_RECEIPTDATE` AS `bfcol_3`,
77
`L_SHIPMODE` AS `bfcol_4`
8-
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
8+
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_1`
99
), `bfcte_1` AS (
1010
SELECT
1111
`O_ORDERKEY` AS `bfcol_5`,
1212
`O_ORDERPRIORITY` AS `bfcol_6`
13-
FROM `bigframes-dev-perf`.`tpch_0001t`.`ORDERS` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
13+
FROM `bigframes-dev-perf`.`tpch_0001t`.`ORDERS` AS `bft_0`
1414
), `bfcte_2` AS (
1515
SELECT
1616
`bfcol_5`,

packages/bigframes/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/13/out.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ WITH `bfcte_0` AS (
22
SELECT
33
`O_ORDERKEY` AS `bfcol_10`,
44
`O_CUSTKEY` AS `bfcol_11`
5-
FROM `bigframes-dev-perf`.`tpch_0001t`.`ORDERS` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
5+
FROM `bigframes-dev-perf`.`tpch_0001t`.`ORDERS` AS `bft_1`
66
WHERE
77
NOT (
88
REGEXP_CONTAINS(`O_COMMENT`, 'special.*requests')
99
)
1010
), `bfcte_1` AS (
1111
SELECT
1212
`C_CUSTKEY` AS `bfcol_3`
13-
FROM `bigframes-dev-perf`.`tpch_0001t`.`CUSTOMER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
13+
FROM `bigframes-dev-perf`.`tpch_0001t`.`CUSTOMER` AS `bft_0`
1414
), `bfcte_2` AS (
1515
SELECT
1616
`bfcol_3`,

packages/bigframes/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/14/out.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ WITH `bfcte_0` AS (
1212
`L_EXTENDEDPRICE` AS `bfcol_1`,
1313
`L_DISCOUNT` AS `bfcol_2`,
1414
`L_SHIPDATE` AS `bfcol_3`
15-
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
15+
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_1`
1616
), `bfcte_3` AS (
1717
SELECT
1818
`P_PARTKEY` AS `bfcol_4`
19-
FROM `bigframes-dev-perf`.`tpch_0001t`.`PART` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
19+
FROM `bigframes-dev-perf`.`tpch_0001t`.`PART` AS `bft_0`
2020
), `bfcte_4` AS (
2121
SELECT
2222
`P_PARTKEY` AS `bfcol_8`,
2323
`P_TYPE` AS `bfcol_9`
24-
FROM `bigframes-dev-perf`.`tpch_0001t`.`PART` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
24+
FROM `bigframes-dev-perf`.`tpch_0001t`.`PART` AS `bft_0`
2525
), `bfcte_5` AS (
2626
SELECT
2727
`bfcol_4`,

packages/bigframes/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/15/out.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ WITH `bfcte_0` AS (
2121
`L_EXTENDEDPRICE` * (
2222
1 - `L_DISCOUNT`
2323
) AS `bfcol_24`
24-
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
24+
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_1`
2525
WHERE
2626
(
2727
`L_SHIPDATE` >= CAST('1996-01-01' AS DATE)
@@ -32,14 +32,14 @@ WITH `bfcte_0` AS (
3232
), `bfcte_2` AS (
3333
SELECT
3434
`S_SUPPKEY` AS `bfcol_4`
35-
FROM `bigframes-dev-perf`.`tpch_0001t`.`SUPPLIER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
35+
FROM `bigframes-dev-perf`.`tpch_0001t`.`SUPPLIER` AS `bft_0`
3636
), `bfcte_3` AS (
3737
SELECT
3838
`S_SUPPKEY` AS `bfcol_8`,
3939
`S_NAME` AS `bfcol_9`,
4040
`S_ADDRESS` AS `bfcol_10`,
4141
`S_PHONE` AS `bfcol_11`
42-
FROM `bigframes-dev-perf`.`tpch_0001t`.`SUPPLIER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
42+
FROM `bigframes-dev-perf`.`tpch_0001t`.`SUPPLIER` AS `bft_0`
4343
), `bfcte_4` AS (
4444
SELECT
4545
`bfcol_23`,

packages/bigframes/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/16/out.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ WITH `bfcte_0` AS (
66
NOT (
77
REGEXP_CONTAINS(`S_COMMENT`, 'Customer.*Complaints')
88
) AS `bfcol_9`
9-
FROM `bigframes-dev-perf`.`tpch_0001t`.`SUPPLIER` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
9+
FROM `bigframes-dev-perf`.`tpch_0001t`.`SUPPLIER` AS `bft_2`
1010
WHERE
1111
NOT (
1212
REGEXP_CONTAINS(`S_COMMENT`, 'Customer.*Complaints')
@@ -15,14 +15,14 @@ WITH `bfcte_0` AS (
1515
SELECT
1616
`PS_PARTKEY` AS `bfcol_2`,
1717
`PS_SUPPKEY` AS `bfcol_3`
18-
FROM `bigframes-dev-perf`.`tpch_0001t`.`PARTSUPP` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
18+
FROM `bigframes-dev-perf`.`tpch_0001t`.`PARTSUPP` AS `bft_1`
1919
), `bfcte_2` AS (
2020
SELECT
2121
`P_PARTKEY` AS `bfcol_4`,
2222
`P_BRAND` AS `bfcol_5`,
2323
`P_TYPE` AS `bfcol_6`,
2424
`P_SIZE` AS `bfcol_7`
25-
FROM `bigframes-dev-perf`.`tpch_0001t`.`PART` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
25+
FROM `bigframes-dev-perf`.`tpch_0001t`.`PART` AS `bft_0`
2626
), `bfcte_3` AS (
2727
SELECT
2828
`bfcol_8`

packages/bigframes/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/17/out.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WITH `bfcte_0` AS (
55
), `bfcte_1` AS (
66
SELECT
77
`P_PARTKEY` AS `bfcol_15`
8-
FROM `bigframes-dev-perf`.`tpch_0001t`.`PART` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
8+
FROM `bigframes-dev-perf`.`tpch_0001t`.`PART` AS `bft_1`
99
WHERE
1010
(
1111
`P_BRAND` = 'Brand#23'
@@ -17,12 +17,12 @@ WITH `bfcte_0` AS (
1717
`L_PARTKEY` AS `bfcol_3`,
1818
`L_QUANTITY` AS `bfcol_4`,
1919
`L_EXTENDEDPRICE` AS `bfcol_5`
20-
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
20+
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_0`
2121
), `bfcte_3` AS (
2222
SELECT
2323
`L_PARTKEY` AS `bfcol_6`,
2424
`L_QUANTITY` AS `bfcol_7`
25-
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-04-05T18:00:00'
25+
FROM `bigframes-dev-perf`.`tpch_0001t`.`LINEITEM` AS `bft_0`
2626
), `bfcte_4` AS (
2727
SELECT
2828
`bfcol_4` AS `bfcol_16`,

0 commit comments

Comments
 (0)