-
Notifications
You must be signed in to change notification settings - Fork 63
chore: add benchmarks for read_gbq_colab #1860
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
77c9061
chore: add benchmarks for read_gbq_colab
tswast 5c21699
Merge branch 'main' into b420984164-bench-methods
tswast b14171c
correct project id
tswast 526356a
Merge remote-tracking branch 'origin/b420984164-bench-methods' into b…
tswast 615a76a
exclude error too
tswast 1c963c3
Delete tests/benchmark/read_gbq_colab/first_page.py_percentile_99.error
tswast 8a36a32
explain column selection for groupby
tswast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| *.bytesprocessed | ||
| *.bq_exec_time_seconds | ||
| *.error | ||
| *.local_exec_time_seconds | ||
| *.query_char_count | ||
| *.slotmillis |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # 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 pathlib | ||
|
|
||
| import benchmark.utils as utils | ||
|
|
||
| import bigframes.session | ||
|
|
||
| PAGE_SIZE = utils.READ_GBQ_COLAB_PAGE_SIZE | ||
|
|
||
|
|
||
| def aggregate_output( | ||
| *, project_id, dataset_id, table_id, session: bigframes.session.Session | ||
| ): | ||
| # TODO(tswast): Support alternative query if table_id is a local DataFrame, | ||
| # e.g. "{local_inline}" or "{local_large}" | ||
| df = session._read_gbq_colab( | ||
| f"SELECT * FROM `{project_id}`.{dataset_id}.{table_id}" | ||
| ) | ||
|
|
||
| # Simulate getting the first page, since we'll always do that first in the UI. | ||
| df.shape | ||
| next(iter(df.to_pandas_batches(page_size=PAGE_SIZE))) | ||
|
|
||
| # To simulate very small rows that can only fit a boolean, | ||
| # some tables don't have an integer column. If an integer column is available, | ||
| # we prefer to group by that to get a more realistic number of groups. | ||
| group_column = "col_int64_1" | ||
| if group_column not in df.columns: | ||
| group_column = "col_bool_0" | ||
|
|
||
| # Simulate the user aggregating by a column and visualizing those results | ||
| df_aggregated = ( | ||
| df.assign(rounded=df[group_column].astype("Int64").round(-9)) | ||
| .groupby("rounded") | ||
| .sum() | ||
| ) | ||
|
|
||
| df_aggregated.shape | ||
| next(iter(df_aggregated.to_pandas_batches(page_size=PAGE_SIZE))) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ( | ||
| project_id, | ||
| dataset_id, | ||
| table_id, | ||
| session, | ||
| suffix, | ||
| ) = utils.get_configuration(include_table_id=True) | ||
| current_path = pathlib.Path(__file__).absolute() | ||
|
|
||
| utils.get_execution_time( | ||
| aggregate_output, | ||
| current_path, | ||
| suffix, | ||
| project_id=project_id, | ||
| dataset_id=dataset_id, | ||
| table_id=table_id, | ||
| session=session, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| {"benchmark_suffix": "percentile_09", "project_id": "bigframes-dev-perf", "dataset_id": "read_gbq_colab_benchmark", "table_id": "percentile_09", "ordered": false} | ||
| {"benchmark_suffix": "percentile_19", "project_id": "bigframes-dev-perf", "dataset_id": "read_gbq_colab_benchmark", "table_id": "percentile_19", "ordered": false} | ||
| {"benchmark_suffix": "percentile_29", "project_id": "bigframes-dev-perf", "dataset_id": "read_gbq_colab_benchmark", "table_id": "percentile_29", "ordered": false} | ||
| {"benchmark_suffix": "percentile_39", "project_id": "bigframes-dev-perf", "dataset_id": "read_gbq_colab_benchmark", "table_id": "percentile_39", "ordered": false} | ||
| {"benchmark_suffix": "percentile_49", "project_id": "bigframes-dev-perf", "dataset_id": "read_gbq_colab_benchmark", "table_id": "percentile_49", "ordered": false} | ||
| {"benchmark_suffix": "percentile_59", "project_id": "bigframes-dev-perf", "dataset_id": "read_gbq_colab_benchmark", "table_id": "percentile_59", "ordered": false} | ||
| {"benchmark_suffix": "percentile_69", "project_id": "bigframes-dev-perf", "dataset_id": "read_gbq_colab_benchmark", "table_id": "percentile_69", "ordered": false} | ||
| {"benchmark_suffix": "percentile_79", "project_id": "bigframes-dev-perf", "dataset_id": "read_gbq_colab_benchmark", "table_id": "percentile_79", "ordered": false} | ||
| {"benchmark_suffix": "percentile_89", "project_id": "bigframes-dev-perf", "dataset_id": "read_gbq_colab_benchmark", "table_id": "percentile_89", "ordered": false} | ||
| {"benchmark_suffix": "percentile_99", "project_id": "bigframes-dev-perf", "dataset_id": "read_gbq_colab_benchmark", "table_id": "percentile_99", "ordered": false} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # 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 pathlib | ||
|
|
||
| import benchmark.utils as utils | ||
|
|
||
| import bigframes.session | ||
|
|
||
|
|
||
| def dry_run(*, project_id, dataset_id, table_id, session: bigframes.session.Session): | ||
| # TODO(tswast): Support alternative query if table_id is a local DataFrame, | ||
| # e.g. "{local_inline}" or "{local_large}" | ||
| session._read_gbq_colab( | ||
| f"SELECT * FROM `{project_id}`.{dataset_id}.{table_id}", | ||
| dry_run=True, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ( | ||
| project_id, | ||
| dataset_id, | ||
| table_id, | ||
| session, | ||
| suffix, | ||
| ) = utils.get_configuration(include_table_id=True) | ||
| current_path = pathlib.Path(__file__).absolute() | ||
|
|
||
| utils.get_execution_time( | ||
| dry_run, | ||
| current_path, | ||
| suffix, | ||
| project_id=project_id, | ||
| dataset_id=dataset_id, | ||
| table_id=table_id, | ||
| session=session, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # 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 pathlib | ||
|
|
||
| import benchmark.utils as utils | ||
|
|
||
| import bigframes.session | ||
|
|
||
| PAGE_SIZE = utils.READ_GBQ_COLAB_PAGE_SIZE | ||
|
|
||
|
|
||
| def filter_output( | ||
| *, project_id, dataset_id, table_id, session: bigframes.session.Session | ||
| ): | ||
| # TODO(tswast): Support alternative query if table_id is a local DataFrame, | ||
| # e.g. "{local_inline}" or "{local_large}" | ||
| df = session._read_gbq_colab( | ||
| f"SELECT * FROM `{project_id}`.{dataset_id}.{table_id}" | ||
| ) | ||
|
|
||
| # Simulate getting the first page, since we'll always do that first in the UI. | ||
| df.shape | ||
| next(iter(df.to_pandas_batches(page_size=PAGE_SIZE))) | ||
|
|
||
| # Simulate the user filtering by a column and visualizing those results | ||
| df_filtered = df[df["col_bool_0"]] | ||
| df_filtered.shape | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These .shape calls are going to be pretty brutal, going to double-execute |
||
| next(iter(df_filtered.to_pandas_batches(page_size=PAGE_SIZE))) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ( | ||
| project_id, | ||
| dataset_id, | ||
| table_id, | ||
| session, | ||
| suffix, | ||
| ) = utils.get_configuration(include_table_id=True) | ||
| current_path = pathlib.Path(__file__).absolute() | ||
|
|
||
| utils.get_execution_time( | ||
| filter_output, | ||
| current_path, | ||
| suffix, | ||
| project_id=project_id, | ||
| dataset_id=dataset_id, | ||
| table_id=table_id, | ||
| session=session, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # 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 pathlib | ||
|
|
||
| import benchmark.utils as utils | ||
|
|
||
| import bigframes.session | ||
|
|
||
| PAGE_SIZE = utils.READ_GBQ_COLAB_PAGE_SIZE | ||
|
|
||
|
|
||
| def first_page(*, project_id, dataset_id, table_id, session: bigframes.session.Session): | ||
| # TODO(tswast): Support alternative query if table_id is a local DataFrame, | ||
| # e.g. "{local_inline}" or "{local_large}" | ||
| df = session._read_gbq_colab( | ||
| f"SELECT * FROM `{project_id}`.{dataset_id}.{table_id}" | ||
| ) | ||
|
|
||
| # Get number of rows (to calculate number of pages) and the first page. | ||
| df.shape | ||
| next(iter(df.to_pandas_batches(page_size=PAGE_SIZE))) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ( | ||
| project_id, | ||
| dataset_id, | ||
| table_id, | ||
| session, | ||
| suffix, | ||
| ) = utils.get_configuration(include_table_id=True) | ||
| current_path = pathlib.Path(__file__).absolute() | ||
|
|
||
| utils.get_execution_time( | ||
| first_page, | ||
| current_path, | ||
| suffix, | ||
| project_id=project_id, | ||
| dataset_id=dataset_id, | ||
| table_id=table_id, | ||
| session=session, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # 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 pathlib | ||
|
|
||
| import benchmark.utils as utils | ||
|
|
||
| import bigframes.session | ||
|
|
||
| PAGE_SIZE = utils.READ_GBQ_COLAB_PAGE_SIZE | ||
|
|
||
|
|
||
| def last_page(*, project_id, dataset_id, table_id, session: bigframes.session.Session): | ||
| # TODO(tswast): Support alternative query if table_id is a local DataFrame, | ||
| # e.g. "{local_inline}" or "{local_large}" | ||
| df = session._read_gbq_colab( | ||
| f"SELECT * FROM `{project_id}`.{dataset_id}.{table_id}" | ||
| ) | ||
|
|
||
| # Get number of rows (to calculate number of pages) and then all pages. | ||
| df.shape | ||
| for _ in df.to_pandas_batches(page_size=PAGE_SIZE): | ||
| pass | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ( | ||
| project_id, | ||
| dataset_id, | ||
| table_id, | ||
| session, | ||
| suffix, | ||
| ) = utils.get_configuration(include_table_id=True) | ||
| current_path = pathlib.Path(__file__).absolute() | ||
|
|
||
| utils.get_execution_time( | ||
| last_page, | ||
| current_path, | ||
| suffix, | ||
| project_id=project_id, | ||
| dataset_id=dataset_id, | ||
| table_id=table_id, | ||
| session=session, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # 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 pathlib | ||
|
|
||
| import benchmark.utils as utils | ||
|
|
||
| import bigframes.session | ||
|
|
||
| PAGE_SIZE = utils.READ_GBQ_COLAB_PAGE_SIZE | ||
|
|
||
|
|
||
| def sort_output( | ||
| *, project_id, dataset_id, table_id, session: bigframes.session.Session | ||
| ): | ||
| # TODO(tswast): Support alternative query if table_id is a local DataFrame, | ||
| # e.g. "{local_inline}" or "{local_large}" | ||
| df = session._read_gbq_colab( | ||
| f"SELECT * FROM `{project_id}`.{dataset_id}.{table_id}" | ||
| ) | ||
|
|
||
| # Simulate getting the first page, since we'll always do that first in the UI. | ||
| df.shape | ||
| next(iter(df.to_pandas_batches(page_size=PAGE_SIZE))) | ||
|
|
||
| # Simulate the user sorting by a column and visualizing those results | ||
| sort_column = "col_int64_1" | ||
| if sort_column not in df.columns: | ||
| sort_column = "col_bool_0" | ||
|
|
||
| df_sorted = df.sort_values(sort_column) | ||
| df_sorted.shape | ||
| next(iter(df_sorted.to_pandas_batches(page_size=PAGE_SIZE))) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ( | ||
| project_id, | ||
| dataset_id, | ||
| table_id, | ||
| session, | ||
| suffix, | ||
| ) = utils.get_configuration(include_table_id=True) | ||
| current_path = pathlib.Path(__file__).absolute() | ||
|
|
||
| utils.get_execution_time( | ||
| sort_output, | ||
| current_path, | ||
| suffix, | ||
| project_id=project_id, | ||
| dataset_id=dataset_id, | ||
| table_id=table_id, | ||
| session=session, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure I follow what is going on here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need some column to group by and some tables with tiny rows can only fit a boolean. I can add a comment.