Skip to content

feat: include bq schema and query string in dry run results #1752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions bigframes/session/dry_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def get_table_stats(table: bigquery.Table) -> pandas.Series:
index.append("columnDtypes")
values.append(col_dtypes)

# Add raw BQ schema
index.append("bigquerySchema")
values.append(table.schema)

for key in ("numBytes", "numRows", "location", "type"):
index.append(key)
values.append(table._properties[key])
Expand Down Expand Up @@ -96,8 +100,12 @@ def get_query_stats(
) -> pandas.Series:
"""Returns important stats from the query job as a Pandas Series."""

index = []
values = []
index: List[Any] = []
values: List[Any] = []

# Add raw BQ schema
index.append("bigquerySchema")
values.append(query_job.schema)

job_api_repr = copy.deepcopy(query_job._properties)

Expand All @@ -110,6 +118,8 @@ def get_query_stats(
configuration = job_api_repr.get("configuration", {})
index.append("jobType")
values.append(configuration.get("jobType", None))
index.append("dispatchedSql")
values.append(configuration.get("query", {}).get("query", None))

query_config = configuration.get("query", {})
for key in ("destinationTable", "useLegacySql"):
Expand Down
3 changes: 2 additions & 1 deletion tests/system/small/test_dataframe_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ def test_to_pandas_dry_run(session, scalars_pandas_df_multi_index):

result = bf_df.to_pandas(dry_run=True)

assert len(result) == 14
assert isinstance(result, pd.Series)
assert len(result) > 0


def test_to_arrow_override_global_option(scalars_df_index):
Expand Down
5 changes: 4 additions & 1 deletion tests/system/small/test_index_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pandas as pd

import bigframes


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

result = index.to_pandas(dry_run=True)

assert len(result) == 14
assert isinstance(result, pd.Series)
assert len(result) > 0


def test_to_numpy_override_global_option(scalars_df_index):
Expand Down
3 changes: 2 additions & 1 deletion tests/system/small/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4604,4 +4604,5 @@ def test_series_to_pandas_dry_run(scalars_df_index):

result = bf_series.to_pandas(dry_run=True)

assert len(result) == 14
assert isinstance(result, pd.Series)
assert len(result) > 0
3 changes: 3 additions & 0 deletions tests/system/small/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1899,9 +1899,11 @@ def _assert_query_dry_run_stats_are_valid(result: pd.Series):
"columnDtypes",
"indexLevel",
"indexDtypes",
"bigquerySchema",
"projectId",
"location",
"jobType",
"dispatchedSql",
"destinationTable",
"useLegacySql",
"referencedTables",
Expand All @@ -1922,6 +1924,7 @@ def _assert_table_dry_run_stats_are_valid(result: pd.Series):
"isQuery",
"columnCount",
"columnDtypes",
"bigquerySchema",
"numBytes",
"numRows",
"location",
Expand Down