【问题标题】:How do I limit the amount of rows BigQuery gets?如何限制 BigQuery 获取的行数?
【发布时间】:2019-04-30 13:21:02
【问题描述】:

我正在尝试使用 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】:

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

    【讨论】:

    • 非常感谢。那解决了它。我想我对不同的文档集感到困惑。
    猜你喜欢
    • 1970-01-01
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多