检查BigQuery Java中是否存在表

时间:2018-03-09 17:09:02

标签: google-bigquery

我正在尝试编写一个函数来检查BigQuery中是否存在表。以下代码始终返回true。问题在哪里?

谢谢!

    private static boolean checkTableExist() {
    try {
        BigQueryOptions.Builder optionsBuilder = BigQueryOptions.newBuilder();
        BigQuery bigquery = optionsBuilder.build().getService();
        bigquery.getTable(options.getBigQueryDatasetId(), options.getBigQueryTableId());

    } catch (Exception e) {

        return false;
    }
    return true;

}

1 个答案:

答案 0 :(得分:4)

I don't think you should rely on java Exception to test a boolean condition. I haven't looked a lot at the getTable() method, but here is how I check if a table exists:

public boolean isExisting() {
    return getDataset().get(tableName) != null;
}

protected Dataset getDataset() {
    return bigQuery.getDataset(dataSetName);
}
相关问题