Skip to content

Commit 8f365c6

Browse files
added udf support to client.write_table and tests fixed
1 parent eecd8f4 commit 8f365c6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

bigquery/client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ def write_to_table(
861861
query,
862862
dataset=None,
863863
table=None,
864+
external_udf_uris=[],
864865
allow_large_results=None,
865866
use_query_cache=None,
866867
priority=None,
@@ -919,6 +920,14 @@ def write_to_table(
919920
if write_disposition:
920921
configuration['writeDisposition'] = write_disposition
921922

923+
configuration['userDefinedFunctionResources'] = []
924+
for external_udf_uri in external_udf_uris:
925+
configuration['userDefinedFunctionResources'].append(
926+
{
927+
"resourceUri": external_udf_uri
928+
}
929+
)
930+
922931
body = {
923932
"configuration": {
924933
'query': configuration
@@ -1230,7 +1239,7 @@ def _transform_row(self, row, schema):
12301239

12311240
elif col_dict['type'] == 'BOOLEAN':
12321241
row_value = row_value in ('True', 'true', 'TRUE')
1233-
1242+
12341243
elif col_dict['type'] == 'TIMESTAMP':
12351244
row_value = float(row_value)
12361245

bigquery/tests/test_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ def setUp(self):
10121012
self.project_id = 'project'
10131013
self.dataset_id = 'dataset'
10141014
self.table_id = 'table'
1015+
self.external_udf_uris = ['gs://bucket/external_udf.js']
10151016
self.use_query_cache = False
10161017
self.priority = "INTERACTIVE"
10171018
self.client = client.BigQueryClient(self.mock_api,
@@ -1032,6 +1033,9 @@ def test_write(self):
10321033
"tableId": self.table_id
10331034
},
10341035
"query": self.query,
1036+
"userDefinedFunctionResources": [{
1037+
"resourceUri": self.external_udf_uris[0]
1038+
}],
10351039
"useQueryCache": self.use_query_cache,
10361040
"priority": self.priority,
10371041
}
@@ -1042,6 +1046,7 @@ def test_write(self):
10421046
result = self.client.write_to_table(self.query,
10431047
self.dataset_id,
10441048
self.table_id,
1049+
external_udf_uris=self.external_udf_uris,
10451050
use_query_cache=False,
10461051
priority=self.priority)
10471052

0 commit comments

Comments
 (0)