如何限制BigQuery获取的行数?

问题描述 投票:1回答:1

我正在尝试使用firebase云功能从BigQuery表中获取一些数据到我的React前端。

我的桌子有14000多行,所以我不想同时把它们全部放进去,我更愿意一次发送一个大约100个左右的请求。

我看过这里的文档:https://cloud.google.com/bigquery/docs/managing-table-data#browse-table

但他们的解决方案似乎对返回的内容没有任何影响。

exports.getTableDataFromFrontEnd = functions.runWith(runtimeOpts).https.onCall((data, context) => {
  console.log('V23');

  let promise = new Promise(function(resolve, reject) {
    async function browseRows() {  

        // Create a client
        const bigqueryClient = new BigQuery();

        const datasetId = 'CSV_Upload';
        const tableId = 'Test_Table';

        //Limit the query to 100 rows (This is not working).
        const options = {
            limit: 100    
        };

        // List rows in the table
        const [rows] = await bigqueryClient
          .dataset(datasetId)
          .table(tableId)
          .getRows(options)

          resolve(rows) //This still has 14000+ rows.
      }
      browseRows();
    });    
    return promise;
  });
javascript node.js firebase google-bigquery
1个回答
2
投票

我不确定你使用的是哪个库,但如果是这个库,那么选项的名称是maxResults,而不是limit

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.