I am using the BigQuery API in my appengine project to create a table and then load data using insertAll streaming input method. [ Ref: https://cloud.google.com/bigquery/docs/reference/v2/tables/insert ]
Sample python Code to create table:
scope = "https://www.googleapis.com/auth/bigquery"
authorization_token, _ = app_identity.get_access_token(scope)
Bodyfields = {
"kind": "bigquery#table",
"tableReference": {
"projectId": BIGQUERY_PROJECTID,
"datasetId": BIGQUERY_DATASETID,
"tableId": BIGQUERY_TABLEID
},
"friendlyName": 'Table 1',
"description": 'My first table in big query',
"schema": {
"fields": [
{
"name": 'A',
"type": 'STRING'
},
{
"name": 'B',
"type": 'STRING'
}
]
}
}
result = urlfetch.fetch(url="https://www.googleapis.com/bigquery/v2/projects/" + BIGQUERY_PROJECTID + "/datasets/" + BIGQUERY_DATASETID + "/tables", method=urlfetch.POST, payload=json.dumps(Bodyfields), headers = {'Content-Type': 'application/json', "Authorization": "Bearer " + authorization_token})
logging.info(result.content)
This works as expected, but unfortunately the 'expirationTime' of table is set to 1 day.
According to the docs, when expirationTime is not provided in the requestBody, table is persisted indefinitely. [ Ref: https://cloud.google.com/bigquery/docs/reference/v2/tables#expirationTime ]. As seen in the image, my table is expiring in 1 day.
So I modified the code to include 'expirationTime' in the requestBody of insert table method.
Code sample:
ist_one_year_later = datetime.now() + timedelta(weeks=52)
ist_one_year_later_epoch_timestamp = long(float((ist_one_year_later - datetime(1970,1,1)).total_seconds()))
scope = "https://www.googleapis.com/auth/bigquery"
authorization_token, _ = app_identity.get_access_token(scope)
Bodyfields = {
"kind": "bigquery#table",
"tableReference": {
"projectId": BIGQUERY_PROJECTID,
"datasetId": BIGQUERY_DATASETID,
"tableId": BIGQUERY_TABLEID
},
"friendlyName": 'Table 1',
"description": 'My first table in big query',,
"expirationTime": ist_one_year_later_epoch_timestamp,
"schema": {
"fields": [
{
"name": 'A',
"type": 'STRING'
},
{
"name": 'B',
"type": 'STRING'
}
]
}
}
result = urlfetch.fetch(url="https://www.googleapis.com/bigquery/v2/projects/" + BIGQUERY_PROJECTID + "/datasets/" + BIGQUERY_DATASETID + "/tables", method=urlfetch.POST, payload=json.dumps(Bodyfields), headers = {'Content-Type': 'application/json', "Authorization": "Bearer " + authorization_token})
logging.info(result.content)
Now the outcome is even more bizzare. The response of this request, says table is created. But when i try to list the tables in the dataset, the table is not available.
Can someone tell me how to set expirationTime of a table to 1 year from creationTime?
EDIT: I have tried the patch and update method. Both does not give any error, but does not extend the expirationTime also.