GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added collection of Managing Dataset samples by lbristol88 · Pull Request #6 · tswast/google-cloud-python

Conversation

@lbristol88

@lbristol88 lbristol88 commented Apr 5, 2019

Copy link
Copy Markdown

@engelke

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
lbristol88 added 8 commits April 5, 2019 13:47
@lbristol88
Added delete dataset function
6d70183
@lbristol88
Added get dataset function
27f5828
@lbristol88
Added list dataset function
ea12d6f
@lbristol88
Added update dataset description sample
9cc5169
@lbristol88
Added update dataset access sample
55e6a61
@lbristol88
Added update dataset table expiration sample
1a5270f
@lbristol88
Added tests for dataset samples and updated docs
a589575
@lbristol88
Removing original update dataset access from snippets file.
ba7c6fd
tswast
tswast requested changes Apr 5, 2019
View reviewed changes
Comment thread bigquery/samples/delete_dataset.py Outdated
# TODO(developer): Set model_id to the ID of the model to fetch.
# dataset_id = 'your-project.your_dataset'

client.delete_dataset(dataset_id)

@tswast tswast Apr 5, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The original sample also had an example showing the delete_contents=True option. I think you could actually do the same, but also show off not_found_ok=True.

client.delete_dataset(dataset_id)

# Comment about deleting a table that contains tables.
# Comment about tables that might not exist.
client.delete_dataset(dataset_id, delete_contents=True, not_found_ok=True)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ok! Added the parameters and notes about what they do.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread bigquery/samples/get_dataset.py Outdated
)

# View dataset properties
print("Dataset ID: {}".format(dataset_id))

@tswast tswast Apr 5, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We can delete this line since you're printing the ID in the same sample in the print statement above.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Removed!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread bigquery/samples/tests/test_dataset_samples.py Outdated
assert "Created dataset {}".format(random_dataset_id) in out

# get dataset
get_dataset.get_dataset(client, random_dataset_id)

@tswast tswast Apr 5, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

These should all be separate tests. That way we can more easily tell when an individual sample is broken. Models API is an exception because it's so slow to create one.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

All separated out into their own tests. Had to include the create_dataset function for some of the tests or else they wouldn't pass (needs a dataset to make changes to!).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread bigquery/samples/update_dataset_access.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/samples/update_dataset_default_table_expiration.py Outdated

def update_dataset_default_table_expiration(client, dataset_id):

# [START bigquery_update_dataset_default_table_expiration]

@tswast tswast Apr 5, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Needs to be removed from docs/snippets.py.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tswast tswast Apr 5, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Also, please keep the "region tag" the same. That way we can track changes over time better. It was called bigquery_update_dataset_expiration in snippets.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Removed, but forgot to push /facepalm. Updated now!

Updated the region tag as directed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread bigquery/samples/update_dataset_description.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread bigquery/samples/update_dataset_default_table_expiration.py Outdated
) # API request

full_dataset_id = "{}.{}".format(dataset.project, dataset.dataset_id)
print("Updated dataset {}".format(full_dataset_id))

@tswast tswast Apr 5, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

For testing purposes, it would be good to print the new dataset.default_table_expiration_ms also.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Added the expiration to the print statement.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread bigquery/samples/tests/test_dataset_samples.py Outdated
client, random_dataset_id
)
out, err = capsys.readouterr()
assert "Updated dataset {}".format(random_dataset_id) in out

@tswast tswast Apr 5, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Please look for the expected expiration str(24 * 60 * 60 * 1000) in the output too. That way we can be more certain that the expiration was actually updated as expected.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Moved the time into it's own fixture so it's easier to be used in the test.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
lbristol88 added 2 commits April 8, 2019 11:24
@lbristol88
Moved all dataset tests into own file. Made changes based on feedback.
34db4d4
@lbristol88
Made changes based on feedback
502facb
tswast
tswast reviewed Apr 8, 2019
View reviewed changes
Comment thread bigquery/samples/tests/conftest.py Outdated


@pytest.fixture
def one_day_ms(client):

@tswast tswast Apr 8, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This doesn't need to be a fixture. Just a normal variable/constant is fine. Fixtures are more for setup & clean-up code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tswast tswast Apr 8, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Actually, now that I see where this is used in the sample code, I'd prefer this code stay in the sample. That way it's clear to someone reading the sample what expected values for expiration look like.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Took this out of the fixture and put it back into the sample and test.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread bigquery/samples/tests/test_delete_dataset.py Outdated
from .. import delete_dataset


def test_delete_dataset(capsys, client, random_dataset_id):

@tswast tswast Apr 8, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I recommend you use the dataset_id fixture instead of random_dataset_id, since the dataset_id fixture will create a dataset for you (to then delete in the sample).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is now updated.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread bigquery/samples/tests/test_get_dataset.py Outdated
from .. import get_dataset


def test_get_dataset(capsys, client, random_dataset_id):

@tswast tswast Apr 8, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ditto. I recommend you use the dataset_id fixture instead of random_dataset_id, since the dataset_id fixture will create a dataset for you (to then get in the sample).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is now updated.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread bigquery/samples/tests/test_list_datasets.py Outdated
from .. import list_datasets


def test_list_datasets(capsys, client, random_dataset_id):

@tswast tswast Apr 8, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The random_dataset_id fixture isn't necessary for this test.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Fixed!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread bigquery/samples/tests/test_update_dataset_access.py Outdated
from .. import update_dataset_access


def test_update_dataset_access(capsys, client, random_dataset_id):

@tswast tswast Apr 8, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ditto. I recommend you use the dataset_id fixture instead of random_dataset_id, since the dataset_id fixture will create a dataset for you (to then update in the sample).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Replaced with dataset_id as directed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread bigquery/samples/tests/test_update_dataset_default_table_expiration.py Outdated


def test_update_dataset_default_table_expiration(
capsys, client, random_dataset_id, one_day_ms

@tswast tswast Apr 8, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ditto. I recommend you use the dataset_id fixture instead of random_dataset_id, since the dataset_id fixture will create a dataset for you (to then update in the sample).

one_day_ms should just be a constant in this file.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Updated dataset_id and added the constant for one_day_ms from the fixture.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread bigquery/samples/update_dataset_default_table_expiration.py Outdated
# dataset_id = 'your-project.your_dataset'

dataset = client.get_dataset(dataset_id)
dataset.default_table_expiration_ms = one_day_ms

@tswast tswast Apr 8, 2019

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I know it's against DRY principles, but In sample code it's better to actually show the actual value rather than create a constant. That way people can see typical values and understand that an integer is expected.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lbristol88 lbristol88 Apr 8, 2019

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Took out the extra variable as directed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
lbristol88 added 3 commits April 8, 2019 15:33
@lbristol88
Removed unnecessary use of random_dataset_id in tests and removed one…
8f72584
…_day_ms fixture
@lbristol88
Removed unnecessary constant
2b30305
@lbristol88
Stored the math as a constant to make it look cleaner.
d8e579a
tswast
tswast approved these changes Apr 8, 2019
View reviewed changes

@tswast tswast left a comment

Copy link
Copy Markdown
Owner

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good, thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tswast
tswast merged commit e1bb09c into tswast:bq-snippets Apr 8, 2019
tswast pushed a commit that referenced this pull request Apr 9, 2019
@lbristol88 @tswast
Added collection of Managing Dataset samples (#6)
fa82c54
* Added delete dataset function

* Added get dataset function

* Added list dataset function

* Added update dataset description sample

* Added update dataset access sample

* Added update dataset table expiration sample

* Added tests for dataset samples and updated docs

* Removing original update dataset access from snippets file.

* Moved all dataset tests into own file. Made changes based on feedback.

* Made changes based on feedback

* Removed unnecessary use of random_dataset_id in tests and removed one_day_ms fixture

* Removed unnecessary constant

* Stored the math as a constant to make it look cleaner.
tswast pushed a commit that referenced this pull request Apr 10, 2019
@lbristol88 @tswast
Added collection of Managing Dataset samples (#6)
32e43a9
* Added delete dataset function

* Added get dataset function

* Added list dataset function

* Added update dataset description sample

* Added update dataset access sample

* Added update dataset table expiration sample

* Added tests for dataset samples and updated docs

* Removing original update dataset access from snippets file.

* Moved all dataset tests into own file. Made changes based on feedback.

* Made changes based on feedback

* Removed unnecessary use of random_dataset_id in tests and removed one_day_ms fixture

* Removed unnecessary constant

* Stored the math as a constant to make it look cleaner.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@tswast tswast tswast approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@lbristol88 @tswast
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.