Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
1 change: 1 addition & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ PostCommit Jobs run in a schedule against master branch and generally do not get
| [ PostCommit Java BigQueryEarlyRollout ](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_BigQueryEarlyRollout.yml) | N/A |`beam_PostCommit_Java_BigQueryEarlyRollout.json`| [![.github/workflows/beam_PostCommit_Java_BigQueryEarlyRollout.yml](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_BigQueryEarlyRollout.yml/badge.svg?event=schedule)](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_BigQueryEarlyRollout.yml?query=event%3Aschedule) |
| [ PostCommit Java Dataflow V1 ](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_DataflowV1.yml) | N/A |`beam_PostCommit_Java_DataflowV1.json`| [![.github/workflows/beam_PostCommit_Java_DataflowV1.yml](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_DataflowV1.yml/badge.svg?event=schedule)](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_DataflowV1.yml?query=event%3Aschedule) |
| [ PostCommit Java Dataflow V2 ](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_DataflowV2.yml) | N/A |`beam_PostCommit_Java_DataflowV2.json`| [![.github/workflows/beam_PostCommit_Java_DataflowV2.yml](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_DataflowV2.yml/badge.svg?event=schedule)](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_DataflowV2.yml?query=event%3Aschedule) |
| [ PostCommit Java Delta IO Dataflow ](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_Delta_IO_Dataflow.yml) | N/A |`beam_PostCommit_Java_Delta_IO_Dataflow.json`| [![.github/workflows/beam_PostCommit_Java_Delta_IO_Dataflow.yml](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_Delta_IO_Dataflow.yml/badge.svg?event=schedule)](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_Delta_IO_Dataflow.yml?query=event%3Aschedule) |
| [ PostCommit Java Examples Dataflow ARM ](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_Examples_Dataflow_ARM.yml) | ['8','11','17','21','25'] |`beam_PostCommit_Java_Examples_Dataflow_ARM.json`| [![.github/workflows/beam_PostCommit_Java_Examples_Dataflow_ARM.yml](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_Examples_Dataflow_ARM.yml/badge.svg?event=schedule)](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_Examples_Dataflow_ARM.yml?query=event%3Aschedule) |
| [ PostCommit Java Examples Dataflow](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_Examples_Dataflow.yml) | N/A |`beam_PostCommit_Java_Examples_Dataflow.json`| [![.github/workflows/beam_PostCommit_Java_Examples_Dataflow.yml](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_Examples_Dataflow.yml/badge.svg?event=schedule)](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_Examples_Dataflow.yml?query=event%3Aschedule) |
| [ PostCommit Java Examples Dataflow Java ](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_Examples_Dataflow_Java.yml) | ['8','17','21','25'] |`beam_PostCommit_Java_Examples_Dataflow_Java.json`| [![.github/workflows/beam_PostCommit_Java_Examples_Dataflow_Java.yml](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_Examples_Dataflow_Java.yml/badge.svg?event=schedule)](https://github.com/apache/beam/actions/workflows/beam_PostCommit_Java_Examples_Dataflow_Java.yml?query=event%3Aschedule) |
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/beam_PostCommit_Java_Delta_IO_Dataflow.yml
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
38 changes: 38 additions & 0 deletions sdks/java/io/delta/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* limitations under the License.
*/

import groovy.json.JsonOutput

plugins { id 'org.apache.beam.module' }
applyJavaNature(
automaticModuleName: 'org.apache.beam.sdk.io.delta',
Expand Down Expand Up @@ -68,6 +70,10 @@ dependencies {
testImplementation project(":sdks:java:managed")
testRuntimeOnly "org.yaml:snakeyaml:2.0"
testImplementation project(path: ":runners:direct-java", configuration: "shadow")
testImplementation project(":sdks:java:io:google-cloud-platform")
testImplementation project(":sdks:java:extensions:google-cloud-platform-core")
testImplementation library.java.google_cloud_storage
testRuntimeOnly project(path: ":runners:google-cloud-dataflow-java")
}

configurations.all {
Expand All @@ -82,3 +88,35 @@ configurations.all {
resolutionStrategy.force "com.google.cloud.bigdataoss:gcsio:$bigdataoss_gcs_connector_version"
resolutionStrategy.force "com.google.cloud.bigdataoss:util:$bigdataoss_gcs_connector_version"
}

def gcpProject = project.findProperty('gcpProject') ?: 'apache-beam-testing'
def gcpTempLocation = project.findProperty('gcpTempLocation') ?: 'gs://apache-beam-testing-delta-lake/temp'

// Used by Dataflow integration tests.
task dataflowIntegrationTest(type: Test) {
group = "Verification"
evaluationDependsOn(":runners:google-cloud-dataflow-java")
dependsOn ":runners:google-cloud-dataflow-java:buildAndPushDockerJavaContainer"
finalizedBy ":runners:google-cloud-dataflow-java:cleanUpDockerJavaImages"
def dockerJavaImageName = project.project(':runners:google-cloud-dataflow-java').ext.dockerJavaImageName

def args = [
"--runner=DataflowRunner",
"--region=us-central1",
"--project=${gcpProject}",
"--tempLocation=${gcpTempLocation}",
"--tempRoot=${gcpTempLocation}",
"--sdkContainerImage=${dockerJavaImageName}",
"--experiments=use_runner_v2,use_staged_dataflow_worker_jar"
]
systemProperty "beamTestPipelineOptions", JsonOutput.toJson(args)

// Disable Gradle cache: these ITs interact with live service that should always be considered "out of date"
outputs.upToDateWhen { false }

include '**/*IT.class'

maxParallelForks 4
classpath = sourceSets.test.runtimeClasspath
testClassesDirs = sourceSets.test.output.classesDirs
}
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);
Comment thread
chamikaramj marked this conversation as resolved.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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);
}
}
Comment thread
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 =
Comment thread
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();
}
}
Loading