我如何在Java获得BigQuery Table模式



我在bq中有此myTable表:

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

现在,我正在尝试在我的代码中获取表格模式。这是我尝试使用此示例的方法:

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");

现在我如何继续?table是否有一种方法?

表扩展了tableInfo,因此您可以从TableInfo中获取表格定义,以及来自TableDefinition的架构:

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