dina
dina

Reputation: 4289

how can I get a bigquery table schema in java

lets say I have this myTable table in BQ:

[
  {"name": "executionId", "type": "STRING"},
  {"name":"metadata", "type":"record","fields":[
    {"name":"fileName", "type":"STRING"},
    {"name":"fileType", "type":"STRING"},
    {"name":"errors", "type":"STRING"}
  ]}
]

now I'm trying to get the tables schema in my code. here is what I tried using this example:

import com.google.cloud.examples.bigquery.snippets.*;

public class MyClass {
    public static void main(String[] args) throws Exception {
        BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
        BigQuerySnippets bigQuerySnippets = new BigQuerySnippets(bigquery);
        Table table = bigQuerySnippets.getTable("MY_DATASET", "myTable");

now how do I continue? does table have a method for this?

Upvotes: 2

Views: 5843

Answers (1)

Sonya
Sonya

Reputation: 965

Table extends TableInfo, so you can get the TableDefinition from the TableInfo, and the Schema from the TableDefinition:

Schema schema = table.getDefinition().getSchema();

Upvotes: 7

Related Questions