Skip to content

Commit bb51147

Browse files
authored
feat: include bq schema and query string in dry run results (#1752)
* feat: include bq schema and query string in dry run results * rename key * fix tests
1 parent 190390b commit bb51147

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

bigframes/session/dry_runs.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def get_table_stats(table: bigquery.Table) -> pandas.Series:
3737
index.append("columnDtypes")
3838
values.append(col_dtypes)
3939

40+
# Add raw BQ schema
41+
index.append("bigquerySchema")
42+
values.append(table.schema)
43+
4044
for key in ("numBytes", "numRows", "location", "type"):
4145
index.append(key)
4246
values.append(table._properties[key])
@@ -96,8 +100,12 @@ def get_query_stats(
96100
) -> pandas.Series:
97101
"""Returns important stats from the query job as a Pandas Series."""
98102

99-
index = []
100-
values = []
103+
index: List[Any] = []
104+
values: List[Any] = []
105+
106+
# Add raw BQ schema
107+
index.append("bigquerySchema")
108+
values.append(query_job.schema)
101109

102110
job_api_repr = copy.deepcopy(query_job._properties)
103111

@@ -110,6 +118,8 @@ def get_query_stats(
110118
configuration = job_api_repr.get("configuration", {})
111119
index.append("jobType")
112120
values.append(configuration.get("jobType", None))
121+
index.append("dispatchedSql")
122+
values.append(configuration.get("query", {}).get("query", None))
113123

114124
query_config = configuration.get("query", {})
115125
for key in ("destinationTable", "useLegacySql"):

tests/system/small/test_dataframe_io.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ def test_to_pandas_dry_run(session, scalars_pandas_df_multi_index):
319319

320320
result = bf_df.to_pandas(dry_run=True)
321321

322-
assert len(result) == 14
322+
assert isinstance(result, pd.Series)
323+
assert len(result) > 0
323324

324325

325326
def test_to_arrow_override_global_option(scalars_df_index):

tests/system/small/test_index_io.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import pandas as pd
15+
1416
import bigframes
1517

1618

@@ -35,7 +37,8 @@ def test_to_pandas_dry_run(scalars_df_index):
3537

3638
result = index.to_pandas(dry_run=True)
3739

38-
assert len(result) == 14
40+
assert isinstance(result, pd.Series)
41+
assert len(result) > 0
3942

4043

4144
def test_to_numpy_override_global_option(scalars_df_index):

tests/system/small/test_series.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4604,4 +4604,5 @@ def test_series_to_pandas_dry_run(scalars_df_index):
46044604

46054605
result = bf_series.to_pandas(dry_run=True)
46064606

4607-
assert len(result) == 14
4607+
assert isinstance(result, pd.Series)
4608+
assert len(result) > 0

tests/system/small/test_session.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,9 +1899,11 @@ def _assert_query_dry_run_stats_are_valid(result: pd.Series):
18991899
"columnDtypes",
19001900
"indexLevel",
19011901
"indexDtypes",
1902+
"bigquerySchema",
19021903
"projectId",
19031904
"location",
19041905
"jobType",
1906+
"dispatchedSql",
19051907
"destinationTable",
19061908
"useLegacySql",
19071909
"referencedTables",
@@ -1922,6 +1924,7 @@ def _assert_table_dry_run_stats_are_valid(result: pd.Series):
19221924
"isQuery",
19231925
"columnCount",
19241926
"columnDtypes",
1927+
"bigquerySchema",
19251928
"numBytes",
19261929
"numRows",
19271930
"location",

0 commit comments

Comments
 (0)