user2569097
user2569097

Reputation: 1

Headers missing when I query data

I've experienced a strange problem when using the BigQuery API.

We use the Java API to SELECT all the data in a particular table. We do this using the following code:

QueryRequest request = new QueryRequest();
request.setQuery(statement);
Query query = service.jobs().query(projectId, request);
QueryResponse queryResp = query.execute();


// Poll until job complete....

// Job completed
GetQueryResultsResponse queryResult = service.jobs().getQueryResults(
projectId, completedJobId).execute();
List<TableRow> rows = queryResult.getRows();

When we run this on our own tables the first row contains the headers, eg:

{"f":[{"v":"Name"},{"v":"Sex"}]}

However when we run this on a different account with a different table it doesn't include the headers. The first row is the first row of the data. This is causing problems with our application because we are expecting the table headers in the first row. Can anyone help explain why this is happening?

Thanks for your help!

Chris

Upvotes: 0

Views: 748

Answers (1)

Jordan Tigani
Jordan Tigani

Reputation: 26617

The first row of query results is not the headers -- it is the first row of the result.

It sounds like when you imported the data, you may have had a header that was imported as the first row of data (you can use the skipLeadingRows value in your loads to skip a header row).

If you want to get the schema from your data, you can get it from the queryResult.getSchema() function.

Upvotes: 2

Related Questions