Skip to content

BigQuery: Updates samples for BigQuery Beta 2 (do not merge until release) #1178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Oct 31, 2017

Conversation

alixhami
Copy link
Contributor

No description provided.

@alixhami alixhami requested review from tswast and theacodes October 26, 2017 19:02
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 26, 2017
Copy link
Contributor

@tswast tswast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, LGTM. I know you are in class now, so I'll address most of these comments in a new commit to the branch.

job_name = str(uuid.uuid4())
dataset_ref = bigquery_client.dataset(dataset_id)
table_ref = dataset_ref.table(table_id)
job_id = str(uuid.uuid4())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

job_id is optional now that the client library can generate it, so probably can be removed from this sample

job_name = str(uuid.uuid4())
dataset_ref = bigquery_client.dataset(dataset_id)
table_ref = dataset_ref.table(table_id)
job_id = str(uuid.uuid4())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this job_id generation.

]
job_config = bigquery.QueryJobConfig()
job_config.query_parameters = query_params
job_id = str(uuid.uuid4())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this job_id, too.

job_config.query_parameters = query_params
job_id = str(uuid.uuid4())
query_job = client.query(query, job_config=job_config, job_id=job_id)

query_job.result() # Wait for job to complete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the return value for result instead of getting the table after this.

job_config.query_parameters = query_params
job_id = str(uuid.uuid4())
query_job = client.query(query, job_config=job_config, job_id=job_id)

query_job.result() # Wait for job to complete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the rows from the return value for result here.

job_config.query_parameters = query_params
query_job = client.query(query, job_config=job_config, job_id=job_id)

query_job.result() # Waits for job to complete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the return value from result.

bigquery.ScalarQueryParameter('y', 'STRING', y)
)
]
job_id = str(uuid.uuid4())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let the client library generate the job ID.

job_config.query_parameters = query_params
query_job = client.query(query, job_config=job_config, job_id=job_id)

query_job.result() # Waits for job to complete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the return value from result.

for row in destination_table.fetch_data():
print(row)
for row in results:
print("{}: {}".format(row.title, row.unique_words))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it! It's much nicer to show accessing the specific columns in this sample.


# Load at most 25 results.
rows = itertools.islice(table.fetch_data(), 25)
rows = itertools.islice(bigquery_client.list_rows(table), 25)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can actually pass max_results to list_rows now.

Use max_results in list_rows.
Copy link
Contributor

@tswast tswast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I reviewed a second too soon. I see you've addressed the job_id and result changes. Thanks!

@tswast tswast added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Oct 26, 2017
@theacodes theacodes merged commit e5c0ff2 into master Oct 31, 2017
@theacodes theacodes deleted the bigquery-b2 branch October 31, 2017 16:58
@theacodes theacodes removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Oct 31, 2017
plamut pushed a commit to plamut/python-bigquery that referenced this pull request Jun 25, 2020
…ease) [(googleapis#1178)](GoogleCloudPlatform/python-docs-samples#1178)

* updates client.extract_table() sample

* updates client.load_table_from_file() sample

* updates client.load_table_from_uri() sample

* updates parameterized query samples

* updates query samples

* updates dataset quickstart

* fixes typo in sample

* updates simple app sample

* updates snippets

* updates stream data sample

* updates user credentials sample

* removes job_id generation

* Update BQ lib to 0.28.0.

Use max_results in list_rows.

* updates public dataset queries to use 'bigquery-public-data' instead of outdated 'publicdata'

* updates readme and help sections
plamut pushed a commit to plamut/python-bigquery that referenced this pull request Jul 22, 2020
…ease) [(googleapis#1178)](GoogleCloudPlatform/python-docs-samples#1178)

* updates client.extract_table() sample

* updates client.load_table_from_file() sample

* updates client.load_table_from_uri() sample

* updates parameterized query samples

* updates query samples

* updates dataset quickstart

* fixes typo in sample

* updates simple app sample

* updates snippets

* updates stream data sample

* updates user credentials sample

* removes job_id generation

* Update BQ lib to 0.28.0.

Use max_results in list_rows.

* updates public dataset queries to use 'bigquery-public-data' instead of outdated 'publicdata'

* updates readme and help sections
shollyman pushed a commit to googleapis/python-bigquery that referenced this pull request Jul 22, 2020
…ease) [(#1178)](GoogleCloudPlatform/python-docs-samples#1178)

* updates client.extract_table() sample

* updates client.load_table_from_file() sample

* updates client.load_table_from_uri() sample

* updates parameterized query samples

* updates query samples

* updates dataset quickstart

* fixes typo in sample

* updates simple app sample

* updates snippets

* updates stream data sample

* updates user credentials sample

* removes job_id generation

* Update BQ lib to 0.28.0.

Use max_results in list_rows.

* updates public dataset queries to use 'bigquery-public-data' instead of outdated 'publicdata'

* updates readme and help sections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bigquery cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants