-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
This is in regards with Client lib for Google Big Query. We are using google-cloud-bigquery:1.44.0 library for one of the our use cases.
We have observed the following behavior:
When we try to fetch a table's metadata that does not have fields, API is
throwing a NPE.
Stack Trace:
Exception in thread "main" java.lang.NullPointerException
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:770)
at com.google.common.collect.Lists$TransformingSequentialList.(Lists.java:569)
at com.google.common.collect.Lists.transform(Lists.java:553)
at com.google.cloud.bigquery.FieldList.fromPb(FieldList.java:116)
at com.google.cloud.bigquery.Schema.fromPb(Schema.java:107)
at com.google.cloud.bigquery.TableDefinition$Builder.table(TableDefinition.java:128)
at com.google.cloud.bigquery.StandardTableDefinition.fromPb(StandardTableDefinition.java:238)
at com.google.cloud.bigquery.TableDefinition.fromPb(TableDefinition.java:163)
at com.google.cloud.bigquery.TableInfo$BuilderImpl.(TableInfo.java:183)
at com.google.cloud.bigquery.Table.fromPb(Table.java:603)
at com.google.cloud.bigquery.BigQueryImpl.getTable(BigQueryImpl.java:415)
at bigquery.BigQueryTest.main(BigQueryTest.java:24)
Sample Code :
public class BigQueryTest {
public static void main(String args[]) throws IOException {
GoogleCredentials googleCredentials =
ServiceAccountCredentials.fromStream(new FileInputStream(""));
BigQuery bqService =
BigQueryOptions.newBuilder().setCredentials(googleCredentials).build().getService();
Dataset ds_with_empty_tables = bqService.getDataset("Native_table");
Page<Table> list = ds_with_empty_tables.list();
for(Table table : list.iterateAll()){
Table t = bqService.getTable(table.getTableId());
System.out.println(1);
}
}
}
Can someone please explain this behavior. The same scenario seems to be
working in API Reference UI - https://cloud.google.com/bigquery/docs/reference/rest/v2/
#### Environment details
- OS: Windows, Linux
- Java version: 1.8
- google-cloud-java version(s): google-cloud-bigquery:1.44.0
#### Steps to reproduce
- Try to fetch table meta data for any table without any fields using Big Query API.
Sample Code :
public class BigQueryTest {
public static void main(String args[]) throws IOException {
GoogleCredentials googleCredentials =
ServiceAccountCredentials.fromStream(new FileInputStream(""));
BigQuery bqService =
BigQueryOptions.newBuilder().setCredentials(googleCredentials).build().getService();
Dataset ds_with_empty_tables = bqService.getDataset("Native_table");
Page<Table> list = ds_with_empty_tables.list();
for(Table table : list.iterateAll()){
Table t = bqService.getTable(table.getTableId());
System.out.println(1);
}
}
}
#### Stacktrace
Exception in thread "main" java.lang.NullPointerException
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:770)
at com.google.common.collect.Lists$TransformingSequentialList.(Lists.java:569)
at com.google.common.collect.Lists.transform(Lists.java:553)
at com.google.cloud.bigquery.FieldList.fromPb(FieldList.java:116)
at com.google.cloud.bigquery.Schema.fromPb(Schema.java:107)
at com.google.cloud.bigquery.TableDefinition$Builder.table(TableDefinition.java:128)
at com.google.cloud.bigquery.StandardTableDefinition.fromPb(StandardTableDefinition.java:238)
at com.google.cloud.bigquery.TableDefinition.fromPb(TableDefinition.java:163)
at com.google.cloud.bigquery.TableInfo$BuilderImpl.(TableInfo.java:183)
at com.google.cloud.bigquery.Table.fromPb(Table.java:603)
at com.google.cloud.bigquery.BigQueryImpl.getTable(BigQueryImpl.java:415)
at bigquery.BigQueryTest.main(BigQueryTest.java:24)
#### Code snippet
public class BigQueryTest {
public static void main(String args[]) throws IOException {
GoogleCredentials googleCredentials =
ServiceAccountCredentials.fromStream(new FileInputStream(""));
BigQuery bqService =
BigQueryOptions.newBuilder().setCredentials(googleCredentials).build().getService();
Dataset ds_with_empty_tables = bqService.getDataset("Native_table");
Page<Table> list = ds_with_empty_tables.list();
for(Table table : list.iterateAll()){
Table t = bqService.getTable(table.getTableId());
System.out.println(1);
}
}
}
Thanks!