damondouglas commented on a change in pull request #17181: URL: https://github.com/apache/beam/pull/17181#discussion_r835592220
########## File path: sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQuerySchemaTransformReadConfiguration.java ########## @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.io.gcp.bigquery; + +import com.google.api.services.bigquery.model.TableReference; +import com.google.api.services.bigquery.model.TableRow; +import com.google.auto.value.AutoValue; +import org.apache.beam.sdk.schemas.AutoValueSchema; +import org.apache.beam.sdk.schemas.annotations.DefaultSchema; +import org.apache.beam.sdk.schemas.io.InvalidConfigurationException; + +/** + * Configuration for reading from BigQuery. + * + * <p>This class is meant to be used with {@link BigQuerySchemaTransformReadProvider}. + * + * <p><b>Internal only:</b> This class is actively being worked on, and it will likely change. We + * provide no backwards compatibility guarantees, and it should not be implemented outside the Beam + * repository. + */ +@DefaultSchema(AutoValueSchema.class) +@AutoValue +public abstract class BigQuerySchemaTransformReadConfiguration { + + private static final boolean DEFAULT_USE_STANDARD_SQL = true; + + /** + * Instantiates a {@link BigQuerySchemaTransformReadConfiguration.Builder} from the SQL query. + * + * <p>The configuration defaults to useStandardSql=true. + */ + public static Builder createQueryBuilder(String query) { + return defaultBuilder().setQuery(query).setJobType(JobType.QUERY); + } + + /** + * Instantiates a {@link BigQuerySchemaTransformReadConfiguration.Builder} to support BigQuery + * extract jobs. See the getTableSpec() getter for details. + */ + public static Builder createExtractBuilder(String tableSpec) { + return defaultBuilder().setTableSpec(tableSpec).setJobType(JobType.EXTRACT); + } + + /** + * Instantiates a {@link BigQuerySchemaTransformReadConfiguration.Builder} to support BigQuery + * extract jobs. + */ + public static Builder createExtractBuilder(TableReference tableSpec) { + if (tableSpec.getProjectId().isEmpty()) { + return createExtractBuilder( + String.format("%s.%s", tableSpec.getDatasetId(), tableSpec.getTableId())); + } + return createExtractBuilder( + String.format( + "%s:%s.%s", + tableSpec.getProjectId(), tableSpec.getDatasetId(), tableSpec.getTableId())); + } + + private static Builder defaultBuilder() { + return new AutoValue_BigQuerySchemaTransformReadConfiguration.Builder() + .setJobType(JobType.UNSPECIFIED) + .setQuery("") Review comment: @laraschmidt May we consider reverting back to defaulting to empty Strings? Changing the parameters to Nullable leads to this error in the Jenkins output. When I used non-nullable and default to empty string, I didn't get this error: ``` /home/jenkins/jenkins-slave/workspace/beam_PreCommit_Java_PVR_Flink_Docker_Commit/src/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQuerySchemaTransformReadProvider.java:155: error: [argument.type.incompatible] incompatible argument for parameter tableSpec of from. 13:26:39 return BigQueryIO.readTableRowsWithSchema().from(configuration.getTableSpec()); 13:26:39 ^ 13:26:39 found : @Initialized @Nullable String 13:26:39 required: @Initialized @NonNull String 13:26:39 /home/jenkins/jenkins-slave/workspace/beam_PreCommit_Java_PVR_Flink_Docker_Commit/src/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQuerySchemaTransformReadProvider.java:159: error: [argument.type.incompatible] incompatible argument for parameter arg0 of requireNonNull. 13:26:39 String query = Objects.requireNonNull(configuration.getQuery()); 13:26:39 ^ 13:26:39 found : @Initialized @Nullable String 13:26:39 required: @Initialized @NonNull String 13:26:39 /home/jenkins/jenkins-slave/workspace/beam_PreCommit_Java_PVR_Flink_Docker_Commit/src/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQuerySchemaTransformReadProvider.java:164: error: [argument.type.incompatible] incompatible argument for parameter location of withQueryLocation. 13:26:39 read = read.withQueryLocation(configuration.getQueryLocation()); 13:26:39 ^ 13:26:39 found : @Initialized @Nullable String 13:26:39 required: @Initialized @NonNull String 13:26:39 /home/jenkins/jenkins-slave/workspace/beam_PreCommit_Java_PVR_Flink_Docker_Commit/src/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQuerySchemaTransformReadProvider.java:168: error: [condition.nullable] condition on a possibly-null value (configuration.getUseStandardSql()) 13:26:39 if (configuration.getUseStandardSql()) { ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
