Skip to content

Commit c670f9d

Browse files
authored
chore: add scalars_types_df for compiler tests (#1831)
1 parent ac55aae commit c670f9d

File tree

12 files changed

+202
-154
lines changed

12 files changed

+202
-154
lines changed

bigframes/testing/mocks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def create_bigquery_session(
4141
bqclient: Optional[mock.Mock] = None,
4242
session_id: str = "abcxyz",
4343
table_schema: Sequence[google.cloud.bigquery.SchemaField] = TEST_SCHEMA,
44+
table_name: str = "test_table",
4445
anonymous_dataset: Optional[google.cloud.bigquery.DatasetReference] = None,
4546
location: str = "test-region",
4647
ordering_mode: Literal["strict", "partial"] = "partial",
@@ -76,7 +77,7 @@ def create_bigquery_session(
7677
type(table).schema = mock.PropertyMock(return_value=table_schema)
7778
type(table).project = anonymous_dataset.project
7879
type(table).dataset_id = anonymous_dataset.dataset_id
79-
type(table).table_id = "test_table"
80+
type(table).table_id = table_name
8081
type(table).num_rows = mock.PropertyMock(return_value=1000000000)
8182
bqclient.get_table.return_value = table
8283

@@ -94,7 +95,7 @@ def query_mock(
9495
query_job = mock.create_autospec(google.cloud.bigquery.QueryJob, instance=True)
9596
query_job._properties = {}
9697
type(query_job).destination = mock.PropertyMock(
97-
return_value=anonymous_dataset.table("test_table"),
98+
return_value=anonymous_dataset.table(table_name),
9899
)
99100
type(query_job).statement_type = mock.PropertyMock(return_value="SELECT")
100101

tests/unit/core/compile/sqlglot/conftest.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import pytest
2222

2323
from bigframes import dtypes
24+
import bigframes.pandas as bpd
2425
import bigframes.testing.mocks as mocks
2526
import bigframes.testing.utils
2627

@@ -29,26 +30,52 @@
2930

3031

3132
@pytest.fixture(scope="session")
32-
def compiler_session(basic_types_table_schema):
33+
def compiler_session(scalars_types_table_schema):
3334
from bigframes.testing import compiler_session
3435

3536
# TODO: Check if ordering mode is needed for the tests.
36-
session = mocks.create_bigquery_session(table_schema=basic_types_table_schema)
37+
table_name = "scalar_types"
38+
anonymous_dataset = bigquery.DatasetReference.from_string(
39+
"bigframes-dev.sqlglot_test"
40+
)
41+
session = mocks.create_bigquery_session(
42+
table_name=table_name,
43+
table_schema=scalars_types_table_schema,
44+
anonymous_dataset=anonymous_dataset,
45+
)
3746
session._executor = compiler_session.SQLCompilerExecutor()
3847
return session
3948

4049

4150
@pytest.fixture(scope="session")
42-
def basic_types_table_schema() -> typing.Sequence[bigquery.SchemaField]:
51+
def scalars_types_table_schema() -> typing.Sequence[bigquery.SchemaField]:
4352
return [
44-
bigquery.SchemaField("rowindex", "INTEGER"),
53+
bigquery.SchemaField("bool_col", "BOOLEAN"),
54+
bigquery.SchemaField("bytes_col", "BYTES"),
55+
bigquery.SchemaField("date_col", "DATE"),
56+
bigquery.SchemaField("datetime_col", "DATETIME"),
57+
bigquery.SchemaField("geography_col", "GEOGRAPHY"),
4558
bigquery.SchemaField("int64_col", "INTEGER"),
46-
bigquery.SchemaField("string_col", "STRING"),
59+
bigquery.SchemaField("int64_too", "INTEGER"),
60+
bigquery.SchemaField("numeric_col", "NUMERIC"),
4761
bigquery.SchemaField("float64_col", "FLOAT"),
48-
bigquery.SchemaField("bool_col", "BOOLEAN"),
62+
bigquery.SchemaField("rowindex", "INTEGER"),
63+
bigquery.SchemaField("rowindex_2", "INTEGER"),
64+
bigquery.SchemaField("string_col", "STRING"),
65+
bigquery.SchemaField("time_col", "TIME"),
66+
bigquery.SchemaField("timestamp_col", "TIMESTAMP"),
4967
]
5068

5169

70+
@pytest.fixture(scope="session")
71+
def scalars_types_df(compiler_session) -> bpd.DataFrame:
72+
"""Returns a BigFrames DataFrame containing all scalar types and using the `rowindex`
73+
column as the index."""
74+
bf_df = compiler_session.read_gbq_table("bigframes-dev.sqlglot_test.scalar_types")
75+
bf_df = bf_df.set_index("rowindex", drop=False)
76+
return bf_df
77+
78+
5279
@pytest.fixture(scope="session")
5380
def scalars_types_pandas_df() -> pd.DataFrame:
5481
"""Returns a pandas DataFrame containing all scalar types and using the `rowindex`
Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`rowindex` AS `bfcol_0`,
4-
`int64_col` AS `bfcol_1`,
5-
`string_col` AS `bfcol_2`,
6-
`float64_col` AS `bfcol_3`,
7-
`bool_col` AS `bfcol_4`
8-
FROM `test-project`.`test_dataset`.`test_table`
3+
`int64_col` AS `bfcol_0`,
4+
`rowindex` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
96
), `bfcte_1` AS (
107
SELECT
11-
*,
12-
`bfcol_0` AS `bfcol_5`,
13-
`bfcol_2` AS `bfcol_6`,
14-
`bfcol_3` AS `bfcol_7`,
15-
`bfcol_4` AS `bfcol_8`,
16-
`bfcol_1` + 1 AS `bfcol_9`
8+
`bfcol_1` AS `bfcol_2`,
9+
`bfcol_0` AS `bfcol_3`
1710
FROM `bfcte_0`
1811
), `bfcte_2` AS (
1912
SELECT
20-
`bfcol_5` AS `bfcol_10`,
21-
`bfcol_9` AS `bfcol_11`,
22-
`bfcol_6` AS `bfcol_12`,
23-
`bfcol_7` AS `bfcol_13`,
24-
`bfcol_8` AS `bfcol_14`
13+
*,
14+
`bfcol_2` AS `bfcol_4`,
15+
`bfcol_3` + 1 AS `bfcol_5`
2516
FROM `bfcte_1`
17+
), `bfcte_3` AS (
18+
SELECT
19+
`bfcol_4` AS `bfcol_6`,
20+
`bfcol_5` AS `bfcol_7`
21+
FROM `bfcte_2`
2622
)
2723
SELECT
28-
`bfcol_10` AS `rowindex`,
29-
`bfcol_11` AS `int64_col`,
30-
`bfcol_12` AS `string_col`,
31-
`bfcol_13` AS `float64_col`,
32-
`bfcol_14` AS `bool_col`
33-
FROM `bfcte_2`
24+
`bfcol_6` AS `rowindex`,
25+
`bfcol_7` AS `int64_col`
26+
FROM `bfcte_3`
Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,53 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`rowindex` AS `bfcol_0`,
4-
`int64_col` AS `bfcol_1`,
5-
`string_col` AS `bfcol_2`,
6-
`float64_col` AS `bfcol_3`,
7-
`bool_col` AS `bfcol_4`
8-
FROM `test-project`.`test_dataset`.`test_table`
3+
`bool_col` AS `bfcol_0`,
4+
`bytes_col` AS `bfcol_1`,
5+
`date_col` AS `bfcol_2`,
6+
`datetime_col` AS `bfcol_3`,
7+
`geography_col` AS `bfcol_4`,
8+
`int64_col` AS `bfcol_5`,
9+
`int64_too` AS `bfcol_6`,
10+
`numeric_col` AS `bfcol_7`,
11+
`float64_col` AS `bfcol_8`,
12+
`rowindex` AS `bfcol_9`,
13+
`rowindex_2` AS `bfcol_10`,
14+
`string_col` AS `bfcol_11`,
15+
`time_col` AS `bfcol_12`,
16+
`timestamp_col` AS `bfcol_13`
17+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
18+
), `bfcte_1` AS (
19+
SELECT
20+
`bfcol_9` AS `bfcol_14`,
21+
`bfcol_0` AS `bfcol_15`,
22+
`bfcol_1` AS `bfcol_16`,
23+
`bfcol_2` AS `bfcol_17`,
24+
`bfcol_3` AS `bfcol_18`,
25+
`bfcol_4` AS `bfcol_19`,
26+
`bfcol_5` AS `bfcol_20`,
27+
`bfcol_6` AS `bfcol_21`,
28+
`bfcol_7` AS `bfcol_22`,
29+
`bfcol_8` AS `bfcol_23`,
30+
`bfcol_9` AS `bfcol_24`,
31+
`bfcol_10` AS `bfcol_25`,
32+
`bfcol_11` AS `bfcol_26`,
33+
`bfcol_12` AS `bfcol_27`,
34+
`bfcol_13` AS `bfcol_28`
35+
FROM `bfcte_0`
936
)
1037
SELECT
11-
`bfcol_0` AS `rowindex`,
12-
`bfcol_1` AS `int64_col`,
13-
`bfcol_2` AS `string_col`,
14-
`bfcol_3` AS `float64_col`,
15-
`bfcol_4` AS `bool_col`
16-
FROM `bfcte_0`
38+
`bfcol_14` AS `rowindex`,
39+
`bfcol_15` AS `bool_col`,
40+
`bfcol_16` AS `bytes_col`,
41+
`bfcol_17` AS `date_col`,
42+
`bfcol_18` AS `datetime_col`,
43+
`bfcol_19` AS `geography_col`,
44+
`bfcol_20` AS `int64_col`,
45+
`bfcol_21` AS `int64_too`,
46+
`bfcol_22` AS `numeric_col`,
47+
`bfcol_23` AS `float64_col`,
48+
`bfcol_24` AS `rowindex_1`,
49+
`bfcol_25` AS `rowindex_2`,
50+
`bfcol_26` AS `string_col`,
51+
`bfcol_27` AS `time_col`,
52+
`bfcol_28` AS `timestamp_col`
53+
FROM `bfcte_1`
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`rowindex` AS `bfcol_0`,
4-
`int64_col` AS `bfcol_1`,
5-
`string_col` AS `bfcol_2`,
6-
`float64_col` AS `bfcol_3`,
7-
`bool_col` AS `bfcol_4`
8-
FROM `test-project`.`test_dataset`.`test_table`
3+
`int64_col` AS `bfcol_0`,
4+
`rowindex` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
`bfcol_1` AS `bfcol_2`,
9+
`bfcol_0` AS `bfcol_3`
10+
FROM `bfcte_0`
911
)
1012
SELECT
11-
`bfcol_0` AS `rowindex`,
12-
`bfcol_1` AS `int64_col`,
13-
`bfcol_2` AS `string_col`,
14-
`bfcol_3` AS `float64_col`,
15-
`bfcol_4` AS `bool_col`
16-
FROM `bfcte_0`
13+
`bfcol_2` AS `rowindex`,
14+
`bfcol_3` AS `int64_col`
15+
FROM `bfcte_1`
1716
ORDER BY
18-
`bfcol_1` ASC NULLS LAST
17+
`bfcol_2` ASC NULLS LAST
1918
LIMIT 10
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`rowindex` AS `bfcol_0`,
4-
`int64_col` AS `bfcol_1`,
5-
`string_col` AS `bfcol_2`,
6-
`float64_col` AS `bfcol_3`,
7-
`bool_col` AS `bfcol_4`
8-
FROM `test-project`.`test_dataset`.`test_table`
3+
`int64_col` AS `bfcol_0`,
4+
`rowindex` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
`bfcol_1` AS `bfcol_2`,
9+
`bfcol_0` AS `bfcol_3`
10+
FROM `bfcte_0`
911
)
1012
SELECT
11-
`bfcol_0` AS `rowindex`,
12-
`bfcol_1` AS `int64_col`,
13-
`bfcol_2` AS `string_col`,
14-
`bfcol_3` AS `float64_col`,
15-
`bfcol_4` AS `bool_col`
16-
FROM `bfcte_0`
13+
`bfcol_2` AS `rowindex`,
14+
`bfcol_3` AS `int64_col`
15+
FROM `bfcte_1`
1716
ORDER BY
18-
`bfcol_0` ASC NULLS LAST
17+
`bfcol_3` ASC NULLS LAST
Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`rowindex` AS `bfcol_0`,
4-
`int64_col` AS `bfcol_1`,
5-
`string_col` AS `bfcol_2`,
6-
`float64_col` AS `bfcol_3`,
7-
`bool_col` AS `bfcol_4`
8-
FROM `test-project`.`test_dataset`.`test_table`
3+
`int64_col` AS `bfcol_0`,
4+
`rowindex` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
96
), `bfcte_1` AS (
107
SELECT
11-
*,
12-
`bfcol_0` AS `bfcol_5`,
13-
`bfcol_2` AS `bfcol_6`,
14-
`bfcol_3` AS `bfcol_7`,
15-
`bfcol_4` AS `bfcol_8`,
16-
`bfcol_1` + `bfcol_1` AS `bfcol_9`
8+
`bfcol_1` AS `bfcol_2`,
9+
`bfcol_0` AS `bfcol_3`
1710
FROM `bfcte_0`
1811
), `bfcte_2` AS (
1912
SELECT
20-
`bfcol_5` AS `bfcol_10`,
21-
`bfcol_9` AS `bfcol_11`,
22-
`bfcol_6` AS `bfcol_12`,
23-
`bfcol_7` AS `bfcol_13`,
24-
`bfcol_8` AS `bfcol_14`
13+
*,
14+
`bfcol_2` AS `bfcol_4`,
15+
`bfcol_3` + `bfcol_3` AS `bfcol_5`
2516
FROM `bfcte_1`
17+
), `bfcte_3` AS (
18+
SELECT
19+
`bfcol_4` AS `bfcol_6`,
20+
`bfcol_5` AS `bfcol_7`
21+
FROM `bfcte_2`
2622
)
2723
SELECT
28-
`bfcol_10` AS `rowindex`,
29-
`bfcol_11` AS `int64_col`,
30-
`bfcol_12` AS `string_col`,
31-
`bfcol_13` AS `float64_col`,
32-
`bfcol_14` AS `bool_col`
33-
FROM `bfcte_2`
24+
`bfcol_6` AS `rowindex`,
25+
`bfcol_7` AS `int64_col`
26+
FROM `bfcte_3`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`int64_col` AS `bfcol_0`,
4+
`rowindex` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
`bfcol_1` AS `bfcol_2`,
9+
`bfcol_0` AS `bfcol_3`
10+
FROM `bfcte_0`
11+
), `bfcte_2` AS (
12+
SELECT
13+
*,
14+
`bfcol_2` AS `bfcol_4`,
15+
`bfcol_3` + 1 AS `bfcol_5`
16+
FROM `bfcte_1`
17+
), `bfcte_3` AS (
18+
SELECT
19+
`bfcol_4` AS `bfcol_6`,
20+
`bfcol_5` AS `bfcol_7`
21+
FROM `bfcte_2`
22+
)
23+
SELECT
24+
`bfcol_6` AS `rowindex`,
25+
`bfcol_7` AS `int64_col`
26+
FROM `bfcte_3`

0 commit comments

Comments
 (0)