Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0bc45f

Browse files
committed
Added tests for export data formats
1 parent a526c62 commit d0bc45f

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

bigquery/samples/export_data_to_cloud_storage.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def export_table(service, cloud_storage_path,
2929
service: initialized and authorized bigquery
3030
google-api-client object,
3131
cloud_storage_path: fully qualified
32-
path to a Google Cloud Storage location,
33-
e.g. gs://mybucket/myfolder/
34-
export_format: format to export in;
35-
"CSV", "NEWLINE_DELIMITED_JSON", or "AVRO".
32+
path to a Google Cloud Storage location,
33+
e.g. gs://mybucket/myfolder/
34+
export_format: format to export in;
35+
"CSV", "NEWLINE_DELIMITED_JSON", or "AVRO".
3636
3737
Returns: an extract job resource representing the
3838
job, see https://cloud.google.com/bigquery/docs/reference/v2/jobs
@@ -65,7 +65,7 @@ def export_table(service, cloud_storage_path,
6565
# [START run]
6666
def run(cloud_storage_path,
6767
projectId, datasetId, tableId,
68-
num_retries, interval):
68+
num_retries, interval, export_format="CSV"):
6969

7070
bigquery = get_service()
7171
resource = export_table(bigquery, cloud_storage_path,
@@ -74,6 +74,7 @@ def run(cloud_storage_path,
7474
resource['jobReference']['projectId'],
7575
resource['jobReference']['jobId'],
7676
interval,
77+
export_format,
7778
num_retries)
7879
# [END run]
7980

bigquery/tests/test_export_data_to_cloud_storage.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,32 @@
2222

2323
class TestExportTableToGCS(CloudBaseTest):
2424

25-
def test_export_table(self):
25+
def test_export_table_csv(self):
2626
run(self.constants['cloudStorageInputURI'],
2727
self.constants['projectId'],
2828
self.constants['datasetId'],
2929
self.constants['newTableId'],
3030
5,
31-
5)
31+
5,
32+
export_format="CSV")
33+
34+
def test_export_table_json(self):
35+
run(self.constants['cloudStorageInputURI'],
36+
self.constants['projectId'],
37+
self.constants['datasetId'],
38+
self.constants['newTableId'],
39+
5,
40+
5,
41+
export_format="NEWLINE_DELIMITED_JSON")
3242

43+
def test_export_table_avro(self):
44+
run(self.constants['cloudStorageInputURI'],
45+
self.constants['projectId'],
46+
self.constants['datasetId'],
47+
self.constants['newTableId'],
48+
5,
49+
5,
50+
export_format="AVRO")
3351

3452
if __name__ == '__main__':
3553
unittest.main()

0 commit comments

Comments
 (0)