首页 > 解决方案 > 如何限制 BigQuery 获取的行数?

问题描述

我正在尝试使用 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;
  });

标签: javascriptnode.jsfirebasegoogle-bigquery

解决方案


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

在此处输入图像描述


推荐阅读