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

BigQuery returns NULLABLE mode for a field that has a REQUIRED mode (field created as a NOT NULL from the beginning) #3166

Open
anneyxa opened this issue Feb 23, 2024 · 0 comments
Labels
api: bigquery Issues related to the googleapis/java-bigquery API.

Comments

@anneyxa
Copy link

anneyxa commented Feb 23, 2024

Environment details

BigQuery Client Library for Java: google-cloud-bigquery version 2.37.2 and below

I'm using Java 11.

Steps to reproduce

  1. Create a table in BigQuery console (or in any other way) with a NOT NULL field, i.e. CREATE TABLE sample.TEST_TABLE ( C1 INT64 NOT NULL, C2 BIGNUMERIC );
  2. Use BigQuery Client Library for Java to execute select statement for that table. Received schema should report that C1 column has mode REQUIRED, while it reports the mode as NULLABLE.

Code example

// create a com.google.cloud.bigquery.BigQuery object, i.e.:
// BigQuery bigQuery = BigQueryOptions.newBuilder()......

String query = "SELECT * FROM sample.TEST_TABLE";
Job job = bigQuery.create(JobInfo.of(QueryJobConfiguration.newBuilder(query).build()));
TableResult result = job.getQueryResults();
Schema schema = result.getSchema();

// Print the schema, or print the fields:
List<Field> fields = schema.getFields();
for (Field field : fields) {
    System.out.println("Field Mode: " + field.getMode());
    // C1 column which was created as NOT NULL and has REQUIRED mode in BigQuery console 
    // is being returned here as mode NULLABLE
}

// OR

// create a com.google.cloud.bigquery.BigQuery object, i.e.:
// BigQuery bigQuery = BigQueryOptions.newBuilder()......

String query = "SELECT * FROM sample.TEST_TABLE";
QueryJobConfiguration.Builder configuration = QueryJobConfiguration.newBuilder(query).setDryRun(true);
Schema schema = ((QueryStatistics) bigQuery.create(JobInfo.of(configuration.build())).getStatistics()).getSchema();

System.out.println(schema);
// See at C1 column mode: Should be REQUIRED but is NULLABLE.

Prints out 2 nullable fields.

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/java-bigquery API. label Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/java-bigquery API.
Projects
None yet
Development

No branches or pull requests

1 participant