Repository navigation
[#18690] Port Iceberg IO tests off deprecated DoFnTester #40909
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| import static org.hamcrest.Matchers.empty; | ||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
@@ -31,13 +32,15 @@ | |
| import org.apache.beam.sdk.io.iceberg.IcebergUtils; | ||
| import org.apache.beam.sdk.io.iceberg.TestDataWarehouse; | ||
| import org.apache.beam.sdk.schemas.Schema; | ||
| import org.apache.beam.sdk.transforms.DoFnTester; | ||
| import org.apache.beam.sdk.transforms.DoFn.OutputReceiver; | ||
| import org.apache.beam.sdk.transforms.join.CoGbkResult; | ||
| import org.apache.beam.sdk.transforms.windowing.GlobalWindow; | ||
| import org.apache.beam.sdk.transforms.windowing.PaneInfo; | ||
| import org.apache.beam.sdk.values.KV; | ||
| import org.apache.beam.sdk.values.Row; | ||
| import org.apache.beam.sdk.values.TimestampedValue; | ||
| import org.apache.beam.sdk.values.ValueInSingleWindow; | ||
| import org.apache.beam.sdk.values.ValueKind; | ||
| import org.apache.beam.sdk.values.WindowedValues; | ||
| import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList; | ||
| import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; | ||
| import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableSet; | ||
|
|
@@ -175,20 +178,41 @@ private List<ValueInSingleWindow<Row>> process( | |
| throws Exception { | ||
| CoGbkResult result = | ||
| CoGbkResult.of(ResolveChanges.DELETES, deletes).and(ResolveChanges.INSERTS, inserts); | ||
| try (DoFnTester<KV<CdcRowDescriptor, CoGbkResult>, Row> tester = | ||
| DoFnTester.of(new ResolveChanges(scanConfig(icebergSchema)))) { | ||
| tester.processTimestampedElement( | ||
| TimestampedValue.of( | ||
| KV.of( | ||
| CdcRowDescriptor.builder() | ||
| .setCommitSnapshotId(123) | ||
| .setSnapshotSequenceNumber(456) | ||
| .setPrimaryKey(pk) | ||
| .build(), | ||
| result), | ||
| timestamp)); | ||
| return tester.getMutableOutput(tester.getMainOutputTag()); | ||
| } | ||
| ResolveChanges fn = new ResolveChanges(scanConfig(icebergSchema)); | ||
| fn.setup(); | ||
| List<ValueInSingleWindow<Row>> outputs = new ArrayList<>(); | ||
| OutputReceiver<Row> receiver = | ||
| output -> | ||
| WindowedValues.<Row>builder() | ||
| .setValue(output) | ||
| .setWindow(GlobalWindow.INSTANCE) | ||
| .setPaneInfo(PaneInfo.NO_FIRING) | ||
| .setTimestamp(timestamp) | ||
| .setReceiver( | ||
| wv -> | ||
| outputs.add( | ||
| ValueInSingleWindow.of( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Critical: Similar to Pass |
||
| wv.getValue(), | ||
| wv.getTimestamp(), | ||
| wv.getWindows().iterator().next(), | ||
| wv.getPaneInfo(), | ||
| wv.getRecordId(), | ||
| wv.getRecordOffset(), | ||
| wv.causedByDrain(), | ||
| wv.getOpenTelemetryContext(), | ||
| wv.getValueKind()))); | ||
|
|
||
| fn.processElement( | ||
| KV.of( | ||
| CdcRowDescriptor.builder() | ||
| .setCommitSnapshotId(123) | ||
| .setSnapshotSequenceNumber(456) | ||
| .setPrimaryKey(pk) | ||
| .build(), | ||
| result), | ||
| timestamp, | ||
| receiver); | ||
| return outputs; | ||
| } | ||
|
|
||
| private IcebergScanConfig scanConfig(org.apache.iceberg.Schema icebergSchema) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Critical:
LocalResolveDoFnemits CDC records usingout.builder(row).setValueKind(kind).output(), and the tests assert onvalue.getValueKind()(viakindAndProjectedRow). However, the 4-argumentValueInSingleWindow.of(value, timestamp, window, paneInfo)overload hardcodesValueKind.INSERT, discardingwv.getValueKind(). As a result, all emitted records will haveValueKind.INSERTinstead ofUPDATE_BEFORE,UPDATE_AFTER, orDELETE, causing the tests in this class to fail.Use the 9-argument
ValueInSingleWindow.of(...)overload and passwv.getValueKind()(andwv.causedByDrain()). You can also remove the redundantoutputandoutputWithTimestampoverrides sinceOutputReceiveralready provides default methods that delegate tobuilder(...).