Reputation: 869
I have a script to crate new Google BigQuery table from Google Apps Script project. When I run it with default expiration time it works well. But now I want to set expiration time equal 2 hours (7200000ms)
function createNewTable(tableId){
var table = {
expirationTime: "7200000",
tableReference: {
projectId: projectId,
datasetId: datasetId,
tableId: tableId
}
}
table = BigQuery.Tables.insert(table, projectId, datasetId);
console.info('Table created: %s', table.id);
}
It does not work because an error API call to bigquery.tables.insert failed with error: Expiration time must be at least 1 seconds in the future
.
Where I'wrong and how to fix it?
Upvotes: 1
Views: 874
Reputation: 19309
You should provide the number of milliseconds since the epoch, not since the present moment. From BigQuery table resource docs:
expirationTime: Optional. The time when this table expires, in milliseconds since the epoch.
Get the milliseconds since epoch till the present moment, and add the two hours to this:
var expirationTime = 7200000 + new Date().getTime();
If necessary, parse it to string when setting the request body: expirationTime: expirationTime.toString()
.
Upvotes: 2