Skip to content

Commit 7e959e9

Browse files
committed
foo
1 parent 1929f12 commit 7e959e9

5 files changed

Lines changed: 30 additions & 29 deletions

File tree

sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BufferMismatchedRows.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class BufferMismatchedRows<DestinationT extends @NonNull Object, ElementT>
6666
// StorageApiWriteRecordsInconsistent.
6767
private final TupleTag<KV<String, String>> finalizeTag = new TupleTag<>("finalizeTag");
6868
private static final int NUM_DEFAULT_SHARDS = 20;
69+
private static final Duration RETRY_MISMATCHED_ROWS_PERIOD = Duration.standardMinutes(1);
6970

7071
public BufferMismatchedRows(
7172
Coder<BigQueryStorageApiInsertError> failedRowsCoder,
@@ -155,8 +156,6 @@ class BufferingDoFn
155156
private final Counter rowsSentToFailedRowsCollection =
156157
Metrics.counter(BufferMismatchedRows.BufferingDoFn.class, "rowsSentToFailedRowsCollection");
157158

158-
private final Duration RETRY_MISMATCHED_ROWS_PERIOD = Duration.standardMinutes(1);
159-
160159
public BufferingDoFn(
161160
StorageApiWriteUnshardedRecords.WriteRecordsDoFn<DestinationT, ElementT> writeDoFn) {
162161
this.writeDoFn = writeDoFn;

sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/MismatchedRow.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ static MismatchedRow of(StorageApiWritePayload payload, org.joda.time.Instant de
4646
// inside of state
4747
// variables (mostly involving the Dataflow runner and update). Therefore we use a custom coder.
4848
static class Coder extends CustomCoder<MismatchedRow> {
49-
static final ByteArrayCoder byteArrayCoder = ByteArrayCoder.of();
50-
static final InstantCoder instantCoder = InstantCoder.of();
51-
static final NullableCoder<byte[]> nullableByteArrayCoder = NullableCoder.of(byteArrayCoder);
52-
static final NullableCoder<Instant> nullableInstantCoder = NullableCoder.of(InstantCoder.of());
49+
static final ByteArrayCoder BYTE_ARRAY_CODER = ByteArrayCoder.of();
50+
static final InstantCoder INSTANT_CODER = InstantCoder.of();
51+
static final NullableCoder<byte[]> NULLABLE_BYTE_ARRAY_CODER =
52+
NullableCoder.of(BYTE_ARRAY_CODER);
53+
static final NullableCoder<Instant> NULLABLE_INSTANT_CODER =
54+
NullableCoder.of(InstantCoder.of());
5355

5456
static MismatchedRow.Coder of() {
5557
return new Coder();
@@ -58,22 +60,22 @@ static MismatchedRow.Coder of() {
5860
@Override
5961
public void encode(MismatchedRow value, OutputStream outStream)
6062
throws CoderException, IOException {
61-
byteArrayCoder.encode(value.getPayload().getPayload(), outStream);
62-
nullableByteArrayCoder.encode(value.getPayload().getUnknownFieldsPayload(), outStream);
63-
nullableInstantCoder.encode(value.getPayload().getTimestamp(), outStream);
64-
nullableByteArrayCoder.encode(value.getPayload().getFailsafeTableRowPayload(), outStream);
65-
nullableByteArrayCoder.encode(value.getPayload().getSchemaHash(), outStream);
66-
instantCoder.encode(value.getDeadline(), outStream);
63+
BYTE_ARRAY_CODER.encode(value.getPayload().getPayload(), outStream);
64+
NULLABLE_BYTE_ARRAY_CODER.encode(value.getPayload().getUnknownFieldsPayload(), outStream);
65+
NULLABLE_INSTANT_CODER.encode(value.getPayload().getTimestamp(), outStream);
66+
NULLABLE_BYTE_ARRAY_CODER.encode(value.getPayload().getFailsafeTableRowPayload(), outStream);
67+
NULLABLE_BYTE_ARRAY_CODER.encode(value.getPayload().getSchemaHash(), outStream);
68+
INSTANT_CODER.encode(value.getDeadline(), outStream);
6769
}
6870

6971
@Override
7072
public MismatchedRow decode(InputStream inStream) throws CoderException, IOException {
71-
byte[] innerPayload = byteArrayCoder.decode(inStream);
72-
byte @Nullable [] unknownFieldsPayload = nullableByteArrayCoder.decode(inStream);
73-
@Nullable Instant timestamp = nullableInstantCoder.decode(inStream);
74-
byte @Nullable [] failsafeTableRowPayload = nullableByteArrayCoder.decode(inStream);
75-
byte @Nullable [] schemaHash = nullableByteArrayCoder.decode(inStream);
76-
Instant deadline = instantCoder.decode(inStream);
73+
byte[] innerPayload = BYTE_ARRAY_CODER.decode(inStream);
74+
byte @Nullable [] unknownFieldsPayload = NULLABLE_BYTE_ARRAY_CODER.decode(inStream);
75+
@Nullable Instant timestamp = NULLABLE_INSTANT_CODER.decode(inStream);
76+
byte @Nullable [] failsafeTableRowPayload = NULLABLE_BYTE_ARRAY_CODER.decode(inStream);
77+
byte @Nullable [] schemaHash = NULLABLE_BYTE_ARRAY_CODER.decode(inStream);
78+
Instant deadline = INSTANT_CODER.decode(inStream);
7779

7880
StorageApiWritePayload payload =
7981
StorageApiWritePayload.of(

sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/StorageApiWriteUnshardedRecords.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,11 @@ long flush(
581581

582582
pendingMessages.clear();
583583

584+
if (rowsToProcess.getProtoRows().getSerializedRowsCount() == 0) {
585+
// All rows either failed or were buffered with schema mismatches.
586+
return 0;
587+
}
588+
584589
// Handle the case where the request is too large.
585590
if (rowsToProcess.getProtoRows().getSerializedSize() >= maxRequestSize) {
586591
if (rowsToProcess.getProtoRows().getSerializedRowsCount() > 1) {

sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/StorageApiWritesShardedRecords.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public class StorageApiWritesShardedRecords<DestinationT extends @NonNull Object
126126
PCollectionTuple> {
127127
private static final Logger LOG = LoggerFactory.getLogger(StorageApiWritesShardedRecords.class);
128128
private static final Duration DEFAULT_STREAM_IDLE_TIME = Duration.standardHours(1);
129+
private static final Duration RETRY_MISMATCHED_ROWS_PERIOD = Duration.standardMinutes(1);
129130

130131
private final StorageApiDynamicDestinations<ElementT, DestinationT> dynamicDestinations;
131132
private final CreateDisposition createDisposition;
@@ -373,8 +374,6 @@ class WriteRecordsDoFn
373374
@TimerId("idleTimer")
374375
private final TimerSpec idleTimerSpec = TimerSpecs.timer(TimeDomain.PROCESSING_TIME);
375376

376-
private final Duration RETRY_MISMATCHED_ROWS_PERIOD = Duration.standardMinutes(1);
377-
378377
private final Duration streamIdleTime;
379378
private final long splitSize;
380379
private final long maxRequestSize;
@@ -800,9 +799,6 @@ public void process(
800799
@StateId("minPendingTimestamp") ValueState<Long> minPendingTimestamp,
801800
final MultiOutputReceiver o)
802801
throws Exception {
803-
Instant now = Instant.now();
804-
System.err.println("PROCESS " + now);
805-
806802
dynamicDestinations.setSideInputAccessorFromProcessContext(c);
807803
TableDestination tableDestination =
808804
destinations.computeIfAbsent(
@@ -861,7 +857,6 @@ public void process(
861857
idleTimer,
862858
o,
863859
processMismatchedRows);
864-
System.err.println("PROCESS DONE AFTER " + java.time.Duration.between(now, Instant.now()));
865860
}
866861

867862
private void processPayloads(
@@ -1259,7 +1254,6 @@ public void onMismatchedRowsTimer(
12591254
@StateId("currentMismatchedRowTimerValue") ValueState<Long> currentTimerValue,
12601255
@StateId("minPendingTimestamp") ValueState<Long> minPendingTimestamp)
12611256
throws Exception {
1262-
System.err.println("RETRY TIMER " + Instant.now());
12631257
mismatchedRowsBag.readLater();
12641258
currentTimerValue.readLater();
12651259
minPendingTimestamp.readLater();

sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/UpgradeTableSchema.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.beam.sdk.io.gcp.bigquery;
1919

2020
import com.google.api.services.bigquery.model.TableCell;
21-
import com.google.api.services.bigquery.model.TableRow;
2221
import com.google.cloud.bigquery.storage.v1.BigQuerySchemaUtil;
2322
import com.google.cloud.bigquery.storage.v1.TableFieldSchema;
2423
import com.google.cloud.bigquery.storage.v1.TableSchema;
@@ -317,7 +316,8 @@ private static boolean hasUnknownFields(Message message) {
317316
}
318317

319318
public static boolean missingUnknownField(
320-
TableRow unknownFields, ThrowingSupplier<Descriptors.Descriptor> schemaDescriptor)
319+
AbstractMap<String, Object> unknownFields,
320+
ThrowingSupplier<Descriptors.Descriptor> schemaDescriptor)
321321
throws Exception {
322322
@Nullable Object fValue = unknownFields.get("f");
323323
if (fValue instanceof List) {
@@ -392,8 +392,9 @@ private static boolean missingUnknownFieldObject(
392392
}
393393
}
394394
return false;
395-
} else if (value instanceof TableRow) {
396-
return missingUnknownField((TableRow) value, fieldDescriptor.getMessageType());
395+
} else if (value instanceof AbstractMap) {
396+
return missingUnknownField(
397+
(AbstractMap<String, Object>) value, fieldDescriptor.getMessageType());
397398
}
398399
return false;
399400
}

0 commit comments

Comments
 (0)