vb.net中的大查询分页

时间:2014-12-23 21:21:24

标签: vb.net pagination google-bigquery

我正在尝试使用vb.net浏览BigQuery数据。我一直用我的代码得到相同的第一页数据。我理解的方式,我需要设置响应的pagetoken以查看下一页。

使用以下代码,我只得到第一页数据而从不退出循环。

对于登录我设置了我的queryrequest的Oauthtoken,这是第一页正常,但没有尝试以这种方式翻阅结果。

我很欣赏任何领导方向。

    Dim DT As New DataTable
    Dim ErrMessage As String = ""
    Try
        Dim INIT As New BigqueryService.Initializer
        Dim scopes As IList(Of String) = New List(Of String)()
        scopes.Add(BigqueryService.Scope.Bigquery)
        Dim credential As UserCredential
        Using stream As New FileStream("client_secrets.json", FileMode.Open, FileAccess.Read)
            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, scopes, "user", CancellationToken.None, New FileDataStore("BQ.App")).Result
        End Using
        INIT.HttpClientInitializer = credential
        Dim service As New BigqueryService(INIT)
        Dim j As JobsResource = service.Jobs
        Dim req As New QueryRequest
        req.Query = tQuery.Text
        Dim QRequest As JobsResource.QueryRequest = j.Query(req, projectId)
        QRequest.OauthToken = MyAccessToken
        Dim JOBID As String = QRequest.Execute.JobReference.JobId
        Dim DATA = QRequest.Execute
        Dim schema = DATA.Schema
        For Each col In schema.Fields
            DT.Columns.Add(col.Name)
        Next
        Dim page_Tok = ""
        Dim rr As GetQueryResultsResponse
        While True
            Try
                rr.PageToken = page_Tok
            Catch ex As Exception
                 'No Token Yet
            End Try

            rr = j.GetQueryResults(projectId, JOBID).Execute

            page_Tok = rr.PageToken
            If rr.JobComplete = True Then
                If page_Tok = "" Then
                    Exit While
                End If
            End If
            Dim resp2 = rr.Rows
            For Each row In resp2
                Dim DR As DataRow = DT.NewRow
                For f = 0 To row.F.Count - 1
                    Dim field = row.F
                    DR(f) = row.F(f).V
                Next
                DT.Rows.Add(DR)
            Next
        End While
    Catch ex As Exception
        ErrMessage = ex.Message
    End Try

1 个答案:

答案 0 :(得分:1)

我不是VB专家,但您没有在GetQueryResultsRequest中设置页面标记,而是在响应中设置它。见https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/csharp/latest/classGoogle_1_1Apis_1_1Bigquery_1_1v2_1_1JobsResource_1_1GetQueryResultsRequest.html

我认为这会奏效:

        req = j.GetQueryResults(projectId, JOBID)
        req.PageToken = page_tok
        rr = req.Execute