【问题标题】:BigQuery Pagination through large result set with cloud library使用云库通过大型结果集进行 BigQuery 分页
【发布时间】:2018-01-27 13:23:15
【问题描述】:

我正在访问来自 Google BigQuery 的数据,数据为 500MB,我需要将其转换为需求的一部分。我正在设置Allow Large Results,设置destination table等。

我已经在 Google 的新云库中编写了一个 java 作业,因为现在推荐使用它 - com.google.cloud:google-cloud-bigquery:0.21.1-beta(我也尝试了 0.20 测试版,但没有任何成果)

我在对这些数据进行分页时遇到问题,该库在获取结果页面方面不一致。这是我的代码sn-p,

代码片段

    System.out.println("Accessing Handle of Response");
    QueryResponse response = bigquery.getQueryResults(jobId, QueryResultsOption.pageSize(10000));
    System.out.println("Got Handle of Response");

    System.out.println("Accessing results");
    QueryResult result = response.getResult();
    System.out.println("Got handle of Result. Total Rows: "+result.getTotalRows());

    System.out.println("Reading the results");
    int pageIndex = 0;
    int rowId = 0;
    while (result != null) {
        System.out.println("Reading Page: "+ pageIndex);
        if(result.hasNextPage())
        {
            System.out.println("There is Next Page");       
        }
        else
        {
            System.out.println("No Next Page");
        }

        for (List<FieldValue> row : result.iterateAll()) {
            System.out.println("Row: " + rowId);
            rowId++;
        }

        System.out.println("Getting Next Page: ");
        pageIndex++;
        result = result.getNextPage();
    }

输出打印语句

Accessing Handle of Response  
Got Handle of Response  
Accessing results  
Got handle of Result. Total Rows: 9617008  
Reading the results  
Reading Page: 0  
There is Next Page  
Row: 0  
Row: 1  
Row: 2  
Row: 3  
:  
:  
Row: 9999  
Row: 10000  
Row: 10001  
:  
:  
Row: 19999  
:  
:  

请注意,它永远不会点击/打印 - “获取下一页:”。

我的期望是一次获得 10000 行的数据块。请注意,如果我在返回 10-15K 行的查询上运行相同的代码并将 pageSize 设置为 100 条记录,我会在每 100 行之后得到“获取下一页:”。这是这个 beta 库的一个已知问题吗?

【问题讨论】:

    标签: java pagination google-bigquery


    【解决方案1】:

    这看起来非常接近我几个小时以来一直在努力解决的问题。而且我刚刚找到了解决方案,所以我会在这里分享它,尽管您可能很久以前就自己找到了解决方案。

    我完全按照文档和教程所说的那样做,但是我的页面大小没有得到尊重,而且我每次都得到所有行,无论我做什么。最终我找到了另一个例子,我认为是官方的,right here

    我从该示例中学到的是,您应该只使用 iterateAll() 来获取其余行。要获取当前页面行,您需要改用getValues()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-24
      • 2016-05-23
      • 2014-06-29
      • 2012-04-12
      • 1970-01-01
      • 1970-01-01
      • 2013-05-13
      • 1970-01-01
      相关资源
      最近更新 更多