pabloem commented on a change in pull request #12082:
URL: https://github.com/apache/beam/pull/12082#discussion_r459713758



##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryResourceNaming.java
##########
@@ -0,0 +1,107 @@
+/*
+ * 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 java.util.Optional;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.hash.Hashing;
+
+/**
+ * This class contains utilities to standardize how resources are named by 
BigQueryIO.
+ *
+ * <p>Resources can be: - BigQuery jobs - Export jobs - Query jobs - Load jobs 
- Copy jobs -
+ * Temporary datasets - Temporary tables
+ *
+ * <p>This class has no backwards compatibility guaantees. It is considered 
internal.
+ */
+class BigQueryResourceNaming {
+
+  /**
+   * Generate a BigQuery job ID based on a prefix from {@link
+   * BigQueryResourceNaming::createJobIdPrefix}, with destination information 
added to it.
+   *
+   * @param prefix A prefix generated in {@link 
BigQueryResourceNaming::createJobIdPrefix}.
+   * @param tableDestination A descriptor of the destination table.
+   * @param partition A partition number in the destination table.
+   * @param index
+   * @return
+   */
+  static String createJobIdWithDestination(
+      String prefix, TableDestination tableDestination, int partition, long 
index) {
+    // Job ID must be different for each partition of each table.
+    String destinationHash =
+        
Hashing.murmur3_128().hashUnencodedChars(tableDestination.toString()).toString();
+    String jobId = String.format("%s_%s", prefix, destinationHash);
+    if (partition >= 0) {
+      jobId += String.format("_%05d", partition);
+    }
+    if (index >= 0) {
+      jobId += String.format("_%05d", index);
+    }
+    return jobId;
+  }
+
+  public enum JobType {
+    LOAD,
+    COPY,
+    EXPORT,
+    QUERY,
+  }
+
+  static final String BIGQUERY_JOB_TEMPLATE = 
"beam_bq_job_{TYPE}_{JOB_ID}_{STEP}_{RANDOM}";

Review comment:
       Done.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to