java - 我怎样才能在java中获得bigquery表模式

标签 java google-bigquery

假设我在 BQ 中有这个 myTable 表:

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

现在我正在尝试在我的代码中获取表架构。 这是我尝试使用这个 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 有方法吗?

最佳答案

Table延伸TableInfo ,这样你就可以得到TableDefinition来自 TableInfo 和 Schema从表定义:

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

关于java - 我怎样才能在java中获得bigquery表模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41261880/

相关文章:

java - 如何使用 Java 获取 Linux 和 Solaris 上所有正在运行的进程的列表?

google-bigquery - 数据流作业失败并尝试在 Bigquery 上创建 temp_dataset

sql - 更改查询以避免 Bigquery 中的 "Aggregations of aggregations are not allowed"

java - 如何计算字符串数组中超过一定字符数的字符串数量。 java

java - 删除或重复私有(private)静态

java - 加工。粒子系统-如何让粒子一颗一颗进来

sql - 谷歌 BigQuery : Add new column to a table with constant value

java - 仅在辅助表中保留值

google-bigquery - 在 bigquery 中使用一年中的一周和随后的一周

java - 使用 BigQuery 读取 JSON 文件以制作表格