Skip to content

Commit cfebfaa

Browse files
ashleyxuushobsi
andauthored
test: add code snippets for loading data from BigQuery Job (#154)
* test: add code snippets for loading data from BigQuery Job * fix: address the comments * fix: fix the broken test * use BigQuery Client library to get the job_id * feat: Implement operator `@` for `DataFrame.dot` (#139) 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: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/python-bigquery-dataframes/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes b/297502513 🦕 * fix: fix the comments --------- Co-authored-by: Shobhit Singh <[email protected]>
1 parent 79a638e commit cfebfaa

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)