├── .coveragerc
├── .flake8
├── .github
├── .OwlBot.lock.yaml
├── .OwlBot.yaml
├── CODEOWNERS
├── CONTRIBUTING.md
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── feature_request.md
│ └── support_request.md
├── PULL_REQUEST_TEMPLATE.md
├── auto-approve.yml
├── auto-label.yaml
├── blunderbuss.yml
├── header-checker-lint.yml
├── release-please.yml
├── release-trigger.yml
├── snippet-bot.yml
├── sync-repo-settings.yaml
└── workflows
│ ├── docs.yml
│ └── unittest.yml
├── .gitignore
├── .kokoro
├── build.sh
├── continuous
│ ├── common.cfg
│ ├── continuous.cfg
│ ├── prerelease-deps-3.13.cfg
│ └── unit-tests-misc.cfg
├── populate-secrets.sh
├── presubmit
│ ├── common.cfg
│ ├── linting-typing.cfg
│ ├── prerelease-deps.cfg
│ ├── snippets-3.13.cfg
│ ├── snippets-3.9.cfg
│ ├── system-3.13.cfg
│ └── system-3.9.cfg
├── samples
│ ├── lint
│ │ ├── common.cfg
│ │ ├── continuous.cfg
│ │ ├── periodic.cfg
│ │ └── presubmit.cfg
│ ├── python3.10
│ │ ├── common.cfg
│ │ ├── continuous.cfg
│ │ ├── periodic-head.cfg
│ │ ├── periodic.cfg
│ │ └── presubmit.cfg
│ ├── python3.11
│ │ ├── common.cfg
│ │ ├── continuous.cfg
│ │ ├── periodic-head.cfg
│ │ ├── periodic.cfg
│ │ └── presubmit.cfg
│ ├── python3.12
│ │ ├── common.cfg
│ │ ├── continuous.cfg
│ │ ├── periodic-head.cfg
│ │ ├── periodic.cfg
│ │ └── presubmit.cfg
│ ├── python3.13
│ │ ├── common.cfg
│ │ ├── continuous.cfg
│ │ ├── periodic-head.cfg
│ │ ├── periodic.cfg
│ │ └── presubmit.cfg
│ └── python3.9
│ │ ├── common.cfg
│ │ ├── continuous.cfg
│ │ ├── periodic-head.cfg
│ │ ├── periodic.cfg
│ │ └── presubmit.cfg
├── test-samples-against-head.sh
├── test-samples-impl.sh
├── test-samples.sh
├── trampoline.sh
└── trampoline_v2.sh
├── .pre-commit-config.yaml
├── .repo-metadata.json
├── .trampolinerc
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.rst
├── LICENSE
├── MANIFEST.in
├── README.rst
├── SECURITY.md
├── UPGRADING.md
├── benchmark
├── README.md
├── benchmark.py
└── queries.json
├── docs
├── .gitignore
├── README.rst
├── UPGRADING.md
├── _static
│ └── custom.css
├── _templates
│ └── layout.html
├── bigquery
│ ├── legacy_proto_types.rst
│ └── standard_sql.rst
├── changelog.md
├── conf.py
├── dbapi.rst
├── design
│ ├── index.rst
│ └── query-retries.md
├── enums.rst
├── format_options.rst
├── generated
│ └── google.cloud.bigquery.magics.html
├── index.rst
├── job_base.rst
├── magics.rst
├── query.rst
├── reference.rst
├── samples
├── snippets.py
├── summary_overview.md
├── usage.html
└── usage
│ ├── client.rst
│ ├── datasets.rst
│ ├── encryption.rst
│ ├── index.rst
│ ├── jobs.rst
│ ├── pandas.rst
│ ├── queries.rst
│ └── tables.rst
├── google
└── cloud
│ ├── bigquery
│ ├── __init__.py
│ ├── _helpers.py
│ ├── _http.py
│ ├── _job_helpers.py
│ ├── _pandas_helpers.py
│ ├── _pyarrow_helpers.py
│ ├── _tqdm_helpers.py
│ ├── _versions_helpers.py
│ ├── client.py
│ ├── dataset.py
│ ├── dbapi
│ │ ├── __init__.py
│ │ ├── _helpers.py
│ │ ├── connection.py
│ │ ├── cursor.py
│ │ ├── exceptions.py
│ │ └── types.py
│ ├── encryption_configuration.py
│ ├── enums.py
│ ├── exceptions.py
│ ├── external_config.py
│ ├── format_options.py
│ ├── iam.py
│ ├── job
│ │ ├── __init__.py
│ │ ├── base.py
│ │ ├── copy_.py
│ │ ├── extract.py
│ │ ├── load.py
│ │ └── query.py
│ ├── magics
│ │ ├── __init__.py
│ │ ├── line_arg_parser
│ │ │ ├── __init__.py
│ │ │ ├── exceptions.py
│ │ │ ├── lexer.py
│ │ │ ├── parser.py
│ │ │ └── visitors.py
│ │ └── magics.py
│ ├── model.py
│ ├── opentelemetry_tracing.py
│ ├── py.typed
│ ├── query.py
│ ├── retry.py
│ ├── routine
│ │ ├── __init__.py
│ │ └── routine.py
│ ├── schema.py
│ ├── standard_sql.py
│ ├── table.py
│ └── version.py
│ └── bigquery_v2
│ ├── __init__.py
│ └── types
│ ├── __init__.py
│ ├── encryption_config.py
│ ├── model.py
│ ├── model_reference.py
│ ├── standard_sql.py
│ └── table_reference.py
├── mypy.ini
├── noxfile.py
├── owlbot.py
├── pylint.config.py
├── pyproject.toml
├── renovate.json
├── samples
├── AUTHORING_GUIDE.md
├── CONTRIBUTING.md
├── __init__.py
├── add_empty_column.py
├── browse_table_data.py
├── client_list_jobs.py
├── client_load_partitioned_table.py
├── client_query_add_column.py
├── client_query_batch.py
├── client_query_destination_table.py
├── client_query_destination_table_clustered.py
├── client_query_destination_table_cmek.py
├── client_query_destination_table_legacy.py
├── client_query_dry_run.py
├── client_query_job_optional.py
├── client_query_legacy_sql.py
├── client_query_relax_column.py
├── client_query_w_array_params.py
├── client_query_w_named_params.py
├── client_query_w_positional_params.py
├── client_query_w_struct_params.py
├── client_query_w_timestamp_params.py
├── copy_table.py
├── copy_table_cmek.py
├── copy_table_multiple_source.py
├── create_dataset.py
├── create_job.py
├── create_routine.py
├── create_routine_ddl.py
├── create_table.py
├── create_table_clustered.py
├── create_table_range_partitioned.py
├── dataset_exists.py
├── delete_dataset.py
├── delete_dataset_labels.py
├── delete_model.py
├── delete_routine.py
├── delete_table.py
├── desktopapp
│ ├── __init__.py
│ ├── conftest.py
│ ├── mypy.ini
│ ├── noxfile.py
│ ├── noxfile_config.py
│ ├── requirements-test.txt
│ ├── requirements.txt
│ ├── user_credentials.py
│ └── user_credentials_test.py
├── download_public_data.py
├── download_public_data_sandbox.py
├── geography
│ ├── __init__.py
│ ├── conftest.py
│ ├── insert_geojson.py
│ ├── insert_geojson_test.py
│ ├── insert_wkt.py
│ ├── insert_wkt_test.py
│ ├── mypy.ini
│ ├── noxfile.py
│ ├── noxfile_config.py
│ ├── requirements-test.txt
│ ├── requirements.txt
│ ├── to_geodataframe.py
│ └── to_geodataframe_test.py
├── get_dataset.py
├── get_dataset_labels.py
├── get_model.py
├── get_routine.py
├── get_table.py
├── label_dataset.py
├── list_datasets.py
├── list_datasets_by_label.py
├── list_models.py
├── list_routines.py
├── list_tables.py
├── load_table_clustered.py
├── load_table_dataframe.py
├── load_table_file.py
├── load_table_uri_autodetect_csv.py
├── load_table_uri_autodetect_json.py
├── load_table_uri_avro.py
├── load_table_uri_cmek.py
├── load_table_uri_csv.py
├── load_table_uri_json.py
├── load_table_uri_orc.py
├── load_table_uri_parquet.py
├── load_table_uri_truncate_avro.py
├── load_table_uri_truncate_csv.py
├── load_table_uri_truncate_json.py
├── load_table_uri_truncate_orc.py
├── load_table_uri_truncate_parquet.py
├── magics
│ ├── __init__.py
│ ├── _helpers.py
│ ├── conftest.py
│ ├── mypy.ini
│ ├── noxfile.py
│ ├── noxfile_config.py
│ ├── query.py
│ ├── query_params_scalars.py
│ ├── query_params_scalars_test.py
│ ├── query_test.py
│ ├── requirements-test.txt
│ └── requirements.txt
├── mypy.ini
├── notebooks
│ ├── __init__.py
│ ├── conftest.py
│ ├── jupyter_tutorial_test.py
│ ├── mypy.ini
│ ├── noxfile.py
│ ├── noxfile_config.py
│ ├── requirements-test.txt
│ └── requirements.txt
├── query_external_gcs_temporary_table.py
├── query_external_sheets_permanent_table.py
├── query_external_sheets_temporary_table.py
├── query_no_cache.py
├── query_pagination.py
├── query_script.py
├── query_to_arrow.py
├── snippets
│ ├── .gitignore
│ ├── README.rst
│ ├── README.rst.in
│ ├── authenticate_service_account.py
│ ├── authenticate_service_account_test.py
│ ├── authorized_view_tutorial.py
│ ├── authorized_view_tutorial_test.py
│ ├── client_query.py
│ ├── client_query_test.py
│ ├── conftest.py
│ ├── create_iam_policy_test.py
│ ├── create_partitioned_table.py
│ ├── create_partitioned_table_test.py
│ ├── create_table_cmek.py
│ ├── create_table_cmek_test.py
│ ├── create_table_external_data_configuration.py
│ ├── create_table_external_data_configuration_test.py
│ ├── create_table_external_hive_partitioned.py
│ ├── create_table_external_hive_partitioned_test.py
│ ├── create_table_schema_from_json.py
│ ├── create_table_schema_from_json_test.py
│ ├── create_table_snapshot.py
│ ├── create_table_snapshot_test.py
│ ├── dataset_access_test.py
│ ├── delete_job.py
│ ├── delete_job_test.py
│ ├── delete_label_table.py
│ ├── delete_label_table_test.py
│ ├── get_table_labels.py
│ ├── get_table_labels_test.py
│ ├── get_table_make_schema.py
│ ├── get_table_make_schema_test.py
│ ├── label_table.py
│ ├── label_table_test.py
│ ├── load_table_schema_from_json.py
│ ├── load_table_schema_from_json_test.py
│ ├── load_table_uri_firestore.py
│ ├── load_table_uri_firestore_test.py
│ ├── manage_job_cancel.py
│ ├── manage_job_get.py
│ ├── manage_job_test.py
│ ├── materialized_view.py
│ ├── materialized_view_test.py
│ ├── mypy.ini
│ ├── natality_tutorial.py
│ ├── natality_tutorial_test.py
│ ├── nested_repeated_schema.py
│ ├── nested_repeated_schema_test.py
│ ├── noxfile.py
│ ├── noxfile_config.py
│ ├── quickstart.py
│ ├── quickstart_test.py
│ ├── relax_column.py
│ ├── relax_column_test.py
│ ├── requirements-test.txt
│ ├── requirements.txt
│ ├── revoke_dataset_access.py
│ ├── schema.json
│ ├── schema_us_states.json
│ ├── simple_app.py
│ ├── simple_app_test.py
│ ├── test_update_with_dml.py
│ ├── update_dataset_access.py
│ ├── update_table_expiration.py
│ ├── update_table_expiration_test.py
│ ├── update_with_dml.py
│ ├── user_sessions_data.json
│ ├── view.py
│ └── view_test.py
├── table_exists.py
├── table_insert_rows.py
├── table_insert_rows_explicit_none_insert_ids.py
├── tests
│ ├── __init__.py
│ ├── conftest.py
│ ├── test_add_empty_column.py
│ ├── test_browse_table_data.py
│ ├── test_client_list_jobs.py
│ ├── test_client_load_partitioned_table.py
│ ├── test_client_query_add_column.py
│ ├── test_client_query_batch.py
│ ├── test_client_query_destination_table.py
│ ├── test_client_query_destination_table_clustered.py
│ ├── test_client_query_destination_table_cmek.py
│ ├── test_client_query_destination_table_legacy.py
│ ├── test_client_query_dry_run.py
│ ├── test_client_query_job_optional.py
│ ├── test_client_query_legacy_sql.py
│ ├── test_client_query_relax_column.py
│ ├── test_client_query_w_array_params.py
│ ├── test_client_query_w_named_params.py
│ ├── test_client_query_w_positional_params.py
│ ├── test_client_query_w_struct_params.py
│ ├── test_client_query_w_timestamp_params.py
│ ├── test_copy_table.py
│ ├── test_copy_table_cmek.py
│ ├── test_copy_table_multiple_source.py
│ ├── test_create_dataset.py
│ ├── test_create_job.py
│ ├── test_create_table.py
│ ├── test_create_table_clustered.py
│ ├── test_create_table_range_partitioned.py
│ ├── test_dataset_exists.py
│ ├── test_dataset_label_samples.py
│ ├── test_delete_dataset.py
│ ├── test_delete_table.py
│ ├── test_download_public_data.py
│ ├── test_download_public_data_sandbox.py
│ ├── test_get_dataset.py
│ ├── test_get_table.py
│ ├── test_list_datasets.py
│ ├── test_list_datasets_by_label.py
│ ├── test_list_tables.py
│ ├── test_load_table_clustered.py
│ ├── test_load_table_dataframe.py
│ ├── test_load_table_file.py
│ ├── test_load_table_uri_autodetect_csv.py
│ ├── test_load_table_uri_autodetect_json.py
│ ├── test_load_table_uri_avro.py
│ ├── test_load_table_uri_cmek.py
│ ├── test_load_table_uri_csv.py
│ ├── test_load_table_uri_json.py
│ ├── test_load_table_uri_orc.py
│ ├── test_load_table_uri_parquet.py
│ ├── test_load_table_uri_truncate_avro.py
│ ├── test_load_table_uri_truncate_csv.py
│ ├── test_load_table_uri_truncate_json.py
│ ├── test_load_table_uri_truncate_orc.py
│ ├── test_load_table_uri_truncate_parquet.py
│ ├── test_model_samples.py
│ ├── test_query_external_gcs_temporary_table.py
│ ├── test_query_external_sheets_permanent_table.py
│ ├── test_query_external_sheets_temporary_table.py
│ ├── test_query_no_cache.py
│ ├── test_query_pagination.py
│ ├── test_query_script.py
│ ├── test_query_to_arrow.py
│ ├── test_routine_samples.py
│ ├── test_table_exists.py
│ ├── test_table_insert_rows.py
│ ├── test_table_insert_rows_explicit_none_insert_ids.py
│ ├── test_undelete_table.py
│ ├── test_update_dataset_access.py
│ ├── test_update_dataset_default_partition_expiration.py
│ ├── test_update_dataset_default_table_expiration.py
│ ├── test_update_dataset_description.py
│ └── test_update_table_require_partition_filter.py
├── undelete_table.py
├── update_dataset_access.py
├── update_dataset_default_partition_expiration.py
├── update_dataset_default_table_expiration.py
├── update_dataset_description.py
├── update_model.py
├── update_routine.py
└── update_table_require_partition_filter.py
├── scripts
├── decrypt-secrets.sh
└── readme-gen
│ ├── readme_gen.py
│ └── templates
│ ├── README.tmpl.rst
│ ├── auth.tmpl.rst
│ ├── auth_api_key.tmpl.rst
│ ├── install_deps.tmpl.rst
│ └── install_portaudio.tmpl.rst
├── setup.cfg
├── setup.py
├── testing
├── .gitignore
├── constraints-3.10.txt
├── constraints-3.11.txt
├── constraints-3.12.txt
├── constraints-3.13.txt
└── constraints-3.9.txt
└── tests
├── __init__.py
├── data
├── characters.json
├── characters.jsonl
├── colors.avro
├── numeric_38_12.parquet
├── people.csv
├── scalars.csv
├── scalars.jsonl
├── scalars_extreme.jsonl
├── scalars_schema.json
├── scalars_schema_csv.json
└── schema.json
├── scrub_datasets.py
├── system
├── __init__.py
├── conftest.py
├── helpers.py
├── test_arrow.py
├── test_client.py
├── test_job_retry.py
├── test_list_rows.py
├── test_magics.py
├── test_pandas.py
├── test_query.py
└── test_structs.py
└── unit
├── __init__.py
├── _helpers
├── __init__.py
├── test_cell_data_parser.py
├── test_data_frame_cell_data_parser.py
└── test_scalar_query_param_parser.py
├── conftest.py
├── helpers.py
├── job
├── __init__.py
├── helpers.py
├── test_base.py
├── test_copy.py
├── test_extract.py
├── test_load.py
├── test_load_config.py
├── test_query.py
├── test_query_config.py
├── test_query_pandas.py
└── test_query_stats.py
├── line_arg_parser
├── __init__.py
├── test_lexer.py
├── test_parser.py
└── test_visitors.py
├── model
├── __init__.py
├── test_model.py
└── test_model_reference.py
├── routine
├── __init__.py
├── test_remote_function_options.py
├── test_routine.py
├── test_routine_argument.py
└── test_routine_reference.py
├── test__helpers.py
├── test__http.py
├── test__job_helpers.py
├── test__pandas_helpers.py
├── test__pyarrow_helpers.py
├── test__versions_helpers.py
├── test_client.py
├── test_create_dataset.py
├── test_dataset.py
├── test_dbapi__helpers.py
├── test_dbapi_connection.py
├── test_dbapi_cursor.py
├── test_dbapi_types.py
├── test_delete_dataset.py
├── test_encryption_configuration.py
├── test_external_config.py
├── test_format_options.py
├── test_job_retry.py
├── test_legacy_types.py
├── test_list_datasets.py
├── test_list_jobs.py
├── test_list_models.py
├── test_list_projects.py
├── test_list_routines.py
├── test_list_tables.py
├── test_magics.py
├── test_opentelemetry_tracing.py
├── test_packaging.py
├── test_query.py
├── test_retry.py
├── test_schema.py
├── test_signature_compatibility.py
├── test_standard_sql_types.py
├── test_table.py
├── test_table_arrow.py
└── test_table_pandas.py
/.coveragerc:
--------------------------------------------------------------------------------
1 | [run]
2 | branch = True
3 |
4 | [report]
5 | fail_under = 100
6 | show_missing = True
7 | omit =
8 | google/cloud/bigquery/__init__.py
9 | google/cloud/bigquery_v2/* # Legacy proto-based types.
10 | exclude_lines =
11 | # Re-enable the standard pragma
12 | pragma: (no cover|NO COVER)
13 | # Ignore debug-only repr
14 | def __repr__
15 |
--------------------------------------------------------------------------------
/.flake8:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | #
3 | # Copyright 2024 Google LLC
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # https://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # Generated by synthtool. DO NOT EDIT!
18 | [flake8]
19 | ignore = E203, E231, E266, E501, W503
20 | exclude =
21 | # Exclude generated code.
22 | **/proto/**
23 | **/gapic/**
24 | **/services/**
25 | **/types/**
26 | *_pb2.py
27 |
28 | # Standard linting exemptions.
29 | **/.nox/**
30 | __pycache__,
31 | .git,
32 | *.pyc,
33 | conf.py
34 |
--------------------------------------------------------------------------------
/.github/.OwlBot.lock.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2025 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | docker:
15 | image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
16 | digest: sha256:3b3a31be60853477bc39ed8d9bac162cac3ba083724cecaad54eb81d4e4dae9c
17 | # created: 2025-04-16T22:40:03.123475241Z
18 |
--------------------------------------------------------------------------------
/.github/.OwlBot.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | docker:
16 | image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
17 |
18 | deep-remove-regex:
19 | - /owl-bot-staging
20 |
21 | begin-after-commit-hash: f2de93abafa306b2ebadf1d10d947db8bcf2bf15
22 |
23 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Code owners file.
2 | # This file controls who is tagged for review for any given pull request.
3 | #
4 | # For syntax help see:
5 | # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax
6 |
7 | # The @googleapis/api-bigquery is the default owner for changes in this repo
8 | * @googleapis/api-bigquery @googleapis/yoshi-python
9 |
10 | # The python-samples-reviewers team is the default owner for samples changes
11 | /samples/ @googleapis/api-bigquery @googleapis/python-samples-owners @googleapis/yoshi-python
12 |
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution;
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows [Google's Open Source Community
28 | Guidelines](https://opensource.google.com/conduct/).
29 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 |
5 | ---
6 |
7 | Thanks for stopping by to let us know something could be better!
8 |
9 | **PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response.
10 |
11 | Please run down the following list and make sure you've tried the usual "quick fixes":
12 |
13 | - Search the issues already opened: https://github.com/googleapis/python-bigquery/issues
14 | - Search StackOverflow: https://stackoverflow.com/questions/tagged/google-cloud-platform+python
15 |
16 | If you are still having issues, please be sure to include as much information as possible:
17 |
18 | #### Environment details
19 |
20 | - OS type and version:
21 | - Python version: `python --version`
22 | - pip version: `pip --version`
23 | - `google-cloud-bigquery` version: `pip show google-cloud-bigquery`
24 |
25 | #### Steps to reproduce
26 |
27 | 1. ?
28 | 2. ?
29 |
30 | #### Code example
31 |
32 | ```python
33 | # example
34 | ```
35 |
36 | #### Stack trace
37 | ```
38 | # example
39 | ```
40 |
41 | Making sure to follow these steps will guarantee the quickest resolution possible.
42 |
43 | Thanks!
44 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this library
4 |
5 | ---
6 |
7 | Thanks for stopping by to let us know something could be better!
8 |
9 | **PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response.
10 |
11 | **Is your feature request related to a problem? Please describe.**
12 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 | **Describe alternatives you've considered**
16 | A clear and concise description of any alternative solutions or features you've considered.
17 | **Additional context**
18 | Add any other context or screenshots about the feature request here.
19 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/support_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Support request
3 | about: If you have a support contract with Google, please create an issue in the Google Cloud Support console.
4 |
5 | ---
6 |
7 | **PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response.
8 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
2 | - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
3 | - [ ] Ensure the tests and linter pass
4 | - [ ] Code coverage does not decrease (if any source code was changed)
5 | - [ ] Appropriate docs were updated (if necessary)
6 |
7 | Fixes # 🦕
8 |
--------------------------------------------------------------------------------
/.github/auto-approve.yml:
--------------------------------------------------------------------------------
1 | # https://github.com/googleapis/repo-automation-bots/tree/main/packages/auto-approve
2 | processes:
3 | - "OwlBotTemplateChanges"
4 |
--------------------------------------------------------------------------------
/.github/auto-label.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | requestsize:
15 | enabled: true
16 |
17 | path:
18 | pullrequest: true
19 | paths:
20 | samples: "samples"
21 |
--------------------------------------------------------------------------------
/.github/blunderbuss.yml:
--------------------------------------------------------------------------------
1 | # Blunderbuss config
2 | #
3 | # This file controls who is assigned for pull requests and issues.
4 | # Note: This file is autogenerated. To make changes to the assignee
5 | # team, please update `codeowner_team` in `.repo-metadata.json`.
6 | assign_issues:
7 | - googleapis/api-bigquery
8 |
9 | assign_issues_by:
10 | - labels:
11 | - "samples"
12 | to:
13 | - googleapis/python-samples-reviewers
14 | - googleapis/api-bigquery
15 |
16 | assign_prs:
17 | - googleapis/api-bigquery
18 |
--------------------------------------------------------------------------------
/.github/header-checker-lint.yml:
--------------------------------------------------------------------------------
1 | {"allowedCopyrightHolders": ["Google LLC"],
2 | "allowedLicenses": ["Apache-2.0", "MIT", "BSD-3"],
3 | "ignoreFiles": ["**/requirements.txt", "**/requirements-test.txt", "**/__init__.py", "samples/**/constraints.txt", "samples/**/constraints-test.txt"],
4 | "sourceFileExtensions": [
5 | "ts",
6 | "js",
7 | "java",
8 | "sh",
9 | "Dockerfile",
10 | "yaml",
11 | "py",
12 | "html",
13 | "txt"
14 | ]
15 | }
--------------------------------------------------------------------------------
/.github/release-please.yml:
--------------------------------------------------------------------------------
1 | releaseType: python
2 | handleGHRelease: true
3 | # NOTE: this section is generated by synthtool.languages.python
4 | # See https://github.com/googleapis/synthtool/blob/master/synthtool/languages/python.py
5 | branches:
6 | - branch: v2
7 | handleGHRelease: true
8 | releaseType: python
9 | - branch: v1
10 | handleGHRelease: true
11 | releaseType: python
12 | - branch: v0
13 | handleGHRelease: true
14 | releaseType: python
15 |
--------------------------------------------------------------------------------
/.github/release-trigger.yml:
--------------------------------------------------------------------------------
1 | enabled: true
2 | multiScmName: python-bigquery
3 |
--------------------------------------------------------------------------------
/.github/snippet-bot.yml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleapis/python-bigquery/28a5750d455f0381548df6f9b1f7661823837d81/.github/snippet-bot.yml
--------------------------------------------------------------------------------
/.github/sync-repo-settings.yaml:
--------------------------------------------------------------------------------
1 | # https://github.com/googleapis/repo-automation-bots/tree/main/packages/sync-repo-settings
2 | mergeCommitAllowed: false
3 | # Rules for main branch protection
4 | branchProtectionRules:
5 | # Identifies the protection rule pattern. Name of the branch to be protected.
6 | # Defaults to `main`
7 | - pattern: main
8 | requiresLinearHistory: true
9 | requiresCodeOwnerReviews: true
10 | requiresStrictStatusChecks: true
11 | requiredStatusCheckContexts:
12 | - 'Kokoro'
13 | - 'Kokoro system-3.13'
14 | - 'Kokoro snippets-3.13'
15 | - 'cla/google'
16 | - 'Samples - Lint'
17 | - 'Samples - Python 3.9'
18 | - 'Samples - Python 3.10'
19 | - 'Samples - Python 3.11'
20 | - 'Samples - Python 3.12'
21 | - 'Samples - Python 3.13'
22 | - pattern: v2
23 | requiresLinearHistory: true
24 | requiresCodeOwnerReviews: true
25 | requiresStrictStatusChecks: true
26 | requiredStatusCheckContexts:
27 | - 'Kokoro'
28 | - 'cla/google'
29 | - 'Samples - Lint'
30 | - 'Samples - Python 3.9'
31 | - 'Samples - Python 3.10'
32 |
--------------------------------------------------------------------------------
/.github/workflows/docs.yml:
--------------------------------------------------------------------------------
1 | on:
2 | pull_request:
3 | branches:
4 | - main
5 | name: docs
6 | jobs:
7 | docs:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - name: Checkout
11 | uses: actions/checkout@v4
12 | - name: Setup Python
13 | uses: actions/setup-python@v5
14 | with:
15 | python-version: '3.10'
16 | - name: Install nox
17 | run: |
18 | python -m pip install --upgrade setuptools pip wheel
19 | python -m pip install nox
20 | - name: Run docs session
21 | run: |
22 | nox -s docs-3.10
23 |
24 | docfx:
25 | runs-on: ubuntu-latest
26 | steps:
27 | - name: Checkout
28 | uses: actions/checkout@v4
29 | - name: Setup Python
30 | uses: actions/setup-python@v5
31 | with:
32 | python-version: '3.10'
33 | - name: Install nox
34 | run: |
35 | python -m pip install --upgrade setuptools pip wheel
36 | python -m pip install nox
37 | - name: Run docfx session
38 | run: |
39 | nox -s docfx-3.10
40 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.py[cod]
2 | *.sw[op]
3 |
4 | # C extensions
5 | *.so
6 |
7 | # Packages
8 | *.egg
9 | *.egg-info
10 | dist
11 | build
12 | eggs
13 | .eggs
14 | parts
15 | bin
16 | var
17 | sdist
18 | develop-eggs
19 | .installed.cfg
20 | lib
21 | lib64
22 | __pycache__
23 |
24 | # Installer logs
25 | pip-log.txt
26 |
27 | # Unit test / coverage reports
28 | .coverage
29 | .nox
30 | .cache
31 | .pytest_cache
32 | .pytype
33 |
34 |
35 | # Mac
36 | .DS_Store
37 |
38 | # JetBrains
39 | .idea
40 |
41 | # VS Code
42 | .vscode
43 |
44 | # emacs
45 | *~
46 |
47 | # Built documentation
48 | docs/_build
49 | bigquery/docs/generated
50 | docs.metadata
51 |
52 | # Virtual environment
53 | env/
54 | venv/
55 |
56 | # Test logs
57 | coverage.xml
58 | *sponge_log.xml
59 |
60 | # System test environment variables.
61 | system_tests/local_test_setup
62 |
63 | # Make sure a generated file isn't accidentally committed.
64 | pylintrc
65 | pylintrc.test
66 |
--------------------------------------------------------------------------------
/.kokoro/continuous/common.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Build logs will be here
4 | action {
5 | define_artifacts {
6 | regex: "**/*sponge_log.xml"
7 | }
8 | }
9 |
10 | # Download trampoline resources.
11 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
12 |
13 | # Download resources for system tests (service account key, etc.)
14 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"
15 |
16 | # Use the trampoline script to run in docker.
17 | build_file: "python-bigquery/.kokoro/trampoline.sh"
18 |
19 | # Configure the docker image for kokoro-trampoline.
20 | env_vars: {
21 | key: "TRAMPOLINE_IMAGE"
22 | value: "gcr.io/cloud-devrel-kokoro-resources/python-multi"
23 | }
24 | env_vars: {
25 | key: "TRAMPOLINE_BUILD_FILE"
26 | value: "github/python-bigquery/.kokoro/build.sh"
27 | }
28 |
--------------------------------------------------------------------------------
/.kokoro/continuous/continuous.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
--------------------------------------------------------------------------------
/.kokoro/continuous/prerelease-deps-3.13.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Only run this nox session.
4 | env_vars: {
5 | key: "NOX_SESSION"
6 | value: "prerelease_deps-3.13"
7 | }
8 |
--------------------------------------------------------------------------------
/.kokoro/continuous/unit-tests-misc.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Only run these nox sessions.
4 | # A subset based on Python versions that are neither our newest OR oldest
5 | # supported versions of Python
6 | env_vars: {
7 | key: "NOX_SESSION"
8 | value: "unit_noextras-3.9 unit_noextras-3.10 unit_noextras-3.11 unit-3.9 unit-3.10 unit-3.11"
9 | }
--------------------------------------------------------------------------------
/.kokoro/presubmit/common.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Build logs will be here
4 | action {
5 | define_artifacts {
6 | regex: "**/*sponge_log.xml"
7 | }
8 | }
9 |
10 | # Download trampoline resources.
11 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
12 |
13 | # Download resources for system tests (service account key, etc.)
14 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-python"
15 |
16 | # Use the trampoline script to run in docker.
17 | build_file: "python-bigquery/.kokoro/trampoline.sh"
18 |
19 | # Configure the docker image for kokoro-trampoline.
20 | env_vars: {
21 | key: "TRAMPOLINE_IMAGE"
22 | value: "gcr.io/cloud-devrel-kokoro-resources/python-multi"
23 | }
24 | env_vars: {
25 | key: "TRAMPOLINE_BUILD_FILE"
26 | value: "github/python-bigquery/.kokoro/build.sh"
27 | }
28 |
--------------------------------------------------------------------------------
/.kokoro/presubmit/linting-typing.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Only run these nox sessions.
4 | env_vars: {
5 | key: "NOX_SESSION"
6 | value: "lint lint_setup_py blacken mypy mypy_samples pytype"
7 | }
8 |
--------------------------------------------------------------------------------
/.kokoro/presubmit/prerelease-deps.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Only run this nox session.
4 | env_vars: {
5 | key: "NOX_SESSION"
6 | value: "prerelease_deps"
7 | }
8 |
--------------------------------------------------------------------------------
/.kokoro/presubmit/snippets-3.13.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Only run this nox session.
4 | env_vars: {
5 | key: "NOX_SESSION"
6 | value: "snippets-3.13"
7 | }
8 |
--------------------------------------------------------------------------------
/.kokoro/presubmit/snippets-3.9.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Only run this nox session.
4 | env_vars: {
5 | key: "NOX_SESSION"
6 | value: "snippets-3.9"
7 | }
8 |
--------------------------------------------------------------------------------
/.kokoro/presubmit/system-3.13.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Only run this nox session.
4 | env_vars: {
5 | key: "NOX_SESSION"
6 | value: "system-3.13"
7 | }
--------------------------------------------------------------------------------
/.kokoro/presubmit/system-3.9.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Only run this nox session.
4 | env_vars: {
5 | key: "NOX_SESSION"
6 | value: "system-3.9"
7 | }
--------------------------------------------------------------------------------
/.kokoro/samples/lint/common.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Build logs will be here
4 | action {
5 | define_artifacts {
6 | regex: "**/*sponge_log.xml"
7 | }
8 | }
9 |
10 | # Specify which tests to run
11 | env_vars: {
12 | key: "RUN_TESTS_SESSION"
13 | value: "lint"
14 | }
15 |
16 | env_vars: {
17 | key: "TRAMPOLINE_BUILD_FILE"
18 | value: "github/python-bigquery/.kokoro/test-samples.sh"
19 | }
20 |
21 | # Configure the docker image for kokoro-trampoline.
22 | env_vars: {
23 | key: "TRAMPOLINE_IMAGE"
24 | value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
25 | }
26 |
27 | # Download secrets for samples
28 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
29 |
30 | # Download trampoline resources.
31 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
32 |
33 | # Use the trampoline script to run in docker.
34 | build_file: "python-bigquery/.kokoro/trampoline_v2.sh"
--------------------------------------------------------------------------------
/.kokoro/samples/lint/continuous.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
--------------------------------------------------------------------------------
/.kokoro/samples/lint/periodic.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "False"
6 | }
--------------------------------------------------------------------------------
/.kokoro/samples/lint/presubmit.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
--------------------------------------------------------------------------------
/.kokoro/samples/python3.10/common.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Build logs will be here
4 | action {
5 | define_artifacts {
6 | regex: "**/*sponge_log.xml"
7 | }
8 | }
9 |
10 | # Specify which tests to run
11 | env_vars: {
12 | key: "RUN_TESTS_SESSION"
13 | value: "py-3.10"
14 | }
15 |
16 | # Declare build specific Cloud project.
17 | env_vars: {
18 | key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
19 | value: "python-docs-samples-tests-310"
20 | }
21 |
22 | env_vars: {
23 | key: "TRAMPOLINE_BUILD_FILE"
24 | value: "github/python-bigquery/.kokoro/test-samples.sh"
25 | }
26 |
27 | # Configure the docker image for kokoro-trampoline.
28 | env_vars: {
29 | key: "TRAMPOLINE_IMAGE"
30 | value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
31 | }
32 |
33 | # Download secrets for samples
34 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
35 |
36 | # Download trampoline resources.
37 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
38 |
39 | # Use the trampoline script to run in docker.
40 | build_file: "python-bigquery/.kokoro/trampoline_v2.sh"
--------------------------------------------------------------------------------
/.kokoro/samples/python3.10/continuous.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
--------------------------------------------------------------------------------
/.kokoro/samples/python3.10/periodic-head.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
7 |
8 | env_vars: {
9 | key: "TRAMPOLINE_BUILD_FILE"
10 | value: "github/python-bigquery/.kokoro/test-samples-against-head.sh"
11 | }
12 |
--------------------------------------------------------------------------------
/.kokoro/samples/python3.10/periodic.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "False"
6 | }
7 |
--------------------------------------------------------------------------------
/.kokoro/samples/python3.10/presubmit.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
--------------------------------------------------------------------------------
/.kokoro/samples/python3.11/common.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Build logs will be here
4 | action {
5 | define_artifacts {
6 | regex: "**/*sponge_log.xml"
7 | }
8 | }
9 |
10 | # Specify which tests to run
11 | env_vars: {
12 | key: "RUN_TESTS_SESSION"
13 | value: "py-3.11"
14 | }
15 |
16 | # Declare build specific Cloud project.
17 | env_vars: {
18 | key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
19 | value: "python-docs-samples-tests-311"
20 | }
21 |
22 | env_vars: {
23 | key: "TRAMPOLINE_BUILD_FILE"
24 | value: "github/python-bigquery/.kokoro/test-samples.sh"
25 | }
26 |
27 | # Configure the docker image for kokoro-trampoline.
28 | env_vars: {
29 | key: "TRAMPOLINE_IMAGE"
30 | value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
31 | }
32 |
33 | # Download secrets for samples
34 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
35 |
36 | # Download trampoline resources.
37 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
38 |
39 | # Use the trampoline script to run in docker.
40 | build_file: "python-bigquery/.kokoro/trampoline_v2.sh"
--------------------------------------------------------------------------------
/.kokoro/samples/python3.11/continuous.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
--------------------------------------------------------------------------------
/.kokoro/samples/python3.11/periodic-head.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
7 |
8 | env_vars: {
9 | key: "TRAMPOLINE_BUILD_FILE"
10 | value: "github/python-bigquery/.kokoro/test-samples-against-head.sh"
11 | }
12 |
--------------------------------------------------------------------------------
/.kokoro/samples/python3.11/periodic.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "False"
6 | }
7 |
--------------------------------------------------------------------------------
/.kokoro/samples/python3.11/presubmit.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
--------------------------------------------------------------------------------
/.kokoro/samples/python3.12/common.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Build logs will be here
4 | action {
5 | define_artifacts {
6 | regex: "**/*sponge_log.xml"
7 | }
8 | }
9 |
10 | # Specify which tests to run
11 | env_vars: {
12 | key: "RUN_TESTS_SESSION"
13 | value: "py-3.12"
14 | }
15 |
16 | # Declare build specific Cloud project.
17 | env_vars: {
18 | key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
19 | value: "python-docs-samples-tests-312"
20 | }
21 |
22 | env_vars: {
23 | key: "TRAMPOLINE_BUILD_FILE"
24 | value: "github/python-bigquery/.kokoro/test-samples.sh"
25 | }
26 |
27 | # Configure the docker image for kokoro-trampoline.
28 | env_vars: {
29 | key: "TRAMPOLINE_IMAGE"
30 | value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
31 | }
32 |
33 | # Download secrets for samples
34 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
35 |
36 | # Download trampoline resources.
37 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
38 |
39 | # Use the trampoline script to run in docker.
40 | build_file: "python-bigquery/.kokoro/trampoline_v2.sh"
--------------------------------------------------------------------------------
/.kokoro/samples/python3.12/continuous.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
--------------------------------------------------------------------------------
/.kokoro/samples/python3.12/periodic-head.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
7 |
8 | env_vars: {
9 | key: "TRAMPOLINE_BUILD_FILE"
10 | value: "github/python-bigquery/.kokoro/test-samples-against-head.sh"
11 | }
12 |
--------------------------------------------------------------------------------
/.kokoro/samples/python3.12/periodic.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "False"
6 | }
7 |
--------------------------------------------------------------------------------
/.kokoro/samples/python3.12/presubmit.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
--------------------------------------------------------------------------------
/.kokoro/samples/python3.13/common.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Build logs will be here
4 | action {
5 | define_artifacts {
6 | regex: "**/*sponge_log.xml"
7 | }
8 | }
9 |
10 | # Specify which tests to run
11 | env_vars: {
12 | key: "RUN_TESTS_SESSION"
13 | value: "py-3.13"
14 | }
15 |
16 | # Declare build specific Cloud project.
17 | env_vars: {
18 | key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
19 | value: "python-docs-samples-tests-313"
20 | }
21 |
22 | env_vars: {
23 | key: "TRAMPOLINE_BUILD_FILE"
24 | value: "github/python-bigquery/.kokoro/test-samples.sh"
25 | }
26 |
27 | # Configure the docker image for kokoro-trampoline.
28 | env_vars: {
29 | key: "TRAMPOLINE_IMAGE"
30 | value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
31 | }
32 |
33 | # Download secrets for samples
34 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
35 |
36 | # Download trampoline resources.
37 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
38 |
39 | # Use the trampoline script to run in docker.
40 | build_file: "python-bigquery/.kokoro/trampoline_v2.sh"
41 |
--------------------------------------------------------------------------------
/.kokoro/samples/python3.13/continuous.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
--------------------------------------------------------------------------------
/.kokoro/samples/python3.13/periodic-head.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
7 |
8 | env_vars: {
9 | key: "TRAMPOLINE_BUILD_FILE"
10 | value: "github/python-bigquery/.kokoro/test-samples-against-head.sh"
11 | }
12 |
--------------------------------------------------------------------------------
/.kokoro/samples/python3.13/periodic.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "False"
6 | }
7 |
--------------------------------------------------------------------------------
/.kokoro/samples/python3.13/presubmit.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
--------------------------------------------------------------------------------
/.kokoro/samples/python3.9/common.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | # Build logs will be here
4 | action {
5 | define_artifacts {
6 | regex: "**/*sponge_log.xml"
7 | }
8 | }
9 |
10 | # Specify which tests to run
11 | env_vars: {
12 | key: "RUN_TESTS_SESSION"
13 | value: "py-3.9"
14 | }
15 |
16 | # Declare build specific Cloud project.
17 | env_vars: {
18 | key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
19 | value: "python-docs-samples-tests-py39"
20 | }
21 |
22 | env_vars: {
23 | key: "TRAMPOLINE_BUILD_FILE"
24 | value: "github/python-bigquery/.kokoro/test-samples.sh"
25 | }
26 |
27 | # Configure the docker image for kokoro-trampoline.
28 | env_vars: {
29 | key: "TRAMPOLINE_IMAGE"
30 | value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker"
31 | }
32 |
33 | # Download secrets for samples
34 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
35 |
36 | # Download trampoline resources.
37 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline"
38 |
39 | # Use the trampoline script to run in docker.
40 | build_file: "python-bigquery/.kokoro/trampoline_v2.sh"
--------------------------------------------------------------------------------
/.kokoro/samples/python3.9/continuous.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
--------------------------------------------------------------------------------
/.kokoro/samples/python3.9/periodic-head.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
7 |
8 | env_vars: {
9 | key: "TRAMPOLINE_BUILD_FILE"
10 | value: "github/python-bigquery/.kokoro/test-samples-against-head.sh"
11 | }
12 |
--------------------------------------------------------------------------------
/.kokoro/samples/python3.9/periodic.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "False"
6 | }
7 |
--------------------------------------------------------------------------------
/.kokoro/samples/python3.9/presubmit.cfg:
--------------------------------------------------------------------------------
1 | # Format: //devtools/kokoro/config/proto/build.proto
2 |
3 | env_vars: {
4 | key: "INSTALL_LIBRARY_FROM_SOURCE"
5 | value: "True"
6 | }
--------------------------------------------------------------------------------
/.kokoro/test-samples-against-head.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright 2024 Google LLC
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # https://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | # A customized test runner for samples.
17 | #
18 | # For periodic builds, you can specify this file for testing against head.
19 |
20 | # `-e` enables the script to automatically fail when a command fails
21 | # `-o pipefail` sets the exit code to the rightmost comment to exit with a non-zero
22 | set -eo pipefail
23 | # Enables `**` to include files nested inside sub-folders
24 | shopt -s globstar
25 |
26 | exec .kokoro/test-samples-impl.sh
27 |
--------------------------------------------------------------------------------
/.kokoro/trampoline.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright 2024 Google LLC
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | set -eo pipefail
17 |
18 | # Always run the cleanup script, regardless of the success of bouncing into
19 | # the container.
20 | function cleanup() {
21 | chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
22 | ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh
23 | echo "cleanup";
24 | }
25 | trap cleanup EXIT
26 |
27 | $(dirname $0)/populate-secrets.sh # Secret Manager secrets.
28 | python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py"
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2024 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | #
15 | # See https://pre-commit.com for more information
16 | # See https://pre-commit.com/hooks.html for more hooks
17 | repos:
18 | - repo: https://github.com/pre-commit/pre-commit-hooks
19 | rev: v4.0.1
20 | hooks:
21 | - id: trailing-whitespace
22 | - id: end-of-file-fixer
23 | - id: check-yaml
24 | - repo: https://github.com/psf/black
25 | rev: 23.7.0
26 | hooks:
27 | - id: black
28 | - repo: https://github.com/pycqa/flake8
29 | rev: 6.1.0
30 | hooks:
31 | - id: flake8
32 |
--------------------------------------------------------------------------------
/.repo-metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "bigquery",
3 | "name_pretty": "Google Cloud BigQuery",
4 | "product_documentation": "https://cloud.google.com/bigquery",
5 | "client_documentation": "https://cloud.google.com/python/docs/reference/bigquery/latest",
6 | "issue_tracker": "https://issuetracker.google.com/savedsearches/559654",
7 | "release_level": "stable",
8 | "language": "python",
9 | "library_type": "GAPIC_COMBO",
10 | "repo": "googleapis/python-bigquery",
11 | "distribution_name": "google-cloud-bigquery",
12 | "api_id": "bigquery.googleapis.com",
13 | "requires_billing": false,
14 | "default_version": "v2",
15 | "codeowner_team": "@googleapis/api-bigquery",
16 | "api_shortname": "bigquery",
17 | "api_description": "is a fully managed, NoOps, low cost data analytics service.\nData can be streamed into BigQuery at millions of rows per second to enable real-time analysis.\nWith BigQuery you can easily deploy Petabyte-scale Databases."
18 | }
19 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | #
3 | # Copyright 2024 Google LLC
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # https://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | # Generated by synthtool. DO NOT EDIT!
18 | include README.rst LICENSE
19 | recursive-include google *.json *.proto py.typed
20 | recursive-include tests *
21 | global-exclude *.py[co]
22 | global-exclude __pycache__
23 |
24 | # Exclude scripts for samples readmegen
25 | prune scripts/readme-gen
26 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | To report a security issue, please use [g.co/vulnz](https://g.co/vulnz).
4 |
5 | The Google Security Team will respond within 5 working days of your report on g.co/vulnz.
6 |
7 | We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue.
8 |
--------------------------------------------------------------------------------
/benchmark/queries.json:
--------------------------------------------------------------------------------
1 | {
2 | "simple-cacheable": {
3 | "nycyellow-limit1k":"SELECT * FROM `nyc-tlc.yellow.trips` LIMIT 1000",
4 | "nycyellow-limit10k":"SELECT * FROM `nyc-tlc.yellow.trips` LIMIT 10000",
5 | "nycyellow-limit100k":"SELECT * FROM `nyc-tlc.yellow.trips` LIMIT 100000",
6 | "wikisamples-ordered-limit1k":"SELECT title FROM `bigquery-public-data.samples.wikipedia` ORDER BY title LIMIT 1000"
7 | },
8 | "simple-nondeterministic": {
9 | "current-timestamp":"SELECT CURRENT_TIMESTAMP() as ts",
10 | "session-user": "SELECT SESSION_USER() as ts",
11 | "literals": "SELECT 1 as i, 3.14 as pi"
12 | },
13 | "simple-invalid": {
14 | "invalid-query": "invalid sql here"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/docs/.gitignore:
--------------------------------------------------------------------------------
1 | generated/
--------------------------------------------------------------------------------
/docs/README.rst:
--------------------------------------------------------------------------------
1 | ../README.rst
--------------------------------------------------------------------------------
/docs/UPGRADING.md:
--------------------------------------------------------------------------------
1 | ../UPGRADING.md
--------------------------------------------------------------------------------
/docs/_static/custom.css:
--------------------------------------------------------------------------------
1 | div#python2-eol {
2 | border-color: red;
3 | border-width: medium;
4 | }
5 |
6 | /* Ensure minimum width for 'Parameters' / 'Returns' column */
7 | dl.field-list > dt {
8 | min-width: 100px
9 | }
10 |
11 | /* Insert space between methods for readability */
12 | dl.method {
13 | padding-top: 10px;
14 | padding-bottom: 10px
15 | }
16 |
17 | /* Insert empty space between classes */
18 | dl.class {
19 | padding-bottom: 50px
20 | }
21 |
--------------------------------------------------------------------------------
/docs/bigquery/legacy_proto_types.rst:
--------------------------------------------------------------------------------
1 | Legacy proto-based Types for Google Cloud Bigquery v2 API
2 | =========================================================
3 |
4 | .. warning::
5 | These types are provided for backward compatibility only, and are not maintained
6 | anymore. They might also differ from the types supported on the backend. It is
7 | therefore strongly advised to migrate to the types found in :doc:`standard_sql`.
8 |
9 | Also see the :doc:`3.0.0 Migration Guide<../UPGRADING>` for more information.
10 |
11 | .. automodule:: google.cloud.bigquery_v2.types
12 | :members:
13 | :undoc-members:
14 | :show-inheritance:
15 |
--------------------------------------------------------------------------------
/docs/bigquery/standard_sql.rst:
--------------------------------------------------------------------------------
1 | Types for Google Cloud Bigquery v2 API
2 | ======================================
3 |
4 | .. automodule:: google.cloud.bigquery.standard_sql
5 | :members:
6 | :undoc-members:
7 | :show-inheritance:
8 |
--------------------------------------------------------------------------------
/docs/changelog.md:
--------------------------------------------------------------------------------
1 | ../CHANGELOG.md
--------------------------------------------------------------------------------
/docs/design/index.rst:
--------------------------------------------------------------------------------
1 | Client Library Design
2 | =====================
3 |
4 | Some features of this client library have complex requirements and/or
5 | implementation. These documents describe the design decisions that contributued
6 | to those features.
7 |
8 | .. toctree::
9 | :maxdepth: 2
10 |
11 | query-retries
12 |
--------------------------------------------------------------------------------
/docs/enums.rst:
--------------------------------------------------------------------------------
1 | BigQuery Enums
2 | ==============
3 |
4 | .. automodule:: google.cloud.bigquery.enums
5 | :members:
6 | :undoc-members:
7 |
--------------------------------------------------------------------------------
/docs/format_options.rst:
--------------------------------------------------------------------------------
1 | BigQuery Format Options
2 | =======================
3 |
4 | .. automodule:: google.cloud.bigquery.format_options
5 | :members:
6 | :undoc-members:
7 |
--------------------------------------------------------------------------------
/docs/generated/google.cloud.bigquery.magics.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/index.rst:
--------------------------------------------------------------------------------
1 | .. include:: README.rst
2 |
3 | .. note::
4 |
5 | Because the BigQuery client uses the third-party :mod:`requests` library
6 | by default and the BigQuery-Storage client uses :mod:`grpcio` library,
7 | both are safe to share instances across threads. In multiprocessing
8 | scenarios, the best practice is to create client instances *after*
9 | :class:`multiprocessing.Pool` or :class:`multiprocessing.Process` invokes
10 | :func:`os.fork`.
11 |
12 | More Examples
13 | ~~~~~~~~~~~~~
14 |
15 | .. toctree::
16 | :maxdepth: 2
17 |
18 | usage/index
19 | Official Google BigQuery How-to Guides
20 |
21 | API Reference
22 | -------------
23 |
24 | .. toctree::
25 | :maxdepth: 2
26 |
27 | reference
28 | dbapi
29 | design/index
30 |
31 | Migration Guide
32 | ---------------
33 |
34 | See the guides below for instructions on migrating from older to newer *major* releases
35 | of this library (from ``1.x`` to ``2.x``, or from ``2.x`` to ``3.x``).
36 |
37 | .. toctree::
38 | :maxdepth: 2
39 |
40 | UPGRADING
41 |
42 | Changelog
43 | ---------
44 |
45 | For a list of all ``google-cloud-bigquery`` releases:
46 |
47 | .. toctree::
48 | :maxdepth: 2
49 |
50 | changelog
51 |
52 | .. toctree::
53 | :hidden:
54 |
55 | summary_overview.md
56 |
--------------------------------------------------------------------------------
/docs/job_base.rst:
--------------------------------------------------------------------------------
1 | Common Job Resource Classes
2 | ===========================
3 |
4 | .. automodule:: google.cloud.bigquery.job.base
5 | :members:
6 |
--------------------------------------------------------------------------------
/docs/magics.rst:
--------------------------------------------------------------------------------
1 | IPython Magics for BigQuery
2 | ===========================
3 |
4 | To use these magics, you must first register them. Run the ``%load_ext`` magic
5 | in a Jupyter notebook cell.
6 |
7 | .. code::
8 |
9 | %load_ext bigquery_magics
10 |
11 | This makes the ``%%bigquery`` magic available.
12 |
13 | Code Samples
14 | ------------
15 |
16 | Running a query:
17 |
18 | .. literalinclude:: ./samples/magics/query.py
19 | :dedent: 4
20 | :start-after: [START bigquery_jupyter_query]
21 | :end-before: [END bigquery_jupyter_query]
22 |
23 | Running a parameterized query:
24 |
25 | .. literalinclude:: ./samples/magics/query_params_scalars.py
26 | :dedent: 4
27 | :start-after: [START bigquery_jupyter_query_params_scalars]
28 | :end-before: [END bigquery_jupyter_query_params_scalars]
29 |
30 | BigQuery Magics Reference
31 | -------------------------
32 |
33 | - `BigQuery Magics Documentation`_
34 |
35 | .. _BigQuery Magics Documentation: https://googleapis.dev/python/bigquery-magics/latest
36 |
--------------------------------------------------------------------------------
/docs/query.rst:
--------------------------------------------------------------------------------
1 | Query Resource Classes
2 | ======================
3 |
4 | .. automodule:: google.cloud.bigquery.query
5 | :members:
6 |
--------------------------------------------------------------------------------
/docs/samples:
--------------------------------------------------------------------------------
1 | ../samples/
--------------------------------------------------------------------------------
/docs/summary_overview.md:
--------------------------------------------------------------------------------
1 | [
2 | This is a templated file. Adding content to this file may result in it being
3 | reverted. Instead, if you want to place additional content, create an
4 | "overview_content.md" file in `docs/` directory. The Sphinx tool will
5 | pick up on the content and merge the content.
6 | ]: #
7 |
8 | # Google Cloud BigQuery API
9 |
10 | Overview of the APIs available for Google Cloud BigQuery API.
11 |
12 | ## All entries
13 |
14 | Classes, methods and properties & attributes for
15 | Google Cloud BigQuery API.
16 |
17 | [classes](https://cloud.google.com/python/docs/reference/bigquery/latest/summary_class.html)
18 |
19 | [methods](https://cloud.google.com/python/docs/reference/bigquery/latest/summary_method.html)
20 |
21 | [properties and
22 | attributes](https://cloud.google.com/python/docs/reference/bigquery/latest/summary_property.html)
23 |
--------------------------------------------------------------------------------
/docs/usage.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/usage/client.rst:
--------------------------------------------------------------------------------
1 | Creating a Client
2 | ~~~~~~~~~~~~~~~~~
3 |
4 | A project is the top-level container in the ``BigQuery`` API: it is tied
5 | closely to billing, and can provide default access control across all its
6 | datasets. If no ``project`` is passed to the client container, the library
7 | attempts to infer a project using the environment (including explicit
8 | environment variables, GAE, and GCE).
9 |
10 | To override the project inferred from the environment, pass an explicit
11 | ``project`` to the :class:`~google.cloud.bigquery.client.Client` constructor,
12 | or to either of the alternative ``classmethod`` factories:
13 |
14 | .. code-block:: python
15 |
16 | from google.cloud import bigquery
17 | client = bigquery.Client(project='PROJECT_ID')
18 |
19 |
20 | Project ACLs
21 | ^^^^^^^^^^^^
22 |
23 | Each project has an access control list granting reader / writer / owner
24 | permission to one or more entities. This list cannot be queried or set
25 | via the API; it must be managed using the Google Developer Console.
26 |
--------------------------------------------------------------------------------
/docs/usage/index.rst:
--------------------------------------------------------------------------------
1 | Usage Guides
2 | ~~~~~~~~~~~~
3 |
4 | BigQuery Basics
5 | ^^^^^^^^^^^^^^^
6 |
7 | .. toctree::
8 | :maxdepth: 1
9 |
10 | client
11 | queries
12 |
13 | Working with BigQuery Resources
14 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15 |
16 | .. toctree::
17 | :maxdepth: 1
18 |
19 | datasets
20 | tables
21 | encryption
22 | jobs
23 |
24 | Integrations with Other Libraries
25 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26 |
27 | .. toctree::
28 | :maxdepth: 1
29 |
30 | pandas
31 |
32 | See also, the :mod:`google.cloud.bigquery.magics.magics` module for
33 | integrations with Jupyter.
34 |
35 |
36 |
--------------------------------------------------------------------------------
/docs/usage/jobs.rst:
--------------------------------------------------------------------------------
1 | Managing Jobs
2 | ~~~~~~~~~~~~~
3 |
4 | Jobs describe actions performed on data in BigQuery tables:
5 |
6 | - Load data into a table
7 | - Run a query against data in one or more tables
8 | - Extract data from a table
9 | - Copy a table
10 |
11 | Listing jobs
12 | ^^^^^^^^^^^^
13 |
14 | List jobs for a project with the
15 | :func:`~google.cloud.bigquery.client.Client.list_jobs` method:
16 |
17 | .. literalinclude:: ../samples/client_list_jobs.py
18 | :language: python
19 | :dedent: 4
20 | :start-after: [START bigquery_list_jobs]
21 | :end-before: [END bigquery_list_jobs]
22 |
--------------------------------------------------------------------------------
/google/cloud/bigquery/exceptions.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | class BigQueryError(Exception):
17 | """Base class for all custom exceptions defined by the BigQuery client."""
18 |
19 |
20 | class LegacyBigQueryStorageError(BigQueryError):
21 | """Raised when too old a version of BigQuery Storage extra is detected at runtime."""
22 |
23 |
24 | class LegacyPyarrowError(BigQueryError):
25 | """Raised when too old a version of pyarrow package is detected at runtime."""
26 |
27 |
28 | class BigQueryStorageNotFoundError(BigQueryError):
29 | """Raised when BigQuery Storage extra is not installed when trying to
30 | import it.
31 | """
32 |
33 |
34 | class LegacyPandasError(BigQueryError):
35 | """Raised when too old a version of pandas package is detected at runtime."""
36 |
--------------------------------------------------------------------------------
/google/cloud/bigquery/magics/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | from google.cloud.bigquery.magics.magics import context
16 |
17 |
18 | # For backwards compatibility we need to make the context available in the path
19 | # google.cloud.bigquery.magics.context
20 | __all__ = ("context",)
21 |
--------------------------------------------------------------------------------
/google/cloud/bigquery/magics/line_arg_parser/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | from google.cloud.bigquery.magics.line_arg_parser.exceptions import ParseError
16 | from google.cloud.bigquery.magics.line_arg_parser.exceptions import (
17 | DuplicateQueryParamsError,
18 | QueryParamsParseError,
19 | )
20 | from google.cloud.bigquery.magics.line_arg_parser.lexer import Lexer
21 | from google.cloud.bigquery.magics.line_arg_parser.lexer import TokenType
22 | from google.cloud.bigquery.magics.line_arg_parser.parser import Parser
23 | from google.cloud.bigquery.magics.line_arg_parser.visitors import QueryParamsExtractor
24 |
25 |
26 | __all__ = (
27 | "DuplicateQueryParamsError",
28 | "Lexer",
29 | "Parser",
30 | "ParseError",
31 | "QueryParamsExtractor",
32 | "QueryParamsParseError",
33 | "TokenType",
34 | )
35 |
--------------------------------------------------------------------------------
/google/cloud/bigquery/magics/line_arg_parser/exceptions.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | class ParseError(Exception):
17 | pass
18 |
19 |
20 | class QueryParamsParseError(ParseError):
21 | """Raised when --params option is syntactically incorrect."""
22 |
23 |
24 | class DuplicateQueryParamsError(ParseError):
25 | pass
26 |
--------------------------------------------------------------------------------
/google/cloud/bigquery/py.typed:
--------------------------------------------------------------------------------
1 | # Marker file for PEP 561.
2 | # The google-cloud-bigquery package uses inline types.
3 |
--------------------------------------------------------------------------------
/google/cloud/bigquery/routine/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | """User-Defined Routines."""
16 |
17 |
18 | from google.cloud.bigquery.enums import DeterminismLevel
19 | from google.cloud.bigquery.routine.routine import Routine
20 | from google.cloud.bigquery.routine.routine import RoutineArgument
21 | from google.cloud.bigquery.routine.routine import RoutineReference
22 | from google.cloud.bigquery.routine.routine import RoutineType
23 | from google.cloud.bigquery.routine.routine import RemoteFunctionOptions
24 |
25 |
26 | __all__ = (
27 | "DeterminismLevel",
28 | "Routine",
29 | "RoutineArgument",
30 | "RoutineReference",
31 | "RoutineType",
32 | "RemoteFunctionOptions",
33 | )
34 |
--------------------------------------------------------------------------------
/google/cloud/bigquery/version.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | __version__ = "3.34.0"
16 |
--------------------------------------------------------------------------------
/mypy.ini:
--------------------------------------------------------------------------------
1 | [mypy]
2 | python_version = 3.8
3 | namespace_packages = True
4 |
--------------------------------------------------------------------------------
/pylint.config.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | """This module is used to configure gcp-devrel-py-tools run-pylint."""
16 |
17 | # Library configuration
18 |
19 | # library_additions = {}
20 | # library_replacements = {}
21 |
22 | # Test configuration
23 |
24 | # test_additions = copy.deepcopy(library_additions)
25 | # test_replacements = copy.deepcopy(library_replacements)
26 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "config:base",
4 | "group:all",
5 | ":preserveSemverRanges",
6 | ":disableDependencyDashboard"
7 | ],
8 | "ignorePaths": [".pre-commit-config.yaml", ".kokoro/requirements.txt", "setup.py", ".github/workflows/unittest.yml", ".github/workflows/docs.yml"],
9 | "pip_requirements": {
10 | "fileMatch": ["requirements-test.txt", "samples/[\\S/]*constraints.txt", "samples/[\\S/]*constraints-test.txt"]
11 | },
12 | "packageRules": [
13 | {
14 | "matchFileNames": ["pyproject.toml"],
15 | "matchStrings": ["matplotlib (.*); python_version == '3.9'"],
16 | "allowedVersions": ">= 3.7.1, <= 3.9.2"
17 | }
18 | ]
19 | }
20 |
--------------------------------------------------------------------------------
/samples/AUTHORING_GUIDE.md:
--------------------------------------------------------------------------------
1 | See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md
--------------------------------------------------------------------------------
/samples/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/CONTRIBUTING.md
--------------------------------------------------------------------------------
/samples/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleapis/python-bigquery/28a5750d455f0381548df6f9b1f7661823837d81/samples/__init__.py
--------------------------------------------------------------------------------
/samples/dataset_exists.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def dataset_exists(dataset_id: str) -> None:
17 | # [START bigquery_dataset_exists]
18 | from google.cloud import bigquery
19 | from google.cloud.exceptions import NotFound
20 |
21 | client = bigquery.Client()
22 |
23 | # TODO(developer): Set dataset_id to the ID of the dataset to determine existence.
24 | # dataset_id = "your-project.your_dataset"
25 |
26 | try:
27 | client.get_dataset(dataset_id) # Make an API request.
28 | print("Dataset {} already exists".format(dataset_id))
29 | except NotFound:
30 | print("Dataset {} is not found".format(dataset_id))
31 | # [END bigquery_dataset_exists]
32 |
--------------------------------------------------------------------------------
/samples/delete_dataset.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def delete_dataset(dataset_id: str) -> None:
17 | # [START bigquery_delete_dataset]
18 |
19 | from google.cloud import bigquery
20 |
21 | # Construct a BigQuery client object.
22 | client = bigquery.Client()
23 |
24 | # TODO(developer): Set model_id to the ID of the model to fetch.
25 | # dataset_id = 'your-project.your_dataset'
26 |
27 | # Use the delete_contents parameter to delete a dataset and its contents.
28 | # Use the not_found_ok parameter to not receive an error if the dataset has already been deleted.
29 | client.delete_dataset(
30 | dataset_id, delete_contents=True, not_found_ok=True
31 | ) # Make an API request.
32 |
33 | print("Deleted dataset '{}'.".format(dataset_id))
34 | # [END bigquery_delete_dataset]
35 |
--------------------------------------------------------------------------------
/samples/delete_model.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def delete_model(model_id: str) -> None:
17 | """Sample ID: go/samples-tracker/1534"""
18 |
19 | # [START bigquery_delete_model]
20 |
21 | from google.cloud import bigquery
22 |
23 | # Construct a BigQuery client object.
24 | client = bigquery.Client()
25 |
26 | # TODO(developer): Set model_id to the ID of the model to fetch.
27 | # model_id = 'your-project.your_dataset.your_model'
28 |
29 | client.delete_model(model_id) # Make an API request.
30 |
31 | print("Deleted model '{}'.".format(model_id))
32 | # [END bigquery_delete_model]
33 |
--------------------------------------------------------------------------------
/samples/delete_routine.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def delete_routine(routine_id: str) -> None:
17 | # [START bigquery_delete_routine]
18 |
19 | from google.cloud import bigquery
20 |
21 | # Construct a BigQuery client object.
22 | client = bigquery.Client()
23 |
24 | # TODO(developer): Set the fully-qualified ID for the routine.
25 | # routine_id = "my-project.my_dataset.my_routine"
26 |
27 | client.delete_routine(routine_id) # Make an API request.
28 |
29 | print("Deleted routine {}.".format(routine_id))
30 | # [END bigquery_delete_routine]
31 |
--------------------------------------------------------------------------------
/samples/delete_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def delete_table(table_id: str) -> None:
17 | # [START bigquery_delete_table]
18 |
19 | from google.cloud import bigquery
20 |
21 | # Construct a BigQuery client object.
22 | client = bigquery.Client()
23 |
24 | # TODO(developer): Set table_id to the ID of the table to fetch.
25 | # table_id = 'your-project.your_dataset.your_table'
26 |
27 | # If the table does not exist, delete_table raises
28 | # google.api_core.exceptions.NotFound unless not_found_ok is True.
29 | client.delete_table(table_id, not_found_ok=True) # Make an API request.
30 | print("Deleted table '{}'.".format(table_id))
31 | # [END bigquery_delete_table]
32 |
--------------------------------------------------------------------------------
/samples/desktopapp/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
--------------------------------------------------------------------------------
/samples/desktopapp/conftest.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | from google.cloud import bigquery
16 | import pytest
17 |
18 |
19 | @pytest.fixture
20 | def bigquery_client_patch(
21 | monkeypatch: pytest.MonkeyPatch, bigquery_client: bigquery.Client
22 | ) -> None:
23 | monkeypatch.setattr(bigquery, "Client", lambda: bigquery_client)
24 |
--------------------------------------------------------------------------------
/samples/desktopapp/mypy.ini:
--------------------------------------------------------------------------------
1 | [mypy]
2 | ; We require type annotations in all samples.
3 | strict = True
4 | exclude = noxfile\.py
5 | warn_unused_configs = True
6 |
7 | [mypy-google.auth,google.oauth2,geojson,google_auth_oauthlib,IPython.*]
8 | ignore_missing_imports = True
9 |
--------------------------------------------------------------------------------
/samples/desktopapp/requirements-test.txt:
--------------------------------------------------------------------------------
1 | google-cloud-testutils==1.6.4
2 | pytest==8.3.5
3 | mock==5.2.0
4 | pytest-xdist==3.7.0
5 |
--------------------------------------------------------------------------------
/samples/desktopapp/requirements.txt:
--------------------------------------------------------------------------------
1 | google-cloud-bigquery==3.34.0
2 | google-auth-oauthlib==1.2.2
3 |
--------------------------------------------------------------------------------
/samples/download_public_data.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def download_public_data() -> None:
17 | # [START bigquery_pandas_public_data]
18 |
19 | from google.cloud import bigquery
20 |
21 | # Construct a BigQuery client object.
22 | client = bigquery.Client()
23 |
24 | # TODO(developer): Set table_id to the fully-qualified table ID in standard
25 | # SQL format, including the project ID and dataset ID.
26 | table_id = "bigquery-public-data.usa_names.usa_1910_current"
27 |
28 | # Use the BigQuery Storage API to speed-up downloads of large tables.
29 | dataframe = client.list_rows(table_id).to_dataframe(create_bqstorage_client=True)
30 |
31 | print(dataframe.info())
32 | # [END bigquery_pandas_public_data]
33 |
--------------------------------------------------------------------------------
/samples/geography/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
--------------------------------------------------------------------------------
/samples/geography/insert_geojson_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | from . import insert_geojson
16 |
17 |
18 | def test_insert_geojson(table_id: str) -> None:
19 | errors = insert_geojson.insert_geojson(override_values={"table_id": table_id})
20 | assert not errors
21 |
--------------------------------------------------------------------------------
/samples/geography/insert_wkt_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | from . import insert_wkt
16 |
17 |
18 | def test_insert_wkt(table_id: str) -> None:
19 | errors = insert_wkt.insert_wkt(override_values={"table_id": table_id})
20 | assert not errors
21 |
--------------------------------------------------------------------------------
/samples/geography/mypy.ini:
--------------------------------------------------------------------------------
1 | [mypy]
2 | ; We require type annotations in all samples.
3 | strict = True
4 | exclude = noxfile\.py
5 | warn_unused_configs = True
6 |
7 | [mypy-geojson,pandas,shapely.*]
8 | ignore_missing_imports = True
9 |
--------------------------------------------------------------------------------
/samples/geography/requirements-test.txt:
--------------------------------------------------------------------------------
1 | pytest==8.3.5
2 | mock==5.2.0
3 | pytest-xdist==3.7.0
4 |
--------------------------------------------------------------------------------
/samples/geography/requirements.txt:
--------------------------------------------------------------------------------
1 | attrs==25.3.0
2 | certifi==2025.4.26
3 | cffi==1.17.1
4 | charset-normalizer==3.4.2
5 | click===8.1.8; python_version == '3.9'
6 | click==8.2.1; python_version >= '3.10'
7 | click-plugins==1.1.1
8 | cligj==0.7.2
9 | db-dtypes==1.4.3
10 | Fiona==1.10.1
11 | geojson==3.2.0
12 | geopandas==1.0.1
13 | google-api-core==2.24.2
14 | google-auth==2.40.2
15 | google-cloud-bigquery==3.34.0
16 | google-cloud-bigquery-storage==2.32.0
17 | google-cloud-core==2.4.3
18 | google-crc32c==1.7.1
19 | google-resumable-media==2.7.2
20 | googleapis-common-protos==1.70.0
21 | grpcio==1.71.0
22 | idna==3.10
23 | munch==4.0.0
24 | mypy-extensions==1.1.0
25 | packaging==25.0
26 | pandas==2.2.3
27 | proto-plus==1.26.1
28 | pyarrow==20.0.0
29 | pyasn1==0.6.1
30 | pyasn1-modules==0.4.2
31 | pycparser==2.22
32 | pyparsing==3.2.3
33 | python-dateutil==2.9.0.post0
34 | pytz==2025.2
35 | PyYAML==6.0.2
36 | requests==2.32.3
37 | rsa==4.9.1
38 | Shapely===2.0.7; python_version == '3.9'
39 | Shapely==2.1.1; python_version >= '3.10'
40 | six==1.17.0
41 | typing-extensions==4.13.2
42 | typing-inspect==0.9.0
43 | urllib3==2.4.0
44 |
--------------------------------------------------------------------------------
/samples/geography/to_geodataframe.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from google.cloud import bigquery
18 |
19 | if typing.TYPE_CHECKING:
20 | import pandas
21 |
22 |
23 | client: bigquery.Client = bigquery.Client()
24 |
25 |
26 | def get_austin_service_requests_as_geography() -> "pandas.DataFrame":
27 | # [START bigquery_query_results_geodataframe]
28 |
29 | sql = """
30 | SELECT created_date, complaint_description,
31 | ST_GEOGPOINT(longitude, latitude) as location
32 | FROM bigquery-public-data.austin_311.311_service_requests
33 | LIMIT 10
34 | """
35 |
36 | df = client.query_and_wait(sql).to_geodataframe()
37 | # [END bigquery_query_results_geodataframe]
38 | return df
39 |
--------------------------------------------------------------------------------
/samples/geography/to_geodataframe_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import pytest
16 |
17 | from .to_geodataframe import get_austin_service_requests_as_geography
18 |
19 |
20 | def test_get_austin_service_requests_as_geography() -> None:
21 | geopandas = pytest.importorskip("geopandas")
22 | df = get_austin_service_requests_as_geography()
23 | assert isinstance(df, geopandas.GeoDataFrame)
24 | assert len(list(df)) == 3 # verify the number of columns
25 | assert len(df) == 10 # verify the number of rows
26 |
--------------------------------------------------------------------------------
/samples/get_model.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def get_model(model_id: str) -> None:
17 | """Sample ID: go/samples-tracker/1510"""
18 |
19 | # [START bigquery_get_model]
20 |
21 | from google.cloud import bigquery
22 |
23 | # Construct a BigQuery client object.
24 | client = bigquery.Client()
25 |
26 | # TODO(developer): Set model_id to the ID of the model to fetch.
27 | # model_id = 'your-project.your_dataset.your_model'
28 |
29 | model = client.get_model(model_id) # Make an API request.
30 |
31 | full_model_id = "{}.{}.{}".format(model.project, model.dataset_id, model.model_id)
32 | friendly_name = model.friendly_name
33 | print(
34 | "Got model '{}' with friendly_name '{}'.".format(full_model_id, friendly_name)
35 | )
36 | # [END bigquery_get_model]
37 |
--------------------------------------------------------------------------------
/samples/get_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def get_table(table_id: str) -> None:
17 | # [START bigquery_get_table]
18 |
19 | from google.cloud import bigquery
20 |
21 | # Construct a BigQuery client object.
22 | client = bigquery.Client()
23 |
24 | # TODO(developer): Set table_id to the ID of the model to fetch.
25 | # table_id = 'your-project.your_dataset.your_table'
26 |
27 | table = client.get_table(table_id) # Make an API request.
28 |
29 | # View table properties
30 | print(
31 | "Got table '{}.{}.{}'.".format(table.project, table.dataset_id, table.table_id)
32 | )
33 | print("Table schema: {}".format(table.schema))
34 | print("Table description: {}".format(table.description))
35 | print("Table has {} rows".format(table.num_rows))
36 | # [END bigquery_get_table]
37 |
--------------------------------------------------------------------------------
/samples/label_dataset.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def label_dataset(dataset_id: str) -> None:
17 | # [START bigquery_label_dataset]
18 |
19 | from google.cloud import bigquery
20 |
21 | # Construct a BigQuery client object.
22 | client = bigquery.Client()
23 |
24 | # TODO(developer): Set dataset_id to the ID of the dataset to fetch.
25 | # dataset_id = "your-project.your_dataset"
26 |
27 | dataset = client.get_dataset(dataset_id) # Make an API request.
28 | dataset.labels = {"color": "green"}
29 | dataset = client.update_dataset(dataset, ["labels"]) # Make an API request.
30 |
31 | print("Labels added to {}".format(dataset_id))
32 | # [END bigquery_label_dataset]
33 |
--------------------------------------------------------------------------------
/samples/list_datasets.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def list_datasets() -> None:
17 | # [START bigquery_list_datasets]
18 |
19 | from google.cloud import bigquery
20 |
21 | # Construct a BigQuery client object.
22 | client = bigquery.Client()
23 |
24 | datasets = list(client.list_datasets()) # Make an API request.
25 | project = client.project
26 |
27 | if datasets:
28 | print("Datasets in project {}:".format(project))
29 | for dataset in datasets:
30 | print("\t{}".format(dataset.dataset_id))
31 | else:
32 | print("{} project does not contain any datasets.".format(project))
33 | # [END bigquery_list_datasets]
34 |
--------------------------------------------------------------------------------
/samples/list_datasets_by_label.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def list_datasets_by_label() -> None:
17 | # [START bigquery_list_datasets_by_label]
18 |
19 | from google.cloud import bigquery
20 |
21 | # Construct a BigQuery client object.
22 | client = bigquery.Client()
23 |
24 | label_filter = "labels.color:green"
25 | datasets = list(client.list_datasets(filter=label_filter)) # Make an API request.
26 |
27 | if datasets:
28 | print("Datasets filtered by {}:".format(label_filter))
29 | for dataset in datasets:
30 | print("\t{}.{}".format(dataset.project, dataset.dataset_id))
31 | else:
32 | print("No datasets found with this filter.")
33 | # [END bigquery_list_datasets_by_label]
34 |
--------------------------------------------------------------------------------
/samples/list_routines.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def list_routines(dataset_id: str) -> None:
17 | # [START bigquery_list_routines]
18 |
19 | from google.cloud import bigquery
20 |
21 | # Construct a BigQuery client object.
22 | client = bigquery.Client()
23 |
24 | # TODO(developer): Set dataset_id to the ID of the dataset that contains
25 | # the routines you are listing.
26 | # dataset_id = 'your-project.your_dataset'
27 |
28 | routines = client.list_routines(dataset_id) # Make an API request.
29 |
30 | print("Routines contained in dataset {}:".format(dataset_id))
31 | for routine in routines:
32 | print(routine.reference)
33 | # [END bigquery_list_routines]
34 |
--------------------------------------------------------------------------------
/samples/list_tables.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def list_tables(dataset_id: str) -> None:
17 | # [START bigquery_list_tables]
18 |
19 | from google.cloud import bigquery
20 |
21 | # Construct a BigQuery client object.
22 | client = bigquery.Client()
23 |
24 | # TODO(developer): Set dataset_id to the ID of the dataset that contains
25 | # the tables you are listing.
26 | # dataset_id = 'your-project.your_dataset'
27 |
28 | tables = client.list_tables(dataset_id) # Make an API request.
29 |
30 | print("Tables contained in '{}':".format(dataset_id))
31 | for table in tables:
32 | print("{}.{}.{}".format(table.project, table.dataset_id, table.table_id))
33 | # [END bigquery_list_tables]
34 |
--------------------------------------------------------------------------------
/samples/magics/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
--------------------------------------------------------------------------------
/samples/magics/_helpers.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def strip_region_tags(sample_text: str) -> str:
17 | """Remove blank lines and region tags from sample text"""
18 | magic_lines = [
19 | line for line in sample_text.split("\n") if len(line) > 0 and "# [" not in line
20 | ]
21 | return "\n".join(magic_lines)
22 |
--------------------------------------------------------------------------------
/samples/magics/mypy.ini:
--------------------------------------------------------------------------------
1 | [mypy]
2 | ; We require type annotations in all samples.
3 | strict = True
4 | exclude = noxfile\.py
5 | warn_unused_configs = True
6 |
7 | [mypy-IPython.*,nox,noxfile_config,pandas]
8 | ignore_missing_imports = True
9 |
--------------------------------------------------------------------------------
/samples/magics/query_params_scalars_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import pandas
16 |
17 | from . import query_params_scalars
18 |
19 |
20 | def test_query_with_parameters() -> None:
21 | df = query_params_scalars.query_with_parameters()
22 | assert isinstance(df, pandas.DataFrame)
23 | assert len(df) == 10
24 |
--------------------------------------------------------------------------------
/samples/magics/query_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import pandas
16 |
17 | from . import query
18 |
19 |
20 | def test_query() -> None:
21 | df = query.query()
22 | assert isinstance(df, pandas.DataFrame)
23 | assert len(df) == 3
24 |
--------------------------------------------------------------------------------
/samples/magics/requirements-test.txt:
--------------------------------------------------------------------------------
1 | google-cloud-testutils==1.6.4
2 | pytest==8.3.5
3 | mock==5.2.0
4 | pytest-xdist==3.7.0
5 |
--------------------------------------------------------------------------------
/samples/magics/requirements.txt:
--------------------------------------------------------------------------------
1 | bigquery_magics==0.10.0
2 | db-dtypes==1.4.3
3 | google.cloud.bigquery==3.34.0
4 | google-cloud-bigquery-storage==2.32.0
5 | ipython===8.18.1
6 | pandas==2.2.3
7 |
--------------------------------------------------------------------------------
/samples/mypy.ini:
--------------------------------------------------------------------------------
1 | [mypy]
2 | # Should match DEFAULT_PYTHON_VERSION from root noxfile.py
3 | python_version = 3.8
4 | exclude = noxfile\.py
5 | warn_unused_configs = True
6 |
7 | [mypy-google.auth,google.oauth2,geojson,google_auth_oauthlib,IPython.*]
8 | ignore_missing_imports = True
9 |
10 | [mypy-pandas,pyarrow,shapely.*,test_utils.*]
11 | ignore_missing_imports = True
12 |
--------------------------------------------------------------------------------
/samples/notebooks/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
--------------------------------------------------------------------------------
/samples/notebooks/conftest.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | from google.cloud import bigquery
16 | import pytest
17 |
18 |
19 | @pytest.fixture
20 | def bigquery_client_patch(
21 | monkeypatch: pytest.MonkeyPatch, bigquery_client: bigquery.Client
22 | ) -> None:
23 | monkeypatch.setattr(bigquery, "Client", lambda: bigquery_client)
24 |
--------------------------------------------------------------------------------
/samples/notebooks/mypy.ini:
--------------------------------------------------------------------------------
1 | [mypy]
2 | ; We require type annotations in all samples.
3 | strict = True
4 | exclude = noxfile\.py
5 | warn_unused_configs = True
6 |
7 | [mypy-IPython.*,nox,noxfile_config,pandas]
8 | ignore_missing_imports = True
--------------------------------------------------------------------------------
/samples/notebooks/requirements-test.txt:
--------------------------------------------------------------------------------
1 | google-cloud-testutils==1.6.4
2 | pytest==8.3.5
3 | mock==5.2.0
4 | pytest-xdist==3.7.0
5 |
--------------------------------------------------------------------------------
/samples/notebooks/requirements.txt:
--------------------------------------------------------------------------------
1 | bigquery-magics==0.10.0
2 | db-dtypes==1.4.3
3 | google-cloud-bigquery==3.34.0
4 | google-cloud-bigquery-storage==2.32.0
5 | ipython===8.18.1; python_version == '3.9'
6 | ipython==9.2.0; python_version >= '3.10'
7 | matplotlib===3.9.2; python_version == '3.9'
8 | matplotlib==3.10.3; python_version >= '3.10'
9 | pandas==2.2.3
10 |
--------------------------------------------------------------------------------
/samples/query_no_cache.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def query_no_cache() -> None:
17 | # [START bigquery_query_no_cache]
18 | from google.cloud import bigquery
19 |
20 | # Construct a BigQuery client object.
21 | client = bigquery.Client()
22 |
23 | job_config = bigquery.QueryJobConfig(use_query_cache=False)
24 | sql = """
25 | SELECT corpus
26 | FROM `bigquery-public-data.samples.shakespeare`
27 | GROUP BY corpus;
28 | """
29 | results = client.query_and_wait(sql, job_config=job_config) # Make an API request.
30 |
31 | for row in results:
32 | print(row)
33 | # [END bigquery_query_no_cache]
34 |
--------------------------------------------------------------------------------
/samples/snippets/.gitignore:
--------------------------------------------------------------------------------
1 | client_secrets.json
2 | service_account.json
3 |
--------------------------------------------------------------------------------
/samples/snippets/README.rst.in:
--------------------------------------------------------------------------------
1 | # This file is used to generate README.rst
2 |
3 | product:
4 | name: Google BigQuery
5 | short_name: BigQuery
6 | url: https://cloud.google.com/bigquery/docs
7 | description: >
8 | `Google BigQuery`_ is Google's fully managed, petabyte scale, low cost
9 | analytics data warehouse. BigQuery is NoOps—there is no infrastructure to
10 | manage and you don't need a database administrator—so you can focus on
11 | analyzing data to find meaningful insights, use familiar SQL, and take
12 | advantage of our pay-as-you-go model.
13 |
14 | required_role: BigQuery Admin
15 |
16 | setup:
17 | - auth
18 | - install_deps
19 |
20 | samples:
21 | - name: Quickstart
22 | file: quickstart.py
23 | - name: Simple Application
24 | file: simple_app.py
25 | - name: User Credentials
26 | file: user_credentials.py
27 | show_help: true
28 |
29 | cloud_client_library: true
30 |
31 | folder: bigquery/cloud-client
32 |
--------------------------------------------------------------------------------
/samples/snippets/authenticate_service_account_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 | from typing import Any
17 |
18 | import google.auth
19 |
20 | import authenticate_service_account # type: ignore
21 |
22 | if typing.TYPE_CHECKING:
23 | import pytest
24 |
25 |
26 | def mock_credentials(*args: Any, **kwargs: Any) -> google.auth.credentials.Credentials:
27 | credentials, _ = google.auth.default(
28 | ["https://www.googleapis.com/auth/cloud-platform"]
29 | )
30 | return credentials
31 |
32 |
33 | def test_main(monkeypatch: "pytest.MonkeyPatch") -> None:
34 | monkeypatch.setattr(
35 | "google.oauth2.service_account.Credentials.from_service_account_file",
36 | mock_credentials,
37 | )
38 | client = authenticate_service_account.main()
39 | assert client is not None
40 |
--------------------------------------------------------------------------------
/samples/snippets/client_query_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import client_query # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query(capsys: "pytest.CaptureFixture[str]") -> None:
24 | client_query.client_query()
25 | out, _ = capsys.readouterr()
26 | assert "The query data:" in out
27 | assert "name=James, count=272793" in out
28 |
29 |
30 | def test_client_query_job_optional(
31 | capsys: "pytest.CaptureFixture[str]", monkeypatch: "pytest.MonkeyPatch"
32 | ) -> None:
33 | monkeypatch.setenv("QUERY_PREVIEW_ENABLED", "true")
34 |
35 | client_query.client_query()
36 | out, _ = capsys.readouterr()
37 | assert "The query data:" in out
38 | assert "name=James, count=272793" in out
39 |
--------------------------------------------------------------------------------
/samples/snippets/create_partitioned_table_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import create_partitioned_table # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_create_partitioned_table(
24 | capsys: "pytest.CaptureFixture[str]",
25 | random_table_id: str,
26 | ) -> None:
27 | table = create_partitioned_table.create_partitioned_table(random_table_id)
28 |
29 | out, _ = capsys.readouterr()
30 | assert "Created" in out
31 | assert random_table_id in out
32 |
33 | assert table.time_partitioning.type_ == "DAY"
34 | assert table.time_partitioning.field == "date"
35 |
--------------------------------------------------------------------------------
/samples/snippets/create_table_cmek_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import create_table_cmek # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_create_table(
24 | capsys: "pytest.CaptureFixture[str]",
25 | random_table_id: str,
26 | ) -> None:
27 | kms_key_name = (
28 | "projects/cloud-samples-tests/locations/us/keyRings/test/cryptoKeys/test"
29 | )
30 |
31 | create_table_cmek.create_table_cmek(random_table_id, kms_key_name)
32 |
33 | out, _ = capsys.readouterr()
34 | assert "Created" in out
35 | assert random_table_id in out
36 | assert kms_key_name in out
37 |
--------------------------------------------------------------------------------
/samples/snippets/create_table_external_data_configuration_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import create_table_external_data_configuration # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_create_table_external_data_configuration(
24 | capsys: "pytest.CaptureFixture[str]",
25 | random_table_id: str,
26 | ) -> None:
27 | create_table_external_data_configuration.create_table_external_data_configuration(
28 | random_table_id
29 | )
30 | out, _ = capsys.readouterr()
31 | assert "Created table with external source format AVRO" in out
32 |
--------------------------------------------------------------------------------
/samples/snippets/create_table_schema_from_json_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import create_table_schema_from_json # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_create_table(
24 | capsys: "pytest.CaptureFixture[str]",
25 | random_table_id: str,
26 | ) -> None:
27 | create_table_schema_from_json.create_table(random_table_id)
28 |
29 | out, _ = capsys.readouterr()
30 | assert "Created" in out
31 | assert random_table_id in out
32 |
--------------------------------------------------------------------------------
/samples/snippets/create_table_snapshot_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import create_table_snapshot # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_create_table_snapshot(
24 | capsys: "pytest.CaptureFixture[str]",
25 | table_id: str,
26 | random_table_id: str,
27 | ) -> None:
28 | create_table_snapshot.create_table_snapshot(table_id, random_table_id)
29 |
30 | out, _ = capsys.readouterr()
31 |
32 | assert "Created table snapshot {}".format(random_table_id) in out
33 |
--------------------------------------------------------------------------------
/samples/snippets/delete_label_table_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import delete_label_table # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_delete_label_table(
24 | capsys: "pytest.CaptureFixture[str]",
25 | table_id: str,
26 | ) -> None:
27 | table = delete_label_table.delete_label_table(table_id, "color")
28 |
29 | out, _ = capsys.readouterr()
30 | assert "Deleted" in out
31 | assert "color" in out
32 | assert table_id in out
33 | assert table.labels is None or "color" not in table.labels
34 |
--------------------------------------------------------------------------------
/samples/snippets/get_table_make_schema_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import get_table_make_schema # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pathlib
21 |
22 | import pytest
23 |
24 |
25 | def test_get_table_make_schema(
26 | capsys: "pytest.CaptureFixture[str]",
27 | table_id: str,
28 | tmp_path: "pathlib.Path",
29 | ) -> None:
30 | schema_path = str(tmp_path / "test_schema.json")
31 |
32 | get_table_make_schema.get_table_make_schema(table_id, schema_path)
33 |
34 | out, _ = capsys.readouterr()
35 | assert "Got table" in out
36 | assert table_id in out
37 |
--------------------------------------------------------------------------------
/samples/snippets/label_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def label_table(table_id: str) -> None:
17 | orig_table_id = table_id
18 | # [START bigquery_label_table]
19 | from google.cloud import bigquery
20 |
21 | client = bigquery.Client()
22 |
23 | # TODO(dev): Change table_id to the full name of the table you want to create.
24 | table_id = "your-project.your_dataset.your_table_name"
25 |
26 | # [END bigquery_label_table]
27 | table_id = orig_table_id
28 | # [START bigquery_label_table]
29 | table = client.get_table(table_id) # API request
30 |
31 | labels = {"color": "green"}
32 | table.labels = labels
33 |
34 | table = client.update_table(table, ["labels"]) # API request
35 |
36 | print(f"Added {table.labels} to {table_id}.")
37 | # [END bigquery_label_table]
38 |
--------------------------------------------------------------------------------
/samples/snippets/label_table_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import label_table # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_label_table(
24 | capsys: "pytest.CaptureFixture[str]",
25 | table_id: str,
26 | ) -> None:
27 | label_table.label_table(table_id)
28 |
29 | out, _ = capsys.readouterr()
30 | assert "color" in out
31 | assert table_id in out
32 |
--------------------------------------------------------------------------------
/samples/snippets/load_table_schema_from_json_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import load_table_schema_from_json # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table(
24 | capsys: "pytest.CaptureFixture[str]",
25 | random_table_id: str,
26 | ) -> None:
27 | load_table_schema_from_json.load_table(random_table_id)
28 |
29 | out, _ = capsys.readouterr()
30 | assert "Loaded" in out
31 | assert random_table_id in out
32 |
--------------------------------------------------------------------------------
/samples/snippets/load_table_uri_firestore_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import load_table_uri_firestore # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_firestore(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_firestore.load_table_uri_firestore(random_table_id)
27 | out, _ = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/snippets/manage_job_cancel.py:
--------------------------------------------------------------------------------
1 | # Copyright 2016-2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | # [START bigquery_cancel_job]
16 | from google.cloud import bigquery
17 |
18 |
19 | def cancel_job(
20 | client: bigquery.Client,
21 | location: str = "us",
22 | job_id: str = "abcd-efgh-ijkl-mnop",
23 | ) -> None:
24 | job = client.cancel_job(job_id, location=location)
25 | print(f"{job.location}:{job.job_id} cancelled")
26 |
27 |
28 | # [END bigquery_cancel_job]
29 |
--------------------------------------------------------------------------------
/samples/snippets/manage_job_get.py:
--------------------------------------------------------------------------------
1 | # Copyright 2016-2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | # [START bigquery_get_job]
16 | from google.cloud import bigquery
17 |
18 |
19 | def get_job(
20 | client: bigquery.Client,
21 | location: str = "us",
22 | job_id: str = "abcd-efgh-ijkl-mnop",
23 | ) -> None:
24 | job = client.get_job(job_id, location=location)
25 |
26 | # All job classes have "location" and "job_id" string properties.
27 | # Use these properties for job operations such as "cancel_job" and
28 | # "delete_job".
29 | print(f"{job.location}:{job.job_id}")
30 | print(f"Type: {job.job_type}")
31 | print(f"State: {job.state}")
32 | print(f"Created: {job.created.isoformat()}")
33 |
34 |
35 | # [END bigquery_get_job]
36 |
--------------------------------------------------------------------------------
/samples/snippets/mypy.ini:
--------------------------------------------------------------------------------
1 | [mypy]
2 | ; We require type annotations in all samples.
3 | strict = True
4 | exclude = noxfile\.py
5 | warn_unused_configs = True
6 |
7 | [mypy-google.auth,google.oauth2,google_auth_oauthlib,IPython.*,test_utils.*]
8 | ignore_missing_imports = True
9 |
--------------------------------------------------------------------------------
/samples/snippets/nested_repeated_schema_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2022 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import nested_repeated_schema # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_create_table(
24 | capsys: "pytest.CaptureFixture[str]",
25 | random_table_id: str,
26 | ) -> None:
27 | nested_repeated_schema.nested_schema(random_table_id)
28 |
29 | out, _ = capsys.readouterr()
30 | assert "Created" in out
31 | assert random_table_id in out
32 |
--------------------------------------------------------------------------------
/samples/snippets/requirements-test.txt:
--------------------------------------------------------------------------------
1 | # samples/snippets should be runnable with no "extras"
2 | google-cloud-testutils==1.6.4
3 | pytest==8.3.5
4 | mock==5.2.0
5 | pytest-xdist==3.7.0
6 |
--------------------------------------------------------------------------------
/samples/snippets/requirements.txt:
--------------------------------------------------------------------------------
1 | # samples/snippets should be runnable with no "extras"
2 | google-cloud-bigquery==3.34.0
3 |
--------------------------------------------------------------------------------
/samples/snippets/schema.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "qtr",
4 | "type": "STRING",
5 | "mode": "REQUIRED",
6 | "description": "quarter"
7 | },
8 | {
9 | "name": "rep",
10 | "type": "STRING",
11 | "mode": "NULLABLE",
12 | "description": "sales representative"
13 | },
14 | {
15 | "name": "sales",
16 | "type": "FLOAT",
17 | "mode": "NULLABLE",
18 | "defaultValueExpression": "2.55"
19 | }
20 | ]
21 |
--------------------------------------------------------------------------------
/samples/snippets/schema_us_states.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "name",
4 | "type": "STRING",
5 | "mode": "NULLABLE"
6 | },
7 | {
8 | "name": "post_abbr",
9 | "type": "STRING",
10 | "mode": "NULLABLE"
11 | }
12 | ]
13 |
--------------------------------------------------------------------------------
/samples/snippets/simple_app_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2016 Google Inc. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import simple_app # type: ignore
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_query_stackoverflow(capsys: "pytest.CaptureFixture[str]") -> None:
24 | simple_app.query_stackoverflow()
25 | out, _ = capsys.readouterr()
26 | assert "views" in out
27 |
--------------------------------------------------------------------------------
/samples/table_exists.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 |
16 | def table_exists(table_id: str) -> None:
17 | # [START bigquery_table_exists]
18 | from google.cloud import bigquery
19 | from google.cloud.exceptions import NotFound
20 |
21 | client = bigquery.Client()
22 |
23 | # TODO(developer): Set table_id to the ID of the table to determine existence.
24 | # table_id = "your-project.your_dataset.your_table"
25 |
26 | try:
27 | client.get_table(table_id) # Make an API request.
28 | print("Table {} already exists.".format(table_id))
29 | except NotFound:
30 | print("Table {} is not found.".format(table_id))
31 | # [END bigquery_table_exists]
32 |
--------------------------------------------------------------------------------
/samples/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleapis/python-bigquery/28a5750d455f0381548df6f9b1f7661823837d81/samples/tests/__init__.py
--------------------------------------------------------------------------------
/samples/tests/test_add_empty_column.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import add_empty_column
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_add_empty_column(capsys: "pytest.CaptureFixture[str]", table_id: str) -> None:
24 | add_empty_column.add_empty_column(table_id)
25 | out, err = capsys.readouterr()
26 | assert "A new column has been added." in out
27 |
--------------------------------------------------------------------------------
/samples/tests/test_browse_table_data.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import browse_table_data
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_browse_table_data(
24 | capsys: "pytest.CaptureFixture[str]", table_with_data_id: str
25 | ) -> None:
26 | browse_table_data.browse_table_data(table_with_data_id)
27 | out, err = capsys.readouterr()
28 | assert "Downloaded 164656 rows from table {}".format(table_with_data_id) in out
29 | assert "Downloaded 10 rows from table {}".format(table_with_data_id) in out
30 | assert "Selected 2 columns from table {}".format(table_with_data_id) in out
31 | assert "Downloaded 10 rows from table {}".format(table_with_data_id) in out
32 | assert "word" in out
33 | assert "LVII" in out
34 |
--------------------------------------------------------------------------------
/samples/tests/test_client_list_jobs.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_list_jobs
18 | from .. import create_job
19 |
20 | if typing.TYPE_CHECKING:
21 | from google.cloud import bigquery
22 | import pytest
23 |
24 |
25 | def test_client_list_jobs(
26 | capsys: "pytest.CaptureFixture[str]", client: "bigquery.Client"
27 | ) -> None:
28 | job = create_job.create_job()
29 | client.cancel_job(job.job_id)
30 | job.cancel()
31 | client_list_jobs.client_list_jobs()
32 | out, err = capsys.readouterr()
33 | assert "Started job: {}".format(job.job_id) in out
34 | assert "Last 10 jobs:" in out
35 | assert "Jobs from the last ten minutes:" in out
36 | assert "Last 10 jobs run by all users:" in out
37 | assert "Last 10 jobs done:" in out
38 |
--------------------------------------------------------------------------------
/samples/tests/test_client_load_partitioned_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_load_partitioned_table
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_load_partitioned_table(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | client_load_partitioned_table.client_load_partitioned_table(random_table_id)
27 | out, err = capsys.readouterr()
28 | assert "Loaded 50 rows to table {}".format(random_table_id) in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_batch.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_query_batch
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query_batch(capsys: "pytest.CaptureFixture[str]") -> None:
24 | job = client_query_batch.client_query_batch()
25 | out, err = capsys.readouterr()
26 | assert "Job {} is currently in state {}".format(job.job_id, job.state) in out
27 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_destination_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_query_destination_table
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query_destination_table(
24 | capsys: "pytest.CaptureFixture[str]", table_id: str
25 | ) -> None:
26 | client_query_destination_table.client_query_destination_table(table_id)
27 | out, err = capsys.readouterr()
28 | assert "Query results loaded to the table {}".format(table_id) in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_destination_table_clustered.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_query_destination_table_clustered
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query_destination_table_clustered(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | client_query_destination_table_clustered.client_query_destination_table_clustered(
27 | random_table_id
28 | )
29 | out, err = capsys.readouterr()
30 | assert (
31 | "The destination table is written using the cluster_fields configuration."
32 | in out
33 | )
34 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_destination_table_cmek.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_query_destination_table_cmek
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query_destination_table_cmek(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str, kms_key_name: str
25 | ) -> None:
26 | client_query_destination_table_cmek.client_query_destination_table_cmek(
27 | random_table_id, kms_key_name
28 | )
29 | out, err = capsys.readouterr()
30 | assert "The destination table is written using the encryption configuration" in out
31 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_destination_table_legacy.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_query_destination_table_legacy
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query_destination_table_legacy(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | client_query_destination_table_legacy.client_query_destination_table_legacy(
27 | random_table_id
28 | )
29 | out, err = capsys.readouterr()
30 | assert "Query results loaded to the table {}".format(random_table_id) in out
31 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_dry_run.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_query_dry_run
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query_dry_run(capsys: "pytest.CaptureFixture[str]") -> None:
24 | query_job = client_query_dry_run.client_query_dry_run()
25 | out, err = capsys.readouterr()
26 | assert "This query will process" in out
27 | assert query_job.state == "DONE"
28 | assert query_job.dry_run
29 | assert query_job.total_bytes_processed > 0
30 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_job_optional.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_query_job_optional
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query_shortmode(capsys: "pytest.CaptureFixture[str]") -> None:
24 | client_query_job_optional.client_query_job_optional()
25 | out, err = capsys.readouterr()
26 | assert "Query was run" in out
27 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_legacy_sql.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import re
16 | import typing
17 |
18 | from .. import client_query_legacy_sql
19 |
20 | if typing.TYPE_CHECKING:
21 | import pytest
22 |
23 |
24 | def test_client_query_legacy_sql(capsys: "pytest.CaptureFixture[str]") -> None:
25 | client_query_legacy_sql.client_query_legacy_sql()
26 | out, err = capsys.readouterr()
27 | assert re.search(r"(Row[\w(){}:', ]+)$", out)
28 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_w_array_params.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_query_w_array_params
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query_w_array_params(capsys: "pytest.CaptureFixture[str]") -> None:
24 | client_query_w_array_params.client_query_w_array_params()
25 | out, err = capsys.readouterr()
26 | assert "James" in out
27 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_w_named_params.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_query_w_named_params
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query_w_named_params(capsys: "pytest.CaptureFixture[str]") -> None:
24 | client_query_w_named_params.client_query_w_named_params()
25 | out, err = capsys.readouterr()
26 | assert "the" in out
27 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_w_positional_params.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_query_w_positional_params
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query_w_positional_params(capsys: "pytest.CaptureFixture[str]") -> None:
24 | client_query_w_positional_params.client_query_w_positional_params()
25 | out, err = capsys.readouterr()
26 | assert "the" in out
27 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_w_struct_params.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_query_w_struct_params
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query_w_struct_params(capsys: "pytest.CaptureFixture[str]") -> None:
24 | client_query_w_struct_params.client_query_w_struct_params()
25 | out, err = capsys.readouterr()
26 | assert "1" in out
27 | assert "foo" in out
28 |
--------------------------------------------------------------------------------
/samples/tests/test_client_query_w_timestamp_params.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import client_query_w_timestamp_params
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_client_query_w_timestamp_params(capsys: "pytest.CaptureFixture[str]") -> None:
24 | client_query_w_timestamp_params.client_query_w_timestamp_params()
25 | out, err = capsys.readouterr()
26 | assert "2016, 12, 7, 9, 0" in out
27 |
--------------------------------------------------------------------------------
/samples/tests/test_copy_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | import pytest
18 |
19 | from .. import copy_table
20 |
21 | if typing.TYPE_CHECKING:
22 | from google.cloud import bigquery
23 |
24 |
25 | def test_copy_table(
26 | capsys: "pytest.CaptureFixture[str]",
27 | table_with_data_id: str,
28 | random_table_id: str,
29 | client: "bigquery.Client",
30 | ) -> None:
31 | copy_table.copy_table(table_with_data_id, random_table_id)
32 | out, err = capsys.readouterr()
33 | assert "A copy of the table created." in out
34 | assert (
35 | client.get_table(random_table_id).num_rows
36 | == client.get_table(table_with_data_id).num_rows
37 | )
38 |
--------------------------------------------------------------------------------
/samples/tests/test_copy_table_cmek.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import pytest
16 |
17 | from .. import copy_table_cmek
18 |
19 |
20 | def test_copy_table_cmek(
21 | capsys: "pytest.CaptureFixture[str]",
22 | random_table_id: str,
23 | table_with_data_id: str,
24 | kms_key_name: str,
25 | ) -> None:
26 | copy_table_cmek.copy_table_cmek(random_table_id, table_with_data_id, kms_key_name)
27 | out, err = capsys.readouterr()
28 | assert "A copy of the table created" in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_create_dataset.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import create_dataset
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_create_dataset(
24 | capsys: "pytest.CaptureFixture[str]", random_dataset_id: str
25 | ) -> None:
26 | create_dataset.create_dataset(random_dataset_id)
27 | out, err = capsys.readouterr()
28 | assert "Created dataset {}".format(random_dataset_id) in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_create_job.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import create_job
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 | from google.cloud import bigquery
22 |
23 |
24 | def test_create_job(
25 | capsys: "pytest.CaptureFixture[str]", client: "bigquery.Client"
26 | ) -> None:
27 | query_job = create_job.create_job()
28 | client.cancel_job(query_job.job_id, location=query_job.location)
29 | out, err = capsys.readouterr()
30 | assert "Started job: {}".format(query_job.job_id) in out
31 |
--------------------------------------------------------------------------------
/samples/tests/test_create_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import create_table
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_create_table(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | create_table.create_table(random_table_id)
27 | out, err = capsys.readouterr()
28 | assert "Created table {}".format(random_table_id) in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_create_table_clustered.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import create_table_clustered
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_create_table_clustered(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | table = create_table_clustered.create_table_clustered(random_table_id)
27 | out, _ = capsys.readouterr()
28 | assert "Created clustered table {}".format(random_table_id) in out
29 | assert table.clustering_fields == ["city", "zipcode"]
30 |
--------------------------------------------------------------------------------
/samples/tests/test_create_table_range_partitioned.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import create_table_range_partitioned
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_create_table_range_partitioned(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | table = create_table_range_partitioned.create_table_range_partitioned(
27 | random_table_id
28 | )
29 | out, _ = capsys.readouterr()
30 | assert "Created table {}".format(random_table_id) in out
31 | assert table.range_partitioning.field == "zipcode"
32 | assert table.range_partitioning.range_.start == 0
33 | assert table.range_partitioning.range_.end == 100000
34 | assert table.range_partitioning.range_.interval == 10
35 |
--------------------------------------------------------------------------------
/samples/tests/test_dataset_exists.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from google.cloud import bigquery
18 |
19 | from .. import dataset_exists
20 |
21 | if typing.TYPE_CHECKING:
22 | import pytest
23 |
24 |
25 | def test_dataset_exists(
26 | capsys: "pytest.CaptureFixture[str]",
27 | random_dataset_id: str,
28 | client: bigquery.Client,
29 | ) -> None:
30 | dataset_exists.dataset_exists(random_dataset_id)
31 | out, err = capsys.readouterr()
32 | assert "Dataset {} is not found".format(random_dataset_id) in out
33 | dataset = bigquery.Dataset(random_dataset_id)
34 | dataset = client.create_dataset(dataset)
35 | dataset_exists.dataset_exists(random_dataset_id)
36 | out, err = capsys.readouterr()
37 | assert "Dataset {} already exists".format(random_dataset_id) in out
38 |
--------------------------------------------------------------------------------
/samples/tests/test_delete_dataset.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import delete_dataset
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_delete_dataset(capsys: "pytest.CaptureFixture[str]", dataset_id: str) -> None:
24 | delete_dataset.delete_dataset(dataset_id)
25 | out, err = capsys.readouterr()
26 | assert "Deleted dataset '{}'.".format(dataset_id) in out
27 |
--------------------------------------------------------------------------------
/samples/tests/test_delete_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import delete_table
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_delete_table(capsys: "pytest.CaptureFixture[str]", table_id: str) -> None:
24 | delete_table.delete_table(table_id)
25 | out, err = capsys.readouterr()
26 | assert "Deleted table '{}'.".format(table_id) in out
27 |
--------------------------------------------------------------------------------
/samples/tests/test_download_public_data.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import pytest
16 |
17 | from .. import download_public_data
18 |
19 | pytest.importorskip("google.cloud.bigquery_storage_v1")
20 |
21 |
22 | def test_download_public_data(capsys: pytest.CaptureFixture[str]) -> None:
23 | download_public_data.download_public_data()
24 | out, _ = capsys.readouterr()
25 | assert "year" in out
26 | assert "gender" in out
27 | assert "name" in out
28 |
--------------------------------------------------------------------------------
/samples/tests/test_download_public_data_sandbox.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import pytest
16 |
17 | from .. import download_public_data_sandbox
18 |
19 | pytest.importorskip("google.cloud.bigquery_storage_v1")
20 |
21 |
22 | def test_download_public_data_sandbox(capsys: pytest.CaptureFixture[str]) -> None:
23 | download_public_data_sandbox.download_public_data_sandbox()
24 | out, _ = capsys.readouterr()
25 | assert "year" in out
26 | assert "gender" in out
27 | assert "name" in out
28 |
--------------------------------------------------------------------------------
/samples/tests/test_get_dataset.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import get_dataset
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_get_dataset(capsys: "pytest.CaptureFixture[str]", dataset_id: str) -> None:
24 | get_dataset.get_dataset(dataset_id)
25 | out, err = capsys.readouterr()
26 | assert dataset_id in out
27 |
--------------------------------------------------------------------------------
/samples/tests/test_list_datasets.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import list_datasets
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 | from google.cloud import bigquery
22 |
23 |
24 | def test_list_datasets(
25 | capsys: "pytest.CaptureFixture[str]", dataset_id: str, client: "bigquery.Client"
26 | ) -> None:
27 | list_datasets.list_datasets()
28 | out, err = capsys.readouterr()
29 | assert "Datasets in project {}:".format(client.project) in out
30 |
--------------------------------------------------------------------------------
/samples/tests/test_list_datasets_by_label.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import list_datasets_by_label
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 | from google.cloud import bigquery
22 |
23 |
24 | def test_list_datasets_by_label(
25 | capsys: "pytest.CaptureFixture[str]", dataset_id: str, client: "bigquery.Client"
26 | ) -> None:
27 | dataset = client.get_dataset(dataset_id)
28 | dataset.labels = {"color": "green"}
29 | dataset = client.update_dataset(dataset, ["labels"])
30 | list_datasets_by_label.list_datasets_by_label()
31 | out, err = capsys.readouterr()
32 | assert dataset_id in out
33 |
--------------------------------------------------------------------------------
/samples/tests/test_list_tables.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import list_tables
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_list_tables(
24 | capsys: "pytest.CaptureFixture[str]", dataset_id: str, table_id: str
25 | ) -> None:
26 | list_tables.list_tables(dataset_id)
27 | out, err = capsys.readouterr()
28 | assert "Tables contained in '{}':".format(dataset_id) in out
29 | assert table_id in out
30 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_clustered.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_clustered
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 | from google.cloud import bigquery
22 |
23 |
24 | def test_load_table_clustered(
25 | capsys: "pytest.CaptureFixture[str]",
26 | random_table_id: str,
27 | client: "bigquery.Client",
28 | ) -> None:
29 | table = load_table_clustered.load_table_clustered(random_table_id)
30 |
31 | out, _ = capsys.readouterr()
32 | assert "rows and 4 columns" in out
33 |
34 | rows = list(client.list_rows(table)) # Make an API request.
35 | assert len(rows) > 0
36 | assert table.clustering_fields == ["origin", "destination"]
37 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_autodetect_csv.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_autodetect_csv
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_autodetect_csv(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_autodetect_csv.load_table_uri_autodetect_csv(random_table_id)
27 | out, err = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_autodetect_json.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_autodetect_json
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_autodetect_csv(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_autodetect_json.load_table_uri_autodetect_json(random_table_id)
27 | out, err = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_avro.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_avro
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_avro(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_avro.load_table_uri_avro(random_table_id)
27 | out, _ = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_cmek.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_cmek
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_cmek(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str, kms_key_name: str
25 | ) -> None:
26 | load_table_uri_cmek.load_table_uri_cmek(random_table_id, kms_key_name)
27 | out, _ = capsys.readouterr()
28 | assert "A table loaded with encryption configuration key" in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_csv.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_csv
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_csv(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_csv.load_table_uri_csv(random_table_id)
27 | out, _ = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_json.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_json
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_json(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_json.load_table_uri_json(random_table_id)
27 | out, _ = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_orc.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_orc
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_orc(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_orc.load_table_uri_orc(random_table_id)
27 | out, _ = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_parquet.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_parquet
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_json(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_parquet.load_table_uri_parquet(random_table_id)
27 | out, _ = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_truncate_avro.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_truncate_avro
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_truncate_avro(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_truncate_avro.load_table_uri_truncate_avro(random_table_id)
27 | out, _ = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_truncate_csv.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_truncate_csv
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_truncate_csv(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_truncate_csv.load_table_uri_truncate_csv(random_table_id)
27 | out, _ = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_truncate_json.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_truncate_json
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_truncate_json(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_truncate_json.load_table_uri_truncate_json(random_table_id)
27 | out, _ = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_truncate_orc.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_truncate_orc
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_truncate_orc(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_truncate_orc.load_table_uri_truncate_orc(random_table_id)
27 | out, _ = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_load_table_uri_truncate_parquet.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import load_table_uri_truncate_parquet
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_load_table_uri_truncate_parquet(
24 | capsys: "pytest.CaptureFixture[str]", random_table_id: str
25 | ) -> None:
26 | load_table_uri_truncate_parquet.load_table_uri_truncate_parquet(random_table_id)
27 | out, _ = capsys.readouterr()
28 | assert "Loaded 50 rows." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_query_external_gcs_temporary_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import query_external_gcs_temporary_table
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_query_external_gcs_temporary_table(
24 | capsys: "pytest.CaptureFixture[str]",
25 | ) -> None:
26 | query_external_gcs_temporary_table.query_external_gcs_temporary_table()
27 | out, err = capsys.readouterr()
28 | assert "There are 4 states with names starting with W." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_query_external_sheets_permanent_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import query_external_sheets_permanent_table
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_query_external_sheets_permanent_table(
24 | capsys: "pytest.CaptureFixture[str]", dataset_id: str
25 | ) -> None:
26 | query_external_sheets_permanent_table.query_external_sheets_permanent_table(
27 | dataset_id
28 | )
29 | out, err = capsys.readouterr()
30 | assert "There are 2 states with names starting with W in the selected range." in out
31 |
--------------------------------------------------------------------------------
/samples/tests/test_query_external_sheets_temporary_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import query_external_sheets_temporary_table
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_query_external_sheets_temporary_table(
24 | capsys: "pytest.CaptureFixture[str]",
25 | ) -> None:
26 | query_external_sheets_temporary_table.query_external_sheets_temporary_table()
27 | out, err = capsys.readouterr()
28 | assert "There are 2 states with names starting with W in the selected range." in out
29 |
--------------------------------------------------------------------------------
/samples/tests/test_query_no_cache.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import re
16 | import typing
17 |
18 | from .. import query_no_cache
19 |
20 | if typing.TYPE_CHECKING:
21 | import pytest
22 |
23 |
24 | def test_query_no_cache(capsys: "pytest.CaptureFixture[str]") -> None:
25 | query_no_cache.query_no_cache()
26 | out, err = capsys.readouterr()
27 | assert re.search(r"(Row[\w(){}:', ]+)$", out)
28 |
--------------------------------------------------------------------------------
/samples/tests/test_query_pagination.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import query_pagination
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_query_pagination(capsys: "pytest.CaptureFixture[str]") -> None:
24 | query_pagination.query_pagination()
25 | out, _ = capsys.readouterr()
26 | assert "The query data:" in out
27 | assert "name=James, count=4942431" in out
28 |
--------------------------------------------------------------------------------
/samples/tests/test_query_script.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import query_script
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_query_script(capsys: "pytest.CaptureFixture[str]") -> None:
24 | query_script.query_script()
25 | out, _ = capsys.readouterr()
26 | assert "Script created 2 child jobs." in out
27 | assert (
28 | "53 of the top 100 names from year 2000 also appear in Shakespeare's works."
29 | in out
30 | )
31 | assert "produced 53 row(s)" in out
32 | assert "produced 1 row(s)" in out
33 |
--------------------------------------------------------------------------------
/samples/tests/test_query_to_arrow.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import pytest
16 |
17 | from .. import query_to_arrow
18 |
19 | pyarrow = pytest.importorskip("pyarrow")
20 |
21 |
22 | def test_query_to_arrow(capsys: "pytest.CaptureFixture[str]") -> None:
23 | arrow_table = query_to_arrow.query_to_arrow()
24 | out, err = capsys.readouterr()
25 | assert "Downloaded 8 rows, 2 columns." in out
26 | arrow_schema = arrow_table.schema
27 | assert arrow_schema.names == ["race", "participant"]
28 | assert pyarrow.types.is_string(arrow_schema.types[0])
29 | assert pyarrow.types.is_struct(arrow_schema.types[1])
30 |
--------------------------------------------------------------------------------
/samples/tests/test_table_exists.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from google.cloud import bigquery
18 |
19 | from .. import table_exists
20 |
21 | if typing.TYPE_CHECKING:
22 | import pytest
23 |
24 |
25 | def test_table_exists(
26 | capsys: "pytest.CaptureFixture[str]", random_table_id: str, client: bigquery.Client
27 | ) -> None:
28 | table_exists.table_exists(random_table_id)
29 | out, err = capsys.readouterr()
30 | assert "Table {} is not found.".format(random_table_id) in out
31 | table = bigquery.Table(random_table_id)
32 | table = client.create_table(table)
33 | table_exists.table_exists(random_table_id)
34 | out, err = capsys.readouterr()
35 | assert "Table {} already exists.".format(random_table_id) in out
36 |
--------------------------------------------------------------------------------
/samples/tests/test_table_insert_rows.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from google.cloud import bigquery
18 |
19 | from .. import table_insert_rows
20 |
21 | if typing.TYPE_CHECKING:
22 | import pytest
23 |
24 |
25 | def test_table_insert_rows(
26 | capsys: "pytest.CaptureFixture[str]",
27 | random_table_id: str,
28 | client: bigquery.Client,
29 | ) -> None:
30 | schema = [
31 | bigquery.SchemaField("full_name", "STRING", mode="REQUIRED"),
32 | bigquery.SchemaField("age", "INTEGER", mode="REQUIRED"),
33 | ]
34 |
35 | table = bigquery.Table(random_table_id, schema=schema)
36 | table = client.create_table(table)
37 |
38 | table_insert_rows.table_insert_rows(random_table_id)
39 | out, err = capsys.readouterr()
40 | assert "New rows have been added." in out
41 |
--------------------------------------------------------------------------------
/samples/tests/test_undelete_table.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import undelete_table
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_undelete_table(
24 | capsys: "pytest.CaptureFixture[str]",
25 | table_with_schema_id: str,
26 | random_table_id: str,
27 | ) -> None:
28 | undelete_table.undelete_table(table_with_schema_id, random_table_id)
29 | out, _ = capsys.readouterr()
30 | assert (
31 | "Copied data from deleted table {} to {}".format(
32 | table_with_schema_id, random_table_id
33 | )
34 | in out
35 | )
36 |
--------------------------------------------------------------------------------
/samples/tests/test_update_dataset_access.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import update_dataset_access
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_update_dataset_access(
24 | capsys: "pytest.CaptureFixture[str]", dataset_id: str
25 | ) -> None:
26 | update_dataset_access.update_dataset_access(dataset_id)
27 | out, err = capsys.readouterr()
28 | assert (
29 | "Updated dataset '{}' with modified user permissions.".format(dataset_id) in out
30 | )
31 |
--------------------------------------------------------------------------------
/samples/tests/test_update_dataset_default_partition_expiration.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import update_dataset_default_partition_expiration
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_update_dataset_default_partition_expiration(
24 | capsys: "pytest.CaptureFixture[str]", dataset_id: str
25 | ) -> None:
26 | ninety_days_ms = 90 * 24 * 60 * 60 * 1000 # in milliseconds
27 |
28 | update_dataset_default_partition_expiration.update_dataset_default_partition_expiration(
29 | dataset_id
30 | )
31 | out, _ = capsys.readouterr()
32 | assert (
33 | "Updated dataset {} with new default partition expiration {}".format(
34 | dataset_id, ninety_days_ms
35 | )
36 | in out
37 | )
38 |
--------------------------------------------------------------------------------
/samples/tests/test_update_dataset_default_table_expiration.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import update_dataset_default_table_expiration
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_update_dataset_default_table_expiration(
24 | capsys: "pytest.CaptureFixture[str]", dataset_id: str
25 | ) -> None:
26 | one_day_ms = 24 * 60 * 60 * 1000 # in milliseconds
27 |
28 | update_dataset_default_table_expiration.update_dataset_default_table_expiration(
29 | dataset_id
30 | )
31 | out, err = capsys.readouterr()
32 | assert (
33 | "Updated dataset {} with new expiration {}".format(dataset_id, one_day_ms)
34 | in out
35 | )
36 |
--------------------------------------------------------------------------------
/samples/tests/test_update_dataset_description.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import typing
16 |
17 | from .. import update_dataset_description
18 |
19 | if typing.TYPE_CHECKING:
20 | import pytest
21 |
22 |
23 | def test_update_dataset_description(
24 | capsys: "pytest.CaptureFixture[str]", dataset_id: str
25 | ) -> None:
26 | update_dataset_description.update_dataset_description(dataset_id)
27 | out, err = capsys.readouterr()
28 | assert "Updated description." in out
29 |
--------------------------------------------------------------------------------
/scripts/readme-gen/templates/auth.tmpl.rst:
--------------------------------------------------------------------------------
1 | Authentication
2 | ++++++++++++++
3 |
4 | This sample requires you to have authentication setup. Refer to the
5 | `Authentication Getting Started Guide`_ for instructions on setting up
6 | credentials for applications.
7 |
8 | .. _Authentication Getting Started Guide:
9 | https://cloud.google.com/docs/authentication/getting-started
10 |
--------------------------------------------------------------------------------
/scripts/readme-gen/templates/auth_api_key.tmpl.rst:
--------------------------------------------------------------------------------
1 | Authentication
2 | ++++++++++++++
3 |
4 | Authentication for this service is done via an `API Key`_. To obtain an API
5 | Key:
6 |
7 | 1. Open the `Cloud Platform Console`_
8 | 2. Make sure that billing is enabled for your project.
9 | 3. From the **Credentials** page, create a new **API Key** or use an existing
10 | one for your project.
11 |
12 | .. _API Key:
13 | https://developers.google.com/api-client-library/python/guide/aaa_apikeys
14 | .. _Cloud Console: https://console.cloud.google.com/project?_
15 |
--------------------------------------------------------------------------------
/scripts/readme-gen/templates/install_deps.tmpl.rst:
--------------------------------------------------------------------------------
1 | Install Dependencies
2 | ++++++++++++++++++++
3 |
4 | #. Clone python-docs-samples and change directory to the sample directory you want to use.
5 |
6 | .. code-block:: bash
7 |
8 | $ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
9 |
10 | #. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions.
11 |
12 | .. _Python Development Environment Setup Guide:
13 | https://cloud.google.com/python/setup
14 |
15 | #. Create a virtualenv. Samples are compatible with Python 3.9+.
16 |
17 | .. code-block:: bash
18 |
19 | $ virtualenv env
20 | $ source env/bin/activate
21 |
22 | #. Install the dependencies needed to run the samples.
23 |
24 | .. code-block:: bash
25 |
26 | $ pip install -r requirements.txt
27 |
28 | .. _pip: https://pip.pypa.io/
29 | .. _virtualenv: https://virtualenv.pypa.io/
30 |
--------------------------------------------------------------------------------
/scripts/readme-gen/templates/install_portaudio.tmpl.rst:
--------------------------------------------------------------------------------
1 | Install PortAudio
2 | +++++++++++++++++
3 |
4 | Install `PortAudio`_. This is required by the `PyAudio`_ library to stream
5 | audio from your computer's microphone. PyAudio depends on PortAudio for cross-platform compatibility, and is installed differently depending on the
6 | platform.
7 |
8 | * For Mac OS X, you can use `Homebrew`_::
9 |
10 | brew install portaudio
11 |
12 | **Note**: if you encounter an error when running `pip install` that indicates
13 | it can't find `portaudio.h`, try running `pip install` with the following
14 | flags::
15 |
16 | pip install --global-option='build_ext' \
17 | --global-option='-I/usr/local/include' \
18 | --global-option='-L/usr/local/lib' \
19 | pyaudio
20 |
21 | * For Debian / Ubuntu Linux::
22 |
23 | apt-get install portaudio19-dev python-all-dev
24 |
25 | * Windows may work without having to install PortAudio explicitly (it will get
26 | installed with PyAudio).
27 |
28 | For more details, see the `PyAudio installation`_ page.
29 |
30 |
31 | .. _PyAudio: https://people.csail.mit.edu/hubert/pyaudio/
32 | .. _PortAudio: http://www.portaudio.com/
33 | .. _PyAudio installation:
34 | https://people.csail.mit.edu/hubert/pyaudio/#downloads
35 | .. _Homebrew: http://brew.sh
36 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | #
3 | # Copyright 2023 Google LLC
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # https://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | [pytype]
18 | python_version = 3.8
19 | inputs =
20 | google/cloud/
21 | exclude =
22 | tests/
23 | google/cloud/bigquery_v2/ # Legacy proto-based types.
24 | output = .pytype/
25 | disable =
26 | # There's some issue with finding some pyi files, thus disabling.
27 | # The issue https://github.com/google/pytype/issues/150 is closed, but the
28 | # error still occurs for some reason.
29 | pyi-error
30 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import setuptools # type: ignore
16 |
17 |
18 | setuptools.setup()
19 |
--------------------------------------------------------------------------------
/testing/.gitignore:
--------------------------------------------------------------------------------
1 | test-env.sh
2 | service-account.json
3 | client-secrets.json
--------------------------------------------------------------------------------
/testing/constraints-3.10.txt:
--------------------------------------------------------------------------------
1 | grpcio==1.47.0
2 |
--------------------------------------------------------------------------------
/testing/constraints-3.11.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleapis/python-bigquery/28a5750d455f0381548df6f9b1f7661823837d81/testing/constraints-3.11.txt
--------------------------------------------------------------------------------
/testing/constraints-3.12.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleapis/python-bigquery/28a5750d455f0381548df6f9b1f7661823837d81/testing/constraints-3.12.txt
--------------------------------------------------------------------------------
/testing/constraints-3.13.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleapis/python-bigquery/28a5750d455f0381548df6f9b1f7661823837d81/testing/constraints-3.13.txt
--------------------------------------------------------------------------------
/testing/constraints-3.9.txt:
--------------------------------------------------------------------------------
1 | # This constraints file is used to make sure that the latest dependency versions
2 | # we claim to support in setup.py are indeed installed in test sessions in the most
3 | # recent Python version supported (3.9 at the time of writing - 2021-05-05).
4 | #
5 | # NOTE: Not comprehensive yet, will eventually be maintained semi-automatically by
6 | # the renovate bot.
7 | bigquery-magics==0.6.0
8 | db-dtypes==1.0.4
9 | geopandas==0.9.0
10 | google-api-core==2.11.1
11 | google-auth==2.14.1
12 | google-cloud-bigquery-storage==2.18.0
13 | google-cloud-core==2.4.1
14 | google-resumable-media==2.0.0
15 | grpcio==1.47.0
16 | grpcio==1.49.1; python_version >= '3.11'
17 | ipywidgets==7.7.1
18 | ipython==7.23.1
19 | ipykernel==6.2.0
20 | opentelemetry-api==1.1.0
21 | opentelemetry-instrumentation==0.20b0
22 | opentelemetry-sdk==1.1.0
23 | numpy==1.20.2
24 | packaging==24.2.0
25 | pandas==1.3.0
26 | pandas-gbq==0.26.1
27 | proto-plus==1.22.3
28 | protobuf==3.20.2
29 | pyarrow==4.0.0
30 | python-dateutil==2.8.2
31 | requests==2.21.0
32 | Shapely==1.8.4
33 | matplotlib==3.7.1
34 |
--------------------------------------------------------------------------------
/tests/__init__.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # Copyright 2022 Google LLC
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
--------------------------------------------------------------------------------
/tests/data/colors.avro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleapis/python-bigquery/28a5750d455f0381548df6f9b1f7661823837d81/tests/data/colors.avro
--------------------------------------------------------------------------------
/tests/data/numeric_38_12.parquet:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleapis/python-bigquery/28a5750d455f0381548df6f9b1f7661823837d81/tests/data/numeric_38_12.parquet
--------------------------------------------------------------------------------
/tests/data/people.csv:
--------------------------------------------------------------------------------
1 | full_name,age
2 | Phred Phlyntstone,32
3 | Wylma Phlyntstone,29
--------------------------------------------------------------------------------
/tests/data/scalars.csv:
--------------------------------------------------------------------------------
1 | "[2020-01-01, 2020-02-01)"
2 |
3 |
--------------------------------------------------------------------------------
/tests/data/scalars.jsonl:
--------------------------------------------------------------------------------
1 | {"bool_col": true, "bytes_col": "SGVsbG8sIFdvcmxkIQ==", "date_col": "2021-07-21", "datetime_col": "2021-07-21 11:39:45", "geography_col": "POINT(-122.0838511 37.3860517)", "int64_col": "123456789", "interval_col": "P7Y11M9DT4H15M37.123456S", "numeric_col": "1.23456789", "bignumeric_col": "10.111213141516171819", "float64_col": "1.25", "rowindex": 0, "string_col": "Hello, World!", "time_col": "11:41:43.07616", "timestamp_col": "2021-07-21T17:43:43.945289Z"}
2 | {"bool_col": null, "bytes_col": null, "date_col": null, "datetime_col": null, "geography_col": null, "int64_col": null, "interval_col": null, "numeric_col": null, "bignumeric_col": null, "float64_col": null, "rowindex": 1, "string_col": null, "time_col": null, "timestamp_col": null}
3 |
--------------------------------------------------------------------------------
/tests/data/scalars_schema_csv.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "mode" : "NULLABLE",
4 | "name" : "range_date",
5 | "type" : "RANGE",
6 | "rangeElementType": {
7 | "type": "DATE"
8 | }
9 | }
10 | ]
--------------------------------------------------------------------------------
/tests/scrub_datasets.py:
--------------------------------------------------------------------------------
1 | import re
2 | import sys
3 |
4 | from google.api_core.exceptions import NotFound
5 | from google.cloud.bigquery import Client
6 |
7 |
8 | def main(prefixes):
9 | client = Client()
10 |
11 | pattern = re.compile("|".join("^{}.*$".format(prefix) for prefix in prefixes))
12 |
13 | ds_items = list(client.list_datasets())
14 | for dataset in ds_items:
15 | ds_id = dataset.dataset_id
16 | if pattern.match(ds_id):
17 | print("Deleting dataset: {}".format(ds_id))
18 | try:
19 | client.delete_dataset(dataset.reference, delete_contents=True)
20 | except NotFound:
21 | print(" NOT FOUND")
22 |
23 |
24 | if __name__ == "__main__":
25 | main(sys.argv[1:])
26 |
--------------------------------------------------------------------------------
/tests/system/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
--------------------------------------------------------------------------------
/tests/system/test_structs.py:
--------------------------------------------------------------------------------
1 | import datetime
2 |
3 | import pytest
4 |
5 | from google.cloud.bigquery.dbapi import connect
6 |
7 | person_type = "struct>>"
8 | person_type_sized = (
9 | "struct>>"
10 | )
11 |
12 |
13 | @pytest.mark.parametrize("person_type_decl", [person_type, person_type_sized])
14 | def test_structs(bigquery_client, dataset_id, person_type_decl, table_id):
15 | conn = connect(bigquery_client)
16 | cursor = conn.cursor()
17 | cursor.execute(f"create table {table_id} (person {person_type_decl})")
18 | data = dict(
19 | name="par",
20 | children=[
21 | dict(name="ch1", bdate=datetime.date(2021, 1, 1)),
22 | dict(name="ch2", bdate=datetime.date(2021, 1, 2)),
23 | ],
24 | )
25 | cursor.execute(
26 | f"insert into {table_id} (person) values (%(v:{person_type})s)",
27 | dict(v=data),
28 | )
29 |
30 | cursor.execute(f"select * from {table_id}")
31 | [[result]] = list(cursor)
32 | assert result == data
33 |
--------------------------------------------------------------------------------
/tests/unit/__init__.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # Copyright 2022 Google LLC
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
--------------------------------------------------------------------------------
/tests/unit/_helpers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleapis/python-bigquery/28a5750d455f0381548df6f9b1f7661823837d81/tests/unit/_helpers/__init__.py
--------------------------------------------------------------------------------
/tests/unit/job/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
--------------------------------------------------------------------------------
/tests/unit/line_arg_parser/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
--------------------------------------------------------------------------------
/tests/unit/line_arg_parser/test_lexer.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import pytest
16 |
17 | IPython = pytest.importorskip("IPython")
18 |
19 |
20 | @pytest.fixture(scope="session")
21 | def lexer_class():
22 | from google.cloud.bigquery.magics.line_arg_parser.lexer import Lexer
23 |
24 | return Lexer
25 |
26 |
27 | def test_empy_input(lexer_class):
28 | from google.cloud.bigquery.magics.line_arg_parser import TokenType
29 | from google.cloud.bigquery.magics.line_arg_parser.lexer import Token
30 |
31 | lexer = lexer_class("")
32 | tokens = list(lexer)
33 |
34 | assert tokens == [Token(TokenType.EOL, lexeme="", pos=0)]
35 |
--------------------------------------------------------------------------------
/tests/unit/line_arg_parser/test_visitors.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | import pytest
16 |
17 | IPython = pytest.importorskip("IPython")
18 |
19 |
20 | @pytest.fixture
21 | def base_visitor():
22 | from google.cloud.bigquery.magics.line_arg_parser.visitors import NodeVisitor
23 |
24 | return NodeVisitor()
25 |
26 |
27 | def test_unknown_node(base_visitor):
28 | from google.cloud.bigquery.magics.line_arg_parser.parser import ParseNode
29 |
30 | class UnknownNode(ParseNode):
31 | pass
32 |
33 | node = UnknownNode()
34 |
35 | with pytest.raises(Exception, match=r"No visit_UnknownNode method"):
36 | base_visitor.visit(node)
37 |
--------------------------------------------------------------------------------
/tests/unit/model/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleapis/python-bigquery/28a5750d455f0381548df6f9b1f7661823837d81/tests/unit/model/__init__.py
--------------------------------------------------------------------------------
/tests/unit/routine/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googleapis/python-bigquery/28a5750d455f0381548df6f9b1f7661823837d81/tests/unit/routine/__init__.py
--------------------------------------------------------------------------------
/tests/unit/test_legacy_types.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # Copyright 2022 Google LLC
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | import pytest
17 |
18 | import warnings
19 |
20 | try:
21 | import proto
22 | except ImportError:
23 | proto = None # type: ignore
24 |
25 |
26 | @pytest.mark.skipif(proto is None, reason="proto is not installed")
27 | def test_importing_legacy_types_emits_warning():
28 | with warnings.catch_warnings(record=True) as warned:
29 | from google.cloud.bigquery_v2 import types # noqa: F401
30 |
31 | assert len(warned) == 1
32 | assert warned[0].category is DeprecationWarning
33 | warning_msg = str(warned[0])
34 | assert "bigquery_v2" in warning_msg
35 | assert "not maintained" in warning_msg
36 |
--------------------------------------------------------------------------------