-1

Given a SELECT statement in Big Query and the Java SDK, what are my options to get the actual column names without fetching the data? I know I can execute the statement and then get the Schema via the TableResult. But is there a way to get the names without fetching data? We have a tool where we run arbitrary queries which are not known upfront and in my code I want to access the result columns by name.

Update: someone flagged this as duplicate of a 7 year old entry. I am however looking for a way to use the Java SDK alone to get the column names, not to do some magic with the query itself or query some metatable.

reikje
  • 2,850
  • 2
  • 24
  • 44
  • Possible duplicate of [Bigquery query to find the column names of a table](https://stackoverflow.com/questions/11338670/bigquery-query-to-find-the-column-names-of-a-table) – Andrei Cusnir Feb 19 '19 at 08:54

1 Answers1

1

There are few options but the easiest is to add limit 0 to your query so for example:

SELECT * FROM projectId.datasetId.tableId limit 0
Tamir Klein
  • 3,514
  • 1
  • 20
  • 38
  • Or leave the query as-is and use the `dryRun` setting. – Elliott Brossard Feb 19 '19 at 10:17
  • I will test `dryRun` first, because then I wouldn't have to modify the query. However, I vaguely remember that you don't have a `TableResult` in the Java SDK when doing a `dryRun` - hence no access to a `Schema`. I could be wrong. Will re-test. – reikje Feb 19 '19 at 11:56