Skip to content

Commit 5101a5d

Browse files
committed
Updates
1 parent 098cec7 commit 5101a5d

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

  • sdks/java/io/delta/src/test/java/org/apache/beam/sdk/io/delta

sdks/java/io/delta/src/test/java/org/apache/beam/sdk/io/delta/DeltaIOIT.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@
6767
public class DeltaIOIT {
6868
private static final Logger LOG = LoggerFactory.getLogger(DeltaIOIT.class);
6969

70-
private static final String BUCKET = "apache-beam-testing-delta-lake";
71-
70+
private static final String DEFAULT_BUCKET = "apache-beam-testing-delta-lake";
7271
@Rule public final TestPipeline readPipeline = TestPipeline.create();
7372
@Rule public final TestName testName = new TestName();
7473

74+
private String bucket;
7575
private String repoPath;
7676
private String repoPrefix;
7777
private Storage storage;
@@ -88,8 +88,18 @@ public class DeltaIOIT {
8888
public void setup() throws Exception {
8989
storage = StorageOptions.newBuilder().build().getService();
9090
long salt = System.currentTimeMillis();
91-
repoPrefix = "delta_io_it/" + testName.getMethodName() + "-" + salt;
92-
repoPath = "gs://" + BUCKET + "/" + repoPrefix;
91+
92+
String tempLocation = readPipeline.getOptions().getTempLocation();
93+
if (tempLocation != null && tempLocation.startsWith("gs://")) {
94+
org.apache.beam.sdk.extensions.gcp.util.gcs.GcsPath gcsPath = org.apache.beam.sdk.extensions.gcp.util.gcs.GcsPath
95+
.fromUri(tempLocation);
96+
bucket = gcsPath.getBucket();
97+
repoPrefix = gcsPath.getObject() + "/delta_io_it/" + testName.getMethodName() + "-" + salt;
98+
} else {
99+
bucket = DEFAULT_BUCKET;
100+
repoPrefix = "delta_io_it/" + testName.getMethodName() + "-" + salt;
101+
}
102+
repoPath = "gs://" + bucket + "/" + repoPrefix;
93103

94104
LOG.info("Generating Delta Lake repository at {}", repoPath);
95105

@@ -119,7 +129,7 @@ public void setup() throws Exception {
119129
setupPipeline.run().waitUntilFinish();
120130

121131
// 2. Find written Parquet file to inspect its size
122-
BlobId parquetBlobId = BlobId.of(BUCKET, repoPrefix + "/part-00000.parquet");
132+
BlobId parquetBlobId = BlobId.of(bucket, repoPrefix + "/part-00000.parquet");
123133
Blob parquetBlob = storage.get(parquetBlobId);
124134
assertNotNull("Parquet file not found on GCS: " + parquetBlobId, parquetBlob);
125135
long fileSize = parquetBlob.getSize();
@@ -134,7 +144,7 @@ public void setup() throws Exception {
134144
+ fileSize
135145
+ ",\"modificationTime\":123456789,\"dataChange\":true}}";
136146

137-
BlobId commitBlobId = BlobId.of(BUCKET, repoPrefix + "/_delta_log/00000000000000000000.json");
147+
BlobId commitBlobId = BlobId.of(bucket, repoPrefix + "/_delta_log/00000000000000000000.json");
138148
BlobInfo commitBlobInfo =
139149
BlobInfo.newBuilder(commitBlobId).setContentType("application/json").build();
140150
storage.create(commitBlobInfo, commitContent.getBytes(StandardCharsets.UTF_8));
@@ -143,12 +153,14 @@ public void setup() throws Exception {
143153

144154
@After
145155
public void teardown() {
156+
if (storage == null) {
157+
return;
158+
}
146159
LOG.info("Cleaning up Delta Lake repository at {}", repoPath);
147160
try {
148-
Iterable<Blob> blobs =
149-
storage.list(BUCKET, Storage.BlobListOption.prefix(repoPrefix)).getValues();
161+
Iterable<Blob> blobs =
162+
storage.list(bucket, Storage.BlobListOption.prefix(repoPrefix)).getValues();
150163
blobs.forEach(b -> storage.delete(b.getBlobId()));
151-
storage.close();
152164
} catch (Exception e) {
153165
LOG.warn("Failed to clean up GCS repository at {}", repoPath, e);
154166
}
@@ -160,6 +172,11 @@ public void testReadDeltaLakeTable() {
160172
hadoopConfig.put("fs.gs.impl", "com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem");
161173
hadoopConfig.put(
162174
"fs.AbstractFileSystem.gs.impl", "com.google.cloud.hadoop.fs.gcs.GoogleHadoopFS");
175+
String project = readPipeline.getOptions().as(org.apache.beam.sdk.extensions.gcp.options.GcpOptions.class)
176+
.getProject();
177+
if (project != null) {
178+
hadoopConfig.put("fs.gs.project.id", project);
179+
}
163180

164181
PCollection<Row> output =
165182
readPipeline

0 commit comments

Comments
 (0)