Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Accept a string in Table and Dataset constructors.#7483

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletionsbigquery/google/cloud/bigquery/dataset.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -306,8 +306,13 @@ class Dataset(object):
https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets

Args:
dataset_ref (google.cloud.bigquery.dataset.DatasetReference):
a pointer to a dataset
dataset_ref (Union[ \
:class:`~google.cloud.bigquery.dataset.DatasetReference`, \
str, \
]):
A pointer to a dataset. If ``dataset_ref`` is a string, it must
include both the project ID and the dataset ID, separated by
``.``.
"""

_PROPERTY_TO_API_FIELD = {
Expand All@@ -318,6 +323,8 @@ class Dataset(object):
}

def __init__(self, dataset_ref):
if isinstance(dataset_ref, six.string_types):
dataset_ref = DatasetReference.from_string(dataset_ref)
self._properties = {"datasetReference": dataset_ref.to_api_repr(), "labels": {}}

@property
Expand Down
11 changes: 9 additions & 2 deletionsbigquery/google/cloud/bigquery/table.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -348,8 +348,13 @@ class Table(object):
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables

Args:
table_ref (google.cloud.bigquery.table.TableReference):
A pointer to a table
table_ref (Union[ \
:class:`~google.cloud.bigquery.table.TableReference`, \
str, \
]):
A pointer to a table. If ``table_ref`` is a string, it must
included a project ID, dataset ID, and table ID, each separated
by ``.``.
schema (List[google.cloud.bigquery.schema.SchemaField]):
The table's schema
"""
Expand All@@ -367,6 +372,8 @@ class Table(object):
}

def __init__(self, table_ref, schema=None):
if isinstance(table_ref, six.string_types):
table_ref = TableReference.from_string(table_ref)
self._properties = {"tableReference": table_ref.to_api_repr(), "labels": {}}
# Let the @property do validation.
if schema is not None:
Expand Down
11 changes: 11 additions & 0 deletionsbigquery/tests/unit/test_dataset.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,7 @@
import unittest

import mock
import pytest


class TestAccessEntry(unittest.TestCase):
Expand DownExpand Up@@ -364,6 +365,16 @@ def test_ctor_defaults(self):
self.assertIsNone(dataset.friendly_name)
self.assertIsNone(dataset.location)

def test_ctor_string(self):
dataset = self._make_one("some-project.some_dset")
self.assertEqual(dataset.project, "some-project")
self.assertEqual(dataset.dataset_id, "some_dset")

def test_ctor_string_wo_project_id(self):
with pytest.raises(ValueError):
# Project ID is missing.
self._make_one("some_dset")

def test_ctor_explicit(self):
from google.cloud.bigquery.dataset import DatasetReference, AccessEntry

Expand Down
11 changes: 11 additions & 0 deletionsbigquery/tests/unit/test_table.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -504,6 +504,17 @@ def test_ctor_w_schema(self):

self.assertEqual(table.schema, [full_name, age])

def test_ctor_string(self):
table = self._make_one("some-project.some_dset.some_tbl")
self.assertEqual(table.project, "some-project")
self.assertEqual(table.dataset_id, "some_dset")
self.assertEqual(table.table_id, "some_tbl")

def test_ctor_string_wo_project_id(self):
with pytest.raises(ValueError):
# Project ID is missing.
self._make_one("some_dset.some_tbl")

def test_num_bytes_getter(self):
dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp