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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
## I/Os

* Support for X source added (Java/Python) ([#X](https://github.com/apache/beam/issues/X)).
* Add ArrowFlight IO (Java) ([#20116](https://github.com/apache/beam/issues/20116)).
* IcebergIO: support declaring a table's sort order on dynamic table creation via the new `sort_fields` config ([#38269](https://github.com/apache/beam/issues/38269)).
* IcebergIO: support writing with hash distribution mode, and with autosharding ([#38061](https://github.com/apache/beam/issues/38061))).

Expand Down Expand Up @@ -112,6 +113,7 @@

## I/Os


* DebeziumIO (Java): added `OffsetRetainer` interface and `FileSystemOffsetRetainer` implementation to persist and restore CDC offsets across pipeline restarts, and exposed `withStartOffset` / `withOffsetRetainer` on `DebeziumIO.Read` and the cross-language `ReadBuilder` ([#28248](https://github.com/apache/beam/issues/28248)).

## New Features / Improvements
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ tasks.register("javaPreCommit") {
// a precommit task build multiple IOs (except those splitting into single jobs)
tasks.register("javaioPreCommit") {
dependsOn(":sdks:java:io:amqp:build")
dependsOn(":sdks:java:io:arrow-flight:build")
dependsOn(":sdks:java:io:cassandra:build")
dependsOn(":sdks:java:io:csv:build")
dependsOn(":sdks:java:io:cdap:build")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,8 @@ class BeamModulePlugin implements Plugin<Project> {
arrow_vector : "org.apache.arrow:arrow-vector:$arrow_version",
arrow_memory_core : "org.apache.arrow:arrow-memory-core:$arrow_version",
arrow_memory_netty : "org.apache.arrow:arrow-memory-netty:$arrow_version",
arrow_flight_core : "org.apache.arrow:flight-core:$arrow_version",
arrow_flight_sql : "org.apache.arrow:flight-sql:$arrow_version",
],
groovy: [
groovy_all: "org.codehaus.groovy:groovy-all:2.4.13",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -263,10 +264,24 @@ public void testWriteBatchesWithTimeout() {

p.run().waitUntilFinish();

SendMessageBatchRequestEntry[] entries = entries(range(0, 5));
// due to added delay, batches are timed out on arrival of every 3rd msg
verify(sqs).sendMessageBatch(request("queue", entries[0], entries[1], entries[2]));
verify(sqs).sendMessageBatch(request("queue", entries[3], entries[4]));
ArgumentCaptor<SendMessageBatchRequest> captor =
ArgumentCaptor.forClass(SendMessageBatchRequest.class);
verify(sqs, atLeastOnce()).sendMessageBatch(captor.capture());

List<SendMessageBatchRequest> requests = captor.getAllValues();
// This timeout path checks expiration only when new records arrive, so slower CI can shift the
// split points. What should remain stable is that the timeout forces multiple batches while
// preserving every message exactly once.
assertThat(requests.size()).isBetween(2, 3);
assertThat(flattenEntries(requests))
.extracting(SendMessageBatchRequestEntry::messageBody)
.containsExactly("0", "1", "2", "3", "4");
assertThat(requests)
.allSatisfy(
req -> {
assertThat(req.queueUrl()).isEqualTo("queue");
assertThat(req.entries().size()).isBetween(1, 3);
});
}

@Test
Expand Down Expand Up @@ -337,11 +352,17 @@ public void testWriteBatchesToDynamicWithTimeout() {

p.run().waitUntilFinish();

SendMessageBatchRequestEntry[] entries = entries(range(0, 5));
// due to added delay, dynamic batches are timed out on arrival of every 2nd msg (per batch)
verify(sqs).sendMessageBatch(request("even", entries[0], entries[2]));
verify(sqs).sendMessageBatch(request("uneven", entries[1], entries[3]));
verify(sqs).sendMessageBatch(request("even", entries[4]));
ArgumentCaptor<SendMessageBatchRequest> captor =
ArgumentCaptor.forClass(SendMessageBatchRequest.class);
verify(sqs, atLeastOnce()).sendMessageBatch(captor.capture());

List<SendMessageBatchRequest> requests = captor.getAllValues();
// Non-strict timeout checks may submit an expired batch either when its next record arrives or
// during a synchronous expiration scan triggered by another queue, so CI timing can vary.
assertThat(requests.size()).isBetween(3, 5);
assertThat(messagesForQueue(requests, "even")).containsExactly("0", "2", "4");
assertThat(messagesForQueue(requests, "uneven")).containsExactly("1", "3");
assertThat(requests).allSatisfy(req -> assertThat(req.entries().size()).isBetween(1, 2));
}

@Test
Expand Down Expand Up @@ -406,6 +427,19 @@ private SendMessageBatchRequest anyRequest() {
return any();
}

private List<SendMessageBatchRequestEntry> flattenEntries(
List<SendMessageBatchRequest> requests) {
return requests.stream().flatMap(req -> req.entries().stream()).collect(toList());
}

private List<String> messagesForQueue(List<SendMessageBatchRequest> requests, String queue) {
return requests.stream()
.filter(req -> queue.equals(req.queueUrl()))
.flatMap(req -> req.entries().stream())
.map(SendMessageBatchRequestEntry::messageBody)
.collect(toList());
}

private SendMessageBatchRequest request(String queue, SendMessageBatchRequestEntry... entries) {
return SendMessageBatchRequest.builder()
.queueUrl(queue)
Expand Down
43 changes: 43 additions & 0 deletions sdks/java/io/arrow-flight/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.
*/

plugins { id 'org.apache.beam.module' }
applyJavaNature(automaticModuleName: 'org.apache.beam.sdk.io.arrowflight')

description = "Apache Beam :: SDKs :: Java :: IO :: Arrow Flight"
ext.summary = "IO to read and write data using Apache Arrow Flight RPC."

dependencies {
implementation project(path: ":sdks:java:core", configuration: "shadow")
implementation project(path: ":sdks:java:extensions:arrow")
implementation library.java.joda_time
implementation library.java.slf4j_api
implementation library.java.vendored_guava_32_1_2_jre
implementation(library.java.arrow_flight_core)
implementation(library.java.arrow_memory_core)
implementation(library.java.arrow_vector)
testImplementation library.java.hamcrest
testImplementation library.java.junit
testImplementation(library.java.arrow_memory_netty)
testRuntimeOnly library.java.slf4j_simple
testRuntimeOnly project(path: ":runners:direct-java", configuration: "shadow")
}

test {
jvmArgs '--add-opens=java.base/java.nio=ALL-UNNAMED'
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.

I understsnd add-opens are needed:

Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.RuntimeException: Failed to initialize MemoryUtil. You must start Java with `--add-opens=java.base/java.nio=org.apache.arrow.memory.core,ALL-UNNAMED` (See https://arrow.apache.org/docs/java/install.html) [in thread "direct-runner-worker"]
	at org.apache.arrow.memory.util.MemoryUtil.<clinit>(MemoryUtil.java:140)

this means using ArrowFlightIO one needs to set --JdkAddOpenModules=java.base/java.nio=ALL-UNNAMED pipeline options in Java17+. We should note this here and in ArrowFlightIO Javadoc

Also, Java8 runtime doesn't recognize '--add-opens' pipeline options. However we'll soon remove Java8 support so it's fine here.

}
Loading
Loading