Skip to content
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

BigQuery: Add load_table_from_json() method to BQ client #9076

Merged
merged 5 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Manipulate a copy of the job config if provided
The load_table_from_json() should not directly change the job config
passed in as an argument.
  • Loading branch information
plamut committed Aug 22, 2019
commit 197a0be0aec9b2cfacbae317f4129877e32f8ee6
3 changes: 3 additions & 0 deletions bigquery/google/cloud/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,9 @@ def load_table_from_json(

if job_config is None:
job_config = job.LoadJobConfig()
else:
# Make a copy so that the job config isn't modified in-place.
job_config = copy.deepcopy(job_config)
job_config.source_format = job.SourceFormat.NEWLINE_DELIMITED_JSON

if project is None:
Expand Down
5 changes: 4 additions & 1 deletion bigquery/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5627,6 +5627,8 @@ def test_load_table_from_json_non_default_args(self):
{"name": "Two", "age": 22, "birthday": "1997-08-09", "adult": True},
]

job_config = job.LoadJobConfig()

load_patch = mock.patch(
"google.cloud.bigquery.client.Client.load_table_from_file", autospec=True
)
Expand All @@ -5635,7 +5637,7 @@ def test_load_table_from_json_non_default_args(self):
client.load_table_from_json(
json_rows,
self.TABLE_REF,
job_config=job.LoadJobConfig(), # TODO: add options?
job_config=job_config,
project="project-x",
location="EU",
)
Expand All @@ -5653,6 +5655,7 @@ def test_load_table_from_json_non_default_args(self):
)

sent_config = load_table_from_file.mock_calls[0][2]["job_config"]
assert job_config.source_format is None # the original was not modified
assert sent_config.source_format == job.SourceFormat.NEWLINE_DELIMITED_JSON
assert sent_config.schema is None

Expand Down