Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
SANDEEPERUMALLA opened this issue Dec 26, 2018 · 2 comments
Assignees
Labels
triage me I really want to be triaged.

Comments

@SANDEEPERUMALLA
Copy link

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!

@pmakani
Copy link

pmakani commented Dec 26, 2018

already created PR #4247

@JustinBeckwith JustinBeckwith added the triage me I really want to be triaged. label Dec 27, 2018
@ajaaym
Copy link
Contributor

ajaaym commented Dec 28, 2018

This is fixed in 4247

@ajaaym ajaaym closed this as completed Dec 28, 2018
@pmakani pmakani self-assigned this Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

4 participants