Skip to content

Google Big Query API throws NPE when fetching Table Meta data with no fields #4251

@SANDEEPERUMALLA

Description

@SANDEEPERUMALLA

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

  1. 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!

Metadata

Metadata

Assignees

Labels

triage meI really want to be triaged.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions