-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Adds a Dataflow integration test suite for Delta Lake #38954
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
Open
chamikaramj
wants to merge
4
commits into
apache:master
Choose a base branch
from
chamikaramj:delta_lake_it
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
.github/trigger_files/beam_PostCommit_Java_Delta_IO_Dataflow.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "comment": "Modify this file in a trivial way to cause this test suite to run.", | ||
| "modification": 1 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
.github/workflows/beam_PostCommit_Java_Delta_IO_Dataflow.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # 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. | ||
|
|
||
| name: PostCommit Java Delta IO Dataflow | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '30 4/6 * * *' | ||
| pull_request_target: | ||
| paths: [ 'release/trigger_all_tests.json', '.github/trigger_files/beam_PostCommit_Java_Delta_IO_Dataflow.json' ] | ||
| workflow_dispatch: | ||
|
|
||
| # Setting explicit permissions for the action to avoid the default permissions which are `write-all` in case of pull_request_target event | ||
| permissions: | ||
| actions: write | ||
| pull-requests: write | ||
| checks: write | ||
| contents: read | ||
| deployments: read | ||
| id-token: none | ||
| issues: write | ||
| discussions: read | ||
| packages: read | ||
| pages: read | ||
| repository-projects: read | ||
| security-events: read | ||
| statuses: read | ||
|
|
||
| # This allows a subsequently queued workflow run to interrupt previous runs | ||
| concurrency: | ||
| group: '${{ github.workflow }} @ ${{ github.event.pull_request.number || github.sha || github.head_ref || github.ref }}-${{ github.event.schedule || github.event.comment.id || github.event.sender.login }}' | ||
| cancel-in-progress: true | ||
|
|
||
| env: | ||
| DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }} | ||
| GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GE_CACHE_USERNAME }} | ||
| GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GE_CACHE_PASSWORD }} | ||
|
|
||
| jobs: | ||
| beam_PostCommit_Java_Delta_IO_Dataflow: | ||
| if: | | ||
| github.event_name == 'pull_request_target' || | ||
| github.event_name == 'workflow_dispatch' || | ||
| (github.event_name == 'schedule' && github.repository == 'apache/beam') || | ||
| github.event.comment.body == 'Run PostCommit Java Delta IO Dataflow' | ||
| runs-on: [self-hosted, ubuntu-24.04, main] | ||
| timeout-minutes: 120 | ||
| name: ${{ matrix.job_name }} (${{ matrix.job_phrase }}) | ||
| strategy: | ||
| matrix: | ||
| job_name: ["beam_PostCommit_Java_Delta_IO_Dataflow"] | ||
| job_phrase: ["Run PostCommit Java Delta IO Dataflow"] | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Setup repository | ||
| uses: ./.github/actions/setup-action | ||
| with: | ||
| comment_phrase: ${{ matrix.job_phrase }} | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| github_job: ${{ matrix.job_name }} (${{ matrix.job_phrase }}) | ||
| - name: Setup environment | ||
| uses: ./.github/actions/setup-environment-action | ||
| - name: Run PostCommit Java Delta IO Dataflow | ||
| uses: ./.github/actions/gradle-command-self-hosted-action | ||
| with: | ||
| gradle-command: :sdks:java:io:delta:dataflowIntegrationTest --info |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
sdks/java/io/delta/src/test/java/org/apache/beam/sdk/io/delta/DeltaIOIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| /* | ||
| * 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.delta; | ||
|
|
||
| import static org.junit.Assert.assertNotNull; | ||
|
|
||
| import com.google.cloud.storage.Blob; | ||
| import com.google.cloud.storage.BlobId; | ||
| import com.google.cloud.storage.BlobInfo; | ||
| import com.google.cloud.storage.Storage; | ||
| import com.google.cloud.storage.StorageOptions; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
| import org.apache.avro.generic.GenericRecord; | ||
| import org.apache.beam.runners.direct.DirectOptions; | ||
| import org.apache.beam.runners.direct.DirectRunner; | ||
| import org.apache.beam.sdk.Pipeline; | ||
| import org.apache.beam.sdk.extensions.avro.coders.AvroCoder; | ||
| import org.apache.beam.sdk.extensions.avro.schemas.utils.AvroUtils; | ||
| import org.apache.beam.sdk.io.Compression; | ||
| import org.apache.beam.sdk.io.FileIO; | ||
| import org.apache.beam.sdk.io.parquet.ParquetIO; | ||
| import org.apache.beam.sdk.managed.Managed; | ||
| import org.apache.beam.sdk.options.PipelineOptionsFactory; | ||
| import org.apache.beam.sdk.schemas.Schema; | ||
| import org.apache.beam.sdk.testing.PAssert; | ||
| import org.apache.beam.sdk.testing.TestPipeline; | ||
| import org.apache.beam.sdk.transforms.Create; | ||
| import org.apache.beam.sdk.transforms.MapElements; | ||
| import org.apache.beam.sdk.transforms.windowing.BoundedWindow; | ||
| import org.apache.beam.sdk.transforms.windowing.PaneInfo; | ||
| import org.apache.beam.sdk.values.PCollection; | ||
| import org.apache.beam.sdk.values.Row; | ||
| import org.apache.beam.sdk.values.TypeDescriptor; | ||
| import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TestName; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** Integration tests for {@link DeltaIO}. */ | ||
| @RunWith(JUnit4.class) | ||
| public class DeltaIOIT { | ||
| private static final Logger LOG = LoggerFactory.getLogger(DeltaIOIT.class); | ||
|
|
||
| private static final String DEFAULT_BUCKET = "apache-beam-testing-delta-lake"; | ||
| @Rule public final TestPipeline readPipeline = TestPipeline.create(); | ||
| @Rule public final TestName testName = new TestName(); | ||
|
|
||
| private String bucket; | ||
| private String repoPath; | ||
| private String repoPrefix; | ||
| private Storage storage; | ||
|
|
||
| private static final Schema ROW_SCHEMA = | ||
| Schema.builder().addInt32Field("id").addStringField("name").build(); | ||
|
|
||
| private static final List<Row> TEST_ROWS = | ||
| IntStream.range(0, 100) | ||
| .mapToObj(i -> Row.withSchema(ROW_SCHEMA).addValues(i, "name_" + i).build()) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| @Before | ||
| public void setup() throws Exception { | ||
| storage = StorageOptions.newBuilder().build().getService(); | ||
| long salt = System.currentTimeMillis(); | ||
|
|
||
| String tempLocation = readPipeline.getOptions().getTempLocation(); | ||
| if (tempLocation != null && tempLocation.startsWith("gs://")) { | ||
| org.apache.beam.sdk.extensions.gcp.util.gcsfs.GcsPath gcsPath = org.apache.beam.sdk.extensions.gcp.util.gcsfs.GcsPath | ||
| .fromUri(tempLocation); | ||
| bucket = gcsPath.getBucket(); | ||
| repoPrefix = gcsPath.getObject() + "/delta_io_it/" + testName.getMethodName() + "-" + salt; | ||
| } else { | ||
| bucket = DEFAULT_BUCKET; | ||
| repoPrefix = "delta_io_it/" + testName.getMethodName() + "-" + salt; | ||
| } | ||
| repoPath = "gs://" + bucket + "/" + repoPrefix; | ||
|
|
||
| LOG.info("Generating Delta Lake repository at {}", repoPath); | ||
|
|
||
| // 1. Write Parquet file using a direct local pipeline | ||
| DirectOptions setupOptions = PipelineOptionsFactory.as(DirectOptions.class); | ||
| setupOptions.setRunner(DirectRunner.class); | ||
| setupOptions.setBlockOnRun(true); | ||
| Pipeline setupPipeline = Pipeline.create(setupOptions); | ||
|
|
||
| org.apache.avro.Schema avroSchema = AvroUtils.toAvroSchema(ROW_SCHEMA); | ||
| setupPipeline | ||
| .apply(Create.of(TEST_ROWS).withRowSchema(ROW_SCHEMA)) | ||
| .apply( | ||
| MapElements.into(TypeDescriptor.of(GenericRecord.class)) | ||
| .via(AvroUtils.getRowToGenericRecordFunction(avroSchema))) | ||
| .setCoder(AvroCoder.of(avroSchema)) | ||
| .apply( | ||
| FileIO.<GenericRecord>write() | ||
| .via(ParquetIO.sink(avroSchema)) | ||
| .to(repoPath + "/") | ||
| .withNaming( | ||
| (BoundedWindow window, | ||
| PaneInfo paneInfo, | ||
| int numShards, | ||
| int shardIndex, | ||
| Compression compression) -> "part-00000.parquet")); | ||
| setupPipeline.run().waitUntilFinish(); | ||
|
|
||
| // 2. Find written Parquet file to inspect its size | ||
| BlobId parquetBlobId = BlobId.of(bucket, repoPrefix + "/part-00000.parquet"); | ||
| Blob parquetBlob = storage.get(parquetBlobId); | ||
| assertNotNull("Parquet file not found on GCS: " + parquetBlobId, parquetBlob); | ||
| long fileSize = parquetBlob.getSize(); | ||
|
|
||
| // 3. Create the Delta log commit file | ||
| String commitContent = | ||
| "{\"protocol\":{\"minReaderVersion\":1,\"minWriterVersion\":2}}\n" | ||
| + "{\"metaData\":{\"id\":\"" | ||
| + salt | ||
| + "\",\"format\":{\"provider\":\"parquet\",\"options\":{}},\"schemaString\":\"{\\\"type\\\":\\\"struct\\\",\\\"fields\\\":[{\\\"name\\\":\\\"id\\\",\\\"type\\\":\\\"integer\\\",\\\"nullable\\\":true,\\\"metadata\\\":{}},{\\\"name\\\":\\\"name\\\",\\\"type\\\":\\\"string\\\",\\\"nullable\\\":true,\\\"metadata\\\":{}}]}\",\"partitionColumns\":[],\"configuration\":{},\"createdAt\":123456789}}\n" | ||
| + "{\"add\":{\"path\":\"part-00000.parquet\",\"partitionValues\":{},\"size\":" | ||
| + fileSize | ||
| + ",\"modificationTime\":123456789,\"dataChange\":true}}"; | ||
|
Comment on lines
+137
to
+145
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. Handwriting the metadata file feels brittle. Can we use the Delta Kernel API to commit the Parquet file instead? Better to test on metadata that's generated using the same API we're testing |
||
|
|
||
| BlobId commitBlobId = BlobId.of(bucket, repoPrefix + "/_delta_log/00000000000000000000.json"); | ||
| BlobInfo commitBlobInfo = | ||
| BlobInfo.newBuilder(commitBlobId).setContentType("application/json").build(); | ||
| storage.create(commitBlobInfo, commitContent.getBytes(StandardCharsets.UTF_8)); | ||
| LOG.info("Successfully generated Delta Lake repository"); | ||
| } | ||
|
|
||
| @After | ||
| public void teardown() { | ||
| if (storage == null) { | ||
| return; | ||
| } | ||
| LOG.info("Cleaning up Delta Lake repository at {}", repoPath); | ||
| try { | ||
| Iterable<Blob> blobs = | ||
| storage.list(bucket, Storage.BlobListOption.prefix(repoPrefix)).getValues(); | ||
| blobs.forEach(b -> storage.delete(b.getBlobId())); | ||
| } catch (Exception e) { | ||
| LOG.warn("Failed to clean up GCS repository at {}", repoPath, e); | ||
| } | ||
| } | ||
|
chamikaramj marked this conversation as resolved.
|
||
|
|
||
| @Test | ||
| public void testReadDeltaLakeTable() { | ||
| Map<String, String> hadoopConfig = new HashMap<>(); | ||
| hadoopConfig.put("fs.gs.impl", "com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem"); | ||
| hadoopConfig.put( | ||
| "fs.AbstractFileSystem.gs.impl", "com.google.cloud.hadoop.fs.gcs.GoogleHadoopFS"); | ||
| String project = readPipeline | ||
| .getOptions() | ||
| .as(org.apache.beam.sdk.extensions.gcp.options.GcpOptions.class) | ||
| .getProject(); | ||
| if (project != null) { | ||
| hadoopConfig.put("fs.gs.project.id", project); | ||
| } | ||
|
|
||
| PCollection<Row> output = | ||
|
chamikaramj marked this conversation as resolved.
|
||
| readPipeline | ||
| .apply( | ||
| Managed.read(Managed.DELTA_LAKE) | ||
| .withConfig(ImmutableMap.of("table", repoPath, "hadoop_config", hadoopConfig))) | ||
| .getSinglePCollection(); | ||
|
|
||
| PAssert.that(output).containsInAnyOrder(TEST_ROWS); | ||
| readPipeline.run().waitUntilFinish(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.