如何在Java中获取bigquery表架构 [英] how can I get a bigquery table schema in java
本文介绍了如何在Java中获取bigquery表架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我说我在BQ中有这个 myTable
表:
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");
现在我如何继续? table
对此有方法吗?
now how do I continue?
does table
have a method for this?
推荐答案
Table extends TableInfo, so you can get the TableDefinition from the TableInfo, and the Schema from the TableDefinition:
Schema schema = table.getDefinition().getSchema();
这篇关于如何在Java中获取bigquery表架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文