Skip to content

Commit 077f941

Browse files
committed
Merge remote-tracking branch 'migration/main' into bqs-samples
2 parents 467a34a + e6210fa commit 077f941

102 files changed

Lines changed: 10503 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md

bigquery_storage/CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/CONTRIBUTING.md

bigquery_storage/__init__.py

Whitespace-only changes.

bigquery_storage/conftest.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 datetime
16+
import os
17+
import random
18+
19+
import pytest
20+
21+
22+
@pytest.fixture(scope="session")
23+
def project_id():
24+
return os.environ["GOOGLE_CLOUD_PROJECT"]
25+
26+
27+
@pytest.fixture(scope="session")
28+
def dataset(project_id):
29+
from google.cloud import bigquery
30+
31+
client = bigquery.Client()
32+
33+
# Add a random suffix to dataset name to avoid conflict, because we run
34+
# a samples test on each supported Python version almost at the same time.
35+
dataset_time = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
36+
suffix = f"_{(random.randint(0, 99)):02d}"
37+
dataset_name = "samples_tests_" + dataset_time + suffix
38+
39+
dataset_id = "{}.{}".format(project_id, dataset_name)
40+
dataset = bigquery.Dataset(dataset_id)
41+
dataset.location = "us-east7"
42+
created_dataset = client.create_dataset(dataset)
43+
yield created_dataset
44+
45+
client.delete_dataset(created_dataset, delete_contents=True)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2025 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+
# Generated code. DO NOT EDIT!
17+
#
18+
# Snippet for CreateReadSession
19+
# NOTE: This snippet has been automatically generated for illustrative purposes only.
20+
# It may require modifications to work in your environment.
21+
22+
# To install the latest published package dependency, execute the following:
23+
# python3 -m pip install google-cloud-bigquery-storage
24+
25+
26+
# [START bigquerystorage_v1_generated_BigQueryRead_CreateReadSession_async]
27+
# This snippet has been automatically generated and should be regarded as a
28+
# code template only.
29+
# It will require modifications to work:
30+
# - It may require correct/in-range values for request initialization.
31+
# - It may require specifying regional endpoints when creating the service
32+
# client as shown in:
33+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
34+
from google.cloud import bigquery_storage_v1
35+
36+
37+
async def sample_create_read_session():
38+
# Create a client
39+
client = bigquery_storage_v1.BigQueryReadAsyncClient()
40+
41+
# Initialize request argument(s)
42+
request = bigquery_storage_v1.CreateReadSessionRequest(
43+
parent="parent_value",
44+
)
45+
46+
# Make the request
47+
response = await client.create_read_session(request=request)
48+
49+
# Handle the response
50+
print(response)
51+
52+
53+
# [END bigquerystorage_v1_generated_BigQueryRead_CreateReadSession_async]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2025 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+
# Generated code. DO NOT EDIT!
17+
#
18+
# Snippet for CreateReadSession
19+
# NOTE: This snippet has been automatically generated for illustrative purposes only.
20+
# It may require modifications to work in your environment.
21+
22+
# To install the latest published package dependency, execute the following:
23+
# python3 -m pip install google-cloud-bigquery-storage
24+
25+
26+
# [START bigquerystorage_v1_generated_BigQueryRead_CreateReadSession_sync]
27+
# This snippet has been automatically generated and should be regarded as a
28+
# code template only.
29+
# It will require modifications to work:
30+
# - It may require correct/in-range values for request initialization.
31+
# - It may require specifying regional endpoints when creating the service
32+
# client as shown in:
33+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
34+
from google.cloud import bigquery_storage_v1
35+
36+
37+
def sample_create_read_session():
38+
# Create a client
39+
client = bigquery_storage_v1.BigQueryReadClient()
40+
41+
# Initialize request argument(s)
42+
request = bigquery_storage_v1.CreateReadSessionRequest(
43+
parent="parent_value",
44+
)
45+
46+
# Make the request
47+
response = client.create_read_session(request=request)
48+
49+
# Handle the response
50+
print(response)
51+
52+
53+
# [END bigquerystorage_v1_generated_BigQueryRead_CreateReadSession_sync]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2025 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+
# Generated code. DO NOT EDIT!
17+
#
18+
# Snippet for ReadRows
19+
# NOTE: This snippet has been automatically generated for illustrative purposes only.
20+
# It may require modifications to work in your environment.
21+
22+
# To install the latest published package dependency, execute the following:
23+
# python3 -m pip install google-cloud-bigquery-storage
24+
25+
26+
# [START bigquerystorage_v1_generated_BigQueryRead_ReadRows_async]
27+
# This snippet has been automatically generated and should be regarded as a
28+
# code template only.
29+
# It will require modifications to work:
30+
# - It may require correct/in-range values for request initialization.
31+
# - It may require specifying regional endpoints when creating the service
32+
# client as shown in:
33+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
34+
from google.cloud import bigquery_storage_v1
35+
36+
37+
async def sample_read_rows():
38+
# Create a client
39+
client = bigquery_storage_v1.BigQueryReadAsyncClient()
40+
41+
# Initialize request argument(s)
42+
request = bigquery_storage_v1.ReadRowsRequest(
43+
read_stream="read_stream_value",
44+
)
45+
46+
# Make the request
47+
stream = await client.read_rows(request=request)
48+
49+
# Handle the response
50+
async for response in stream:
51+
print(response)
52+
53+
54+
# [END bigquerystorage_v1_generated_BigQueryRead_ReadRows_async]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2025 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+
# Generated code. DO NOT EDIT!
17+
#
18+
# Snippet for ReadRows
19+
# NOTE: This snippet has been automatically generated for illustrative purposes only.
20+
# It may require modifications to work in your environment.
21+
22+
# To install the latest published package dependency, execute the following:
23+
# python3 -m pip install google-cloud-bigquery-storage
24+
25+
26+
# [START bigquerystorage_v1_generated_BigQueryRead_ReadRows_sync]
27+
# This snippet has been automatically generated and should be regarded as a
28+
# code template only.
29+
# It will require modifications to work:
30+
# - It may require correct/in-range values for request initialization.
31+
# - It may require specifying regional endpoints when creating the service
32+
# client as shown in:
33+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
34+
from google.cloud import bigquery_storage_v1
35+
36+
37+
def sample_read_rows():
38+
# Create a client
39+
client = bigquery_storage_v1.BigQueryReadClient()
40+
41+
# Initialize request argument(s)
42+
request = bigquery_storage_v1.ReadRowsRequest(
43+
read_stream="read_stream_value",
44+
)
45+
46+
# Make the request
47+
stream = client.read_rows(request=request)
48+
49+
# Handle the response
50+
for response in stream:
51+
print(response)
52+
53+
54+
# [END bigquerystorage_v1_generated_BigQueryRead_ReadRows_sync]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2025 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+
# Generated code. DO NOT EDIT!
17+
#
18+
# Snippet for SplitReadStream
19+
# NOTE: This snippet has been automatically generated for illustrative purposes only.
20+
# It may require modifications to work in your environment.
21+
22+
# To install the latest published package dependency, execute the following:
23+
# python3 -m pip install google-cloud-bigquery-storage
24+
25+
26+
# [START bigquerystorage_v1_generated_BigQueryRead_SplitReadStream_async]
27+
# This snippet has been automatically generated and should be regarded as a
28+
# code template only.
29+
# It will require modifications to work:
30+
# - It may require correct/in-range values for request initialization.
31+
# - It may require specifying regional endpoints when creating the service
32+
# client as shown in:
33+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
34+
from google.cloud import bigquery_storage_v1
35+
36+
37+
async def sample_split_read_stream():
38+
# Create a client
39+
client = bigquery_storage_v1.BigQueryReadAsyncClient()
40+
41+
# Initialize request argument(s)
42+
request = bigquery_storage_v1.SplitReadStreamRequest(
43+
name="name_value",
44+
)
45+
46+
# Make the request
47+
response = await client.split_read_stream(request=request)
48+
49+
# Handle the response
50+
print(response)
51+
52+
53+
# [END bigquerystorage_v1_generated_BigQueryRead_SplitReadStream_async]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2025 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+
# Generated code. DO NOT EDIT!
17+
#
18+
# Snippet for SplitReadStream
19+
# NOTE: This snippet has been automatically generated for illustrative purposes only.
20+
# It may require modifications to work in your environment.
21+
22+
# To install the latest published package dependency, execute the following:
23+
# python3 -m pip install google-cloud-bigquery-storage
24+
25+
26+
# [START bigquerystorage_v1_generated_BigQueryRead_SplitReadStream_sync]
27+
# This snippet has been automatically generated and should be regarded as a
28+
# code template only.
29+
# It will require modifications to work:
30+
# - It may require correct/in-range values for request initialization.
31+
# - It may require specifying regional endpoints when creating the service
32+
# client as shown in:
33+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
34+
from google.cloud import bigquery_storage_v1
35+
36+
37+
def sample_split_read_stream():
38+
# Create a client
39+
client = bigquery_storage_v1.BigQueryReadClient()
40+
41+
# Initialize request argument(s)
42+
request = bigquery_storage_v1.SplitReadStreamRequest(
43+
name="name_value",
44+
)
45+
46+
# Make the request
47+
response = client.split_read_stream(request=request)
48+
49+
# Handle the response
50+
print(response)
51+
52+
53+
# [END bigquerystorage_v1_generated_BigQueryRead_SplitReadStream_sync]

0 commit comments

Comments
 (0)