|
| 1 | +# Copyright 2023 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 | +def test_bigquery_dataframes_load_data_from_bigquery_job(): |
| 17 | + from google.cloud import bigquery |
| 18 | + |
| 19 | + # Construct a BigQuery client object. |
| 20 | + client = bigquery.Client(project="bigframes-dev", location="us") |
| 21 | + |
| 22 | + query = """ |
| 23 | + SELECT * |
| 24 | + FROM `bigquery-public-data.ml_datasets.penguins` |
| 25 | + LIMIT 20 |
| 26 | + """ |
| 27 | + query_job = client.query(query) |
| 28 | + JOB_ID = query_job.job_id |
| 29 | + your_project_id = "bigframes-dev" |
| 30 | + |
| 31 | + # [START bigquery_dataframes_load_data_from_bigquery_job] |
| 32 | + from google.cloud import bigquery |
| 33 | + |
| 34 | + import bigframes.pandas as bpd |
| 35 | + |
| 36 | + # Project ID inserted based on the query results selected to explore |
| 37 | + project = your_project_id |
| 38 | + # Location inserted based on the query results selected to explore |
| 39 | + location = "us" |
| 40 | + client = bigquery.Client(project=project, location=location) |
| 41 | + |
| 42 | + # Job ID inserted based on the query results selcted to explore |
| 43 | + job_id = JOB_ID |
| 44 | + job = client.get_job(job_id) |
| 45 | + destination = str(job.destination) |
| 46 | + |
| 47 | + # Load data from a BigQuery table using BigFrames DataFrames: |
| 48 | + bq_df = bpd.read_gbq_table(destination) |
| 49 | + |
| 50 | + # [END bigquery_dataframes_load_data_from_bigquery_job] |
| 51 | + assert bq_df is not None |
0 commit comments