Skip to content

Commit b6aaf42

Browse files
authored
Initial skeleton for the Delta Lake source (#38571)
1 parent 0c9b272 commit b6aaf42

6 files changed

Lines changed: 219 additions & 0 deletions

File tree

buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ class BeamModulePlugin implements Plugin<Project> {
605605
def cdap_version = "6.5.1"
606606
def checkerframework_version = "3.42.0"
607607
def classgraph_version = "4.8.162"
608+
def delta_lake_version = "4.2.0"
608609
def dbcp2_version = "2.9.0"
609610
def errorprone_version = "2.31.0"
610611
// [bomupgrader] determined by: com.google.api:gax, consistent with: google_cloud_platform_libraries_bom
@@ -729,6 +730,8 @@ class BeamModulePlugin implements Plugin<Project> {
729730
commons_logging : "commons-logging:commons-logging:1.2",
730731
commons_math3 : "org.apache.commons:commons-math3:3.6.1",
731732
dbcp2 : "org.apache.commons:commons-dbcp2:$dbcp2_version",
733+
delta_kernel_api : "io.delta:delta-kernel-api:$delta_lake_version",
734+
delta_kernel_defaults : "io.delta:delta-kernel-defaults:$delta_lake_version",
732735
envoy_control_plane_api : "io.envoyproxy.controlplane:api:1.0.49",
733736
error_prone_annotations : "com.google.errorprone:error_prone_annotations:$errorprone_version",
734737
failsafe : "dev.failsafe:failsafe:3.3.0",

sdks/java/io/delta/build.gradle

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
plugins { id 'org.apache.beam.module' }
20+
applyJavaNature(
21+
automaticModuleName: 'org.apache.beam.sdk.io.delta',
22+
// Latest version of the Delta Kernel API requires Java 17.
23+
requireJavaVersion: JavaVersion.VERSION_17,
24+
)
25+
26+
description = "Apache Beam :: SDKs :: Java :: IO :: Delta Lake"
27+
ext.summary = "Integration with Delta Lake."
28+
29+
30+
dependencies {
31+
implementation project(path: ":sdks:java:core", configuration: "shadow")
32+
implementation library.java.delta_kernel_api
33+
implementation library.java.delta_kernel_defaults
34+
35+
permitUnusedDeclared library.java.delta_kernel_api
36+
permitUnusedDeclared library.java.delta_kernel_defaults
37+
38+
testImplementation library.java.junit
39+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.beam.sdk.io.delta;
19+
20+
import com.google.auto.value.AutoValue;
21+
import java.util.Map;
22+
import org.apache.beam.sdk.annotations.Internal;
23+
import org.apache.beam.sdk.transforms.PTransform;
24+
import org.apache.beam.sdk.values.PBegin;
25+
import org.apache.beam.sdk.values.PCollection;
26+
import org.apache.beam.sdk.values.Row;
27+
import org.checkerframework.checker.nullness.qual.Nullable;
28+
29+
/**
30+
* A connector that reads from <a href="https://delta.io/">Delta Lake</a> tables.
31+
*
32+
* <p>This is work in progress. For more details and to track progress, please see <a
33+
* href="https://github.com/apache/beam/issues/21100">Issue 21100</a>.
34+
*/
35+
@Internal
36+
public class DeltaIO {
37+
38+
public static ReadRows readRows() {
39+
return new AutoValue_DeltaIO_ReadRows.Builder().build();
40+
}
41+
42+
@AutoValue
43+
public abstract static class ReadRows extends PTransform<PBegin, PCollection<Row>> {
44+
45+
public abstract @Nullable String getTablePath();
46+
47+
public abstract @Nullable Long getVersion();
48+
49+
public abstract @Nullable String getTimestamp();
50+
51+
public abstract @Nullable Map<String, String> getHadoopConfig();
52+
53+
abstract Builder toBuilder();
54+
55+
@AutoValue.Builder
56+
abstract static class Builder {
57+
abstract Builder setTablePath(String tablePath);
58+
59+
abstract Builder setVersion(@Nullable Long version);
60+
61+
abstract Builder setTimestamp(@Nullable String timestamp);
62+
63+
abstract Builder setHadoopConfig(@Nullable Map<String, String> hadoopConfig);
64+
65+
abstract ReadRows build();
66+
}
67+
68+
public ReadRows from(String tablePath) {
69+
return toBuilder().setTablePath(tablePath).build();
70+
}
71+
72+
public ReadRows withVersion(@Nullable Long version) {
73+
return toBuilder().setVersion(version).build();
74+
}
75+
76+
public ReadRows withTimestamp(@Nullable String timestamp) {
77+
return toBuilder().setTimestamp(timestamp).build();
78+
}
79+
80+
public ReadRows withConfig(Map<String, String> config) {
81+
return toBuilder().setHadoopConfig(config).build();
82+
}
83+
84+
@Override
85+
public PCollection<Row> expand(PBegin input) {
86+
// TODO(https://github.com/apache/beam/issues/38551): Implement expansion for
87+
// Delta Lake ReadRows
88+
throw new UnsupportedOperationException("Not implemented yet.");
89+
}
90+
}
91+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* Transforms for reading from Delta Lake.
21+
*
22+
* @see org.apache.beam.sdk.io.delta.DeltaIO
23+
*/
24+
package org.apache.beam.sdk.io.delta;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.beam.sdk.io.delta;
19+
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
import org.apache.beam.sdk.io.delta.DeltaIO.ReadRows;
23+
import org.junit.Assert;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.junit.runners.JUnit4;
27+
28+
/** Unit tests for the {@link DeltaIO}. */
29+
@RunWith(JUnit4.class)
30+
public class DeltaIOTest {
31+
32+
@Test
33+
public void testReadRowsBuilderAndGetters() {
34+
String tablePath = "/path/to/table";
35+
long version = 5L;
36+
String timestamp = "2026-05-20T15:43:26Z";
37+
Map<String, String> hadoopConfig = new HashMap<>();
38+
hadoopConfig.put("fs.defaultFS", "file:///");
39+
40+
ReadRows readRows = DeltaIO.readRows()
41+
.from(tablePath)
42+
.withVersion(version)
43+
.withTimestamp(timestamp)
44+
.withConfig(hadoopConfig);
45+
46+
Assert.assertEquals(tablePath, readRows.getTablePath());
47+
Assert.assertEquals(Long.valueOf(version), readRows.getVersion());
48+
Assert.assertEquals(timestamp, readRows.getTimestamp());
49+
Assert.assertEquals(hadoopConfig, readRows.getHadoopConfig());
50+
}
51+
52+
@Test
53+
public void testReadRowsNullDefaults() {
54+
ReadRows readRows = DeltaIO.readRows();
55+
56+
Assert.assertNull(readRows.getTablePath());
57+
Assert.assertNull(readRows.getVersion());
58+
Assert.assertNull(readRows.getTimestamp());
59+
Assert.assertNull(readRows.getHadoopConfig());
60+
}
61+
}

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ include(":sdks:java:io:file-based-io-tests")
226226
include(":sdks:java:io:bigquery-io-perf-tests")
227227
include(":sdks:java:io:cdap")
228228
include(":sdks:java:io:csv")
229+
include(":sdks:java:io:delta")
229230
include(":sdks:java:io:datadog")
230231
include(":sdks:java:io:file-schema-transform")
231232
include(":sdks:java:io:google-ads")

0 commit comments

Comments
 (0)