简体   繁体   中英

Ordering BigQuery Results in Java SDK

I am trying to get ordered results from a BigQuery with help of google cloud SDK.

The query looks like:

SELECT * FROM `table`
            |WHERE id = 111
            |ORDER BY time DESC

Then I create and run the Job:

Job job = QueryJobConfiguration.newBuilder(query)
            .setUseLegacySql(false)
            .build()

The issue, is when I actually fetch results, I receive them unordered:

TableResult results = job.getQueryResults()
results.iterateAll()

If I run the original query inside the BigQuery UI, everything seems to fine.

Any ideas, at which place and why the results being shuffled?

The issue was, that I've added ORDER BY clause later in query.

Still, I was accessing the job with the same jobId. That made BigQuery to fetch previous results, which where unsorted. Updating JobId helped!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM