BigQuery API不返回数据集的最新表



我需要在BigQuery数据集中根据创建时间找到最近的表。我有一个谷歌应用程序脚本函数,可以找到最新的表,它曾经工作得很好,当数据集中只有几个表,但自从数据集中有更多的表(确切地说是72),它只是不断返回相同的"最新";(例如tableame_1623468444656),尽管我知道存在一个新的表。

问题似乎是记录器输出的大小,因为当我记录输出时,它说:"日志输出太大。删除output"。但是不管我是否记录输出,它只是返回所谓的最新表(例如tablename_1623468444656)。

我不知道我需要改变什么,以便函数可以再次找到实际的最新表。函数看起来像这样:

function findNewestTables() {
const data = BigQuery.Tables.list('Projectname', 'Datasetname');
let
maxSoFar = 0,
id = ""; 
data.tables.forEach(table => {
const time = parseInt(table.creationTime);
if(time > maxSoFar){
maxSoFar = time; 
id = table.id;
}
});
const formattedId = id.replace(":", ".");
// return formattedId;
console.log(data);
console.log(formattedId);
};

部分输出看起来像这样,然后它突然被切断。

Logging output too large. Truncating output. { totalItems: 72,
kind: 'bigquery#tableList',
etag: '7+eK1beNA7CVq0xasdfdsfYw==',
nextPageToken: 'Team_1627356444573',
tables: 
[ { id: 'tablename_1623468444656',
type: 'TABLE',
kind: 'bigquery#table',
creationTime: '1628585864499',
tableReference: [Object] },
{ tableReference: [Object],
id: 'tablename_1623554844685',
kind: 'bigquery#table',
creationTime: '1628585864503',
type: 'TABLE' },
{ id: 'tablename_1623641244614',
type: 'TABLE',
kind: 'bigquery#table',
tableReference: [Object],
creationTime: '1628585864573' },
{ tableReference: [Object],
kind: 'bigquery#table',
creationTime: '1628585864714',
type: 'TABLE',
id: 'tablename_1623727644545' },
{ tableReference: [Object],
kind: 'bigquery#table',
type: 'TABLE',
creationTime: '1628585865059',
id: 'tablename_1623814044558' },
{ creationTime: '1628585865037',
id: 'tablename_1623900444676',
type:

提前感谢你的提示。

这就是需要分页的情况之一。看到nextPageToken?如果该值不是空/nil,则意味着您可以调用表。列表,并在随后的请求中将该令牌作为pageTokenGET参数传递,以获取下一页的结果。

有关API的更多详细信息:https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/list

最新更新