From 0fe6c96575a82b06949af34ef449aed5bc8efece Mon Sep 17 00:00:00 2001 From: alexradzin Date: Sun, 30 Jun 2024 08:48:31 +0300 Subject: [PATCH 1/2] better code reuse in callback --- .../arrow/datafusion/DefaultDataFrame.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/datafusion-java/src/main/java/org/apache/arrow/datafusion/DefaultDataFrame.java b/datafusion-java/src/main/java/org/apache/arrow/datafusion/DefaultDataFrame.java index b4d196a..0e055d1 100644 --- a/datafusion-java/src/main/java/org/apache/arrow/datafusion/DefaultDataFrame.java +++ b/datafusion-java/src/main/java/org/apache/arrow/datafusion/DefaultDataFrame.java @@ -2,6 +2,7 @@ import java.nio.file.Path; import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.vector.ipc.ArrowFileReader; import org.apache.arrow.vector.ipc.ArrowReader; @@ -69,13 +70,7 @@ public CompletableFuture show() { DataFrames.showDataframe( runtimePointer, dataframe, - (String errString) -> { - if (ErrorUtil.containsError(errString)) { - future.completeExceptionally(new RuntimeException(errString)); - } else { - future.complete(null); - } - }); + new RuntimeExceptionCallback(future)); return future; } @@ -89,13 +84,7 @@ public CompletableFuture writeParquet(Path path) { runtimePointer, dataframe, path.toAbsolutePath().toString(), - (String errString) -> { - if (ErrorUtil.containsError(errString)) { - future.completeExceptionally(new RuntimeException(errString)); - } else { - future.complete(null); - } - }); + new RuntimeExceptionCallback(future)); return future; } @@ -109,13 +98,7 @@ public CompletableFuture writeCsv(Path path) { runtimePointer, dataframe, path.toAbsolutePath().toString(), - (String errString) -> { - if (ErrorUtil.containsError(errString)) { - future.completeExceptionally(new RuntimeException(errString)); - } else { - future.complete(null); - } - }); + new RuntimeExceptionCallback(future)); return future; } @@ -130,4 +113,21 @@ public TableProvider intoView() { void doClose(long pointer) { DataFrames.destroyDataFrame(pointer); } + + private static class RuntimeExceptionCallback implements Consumer { + private final CompletableFuture future; + + private RuntimeExceptionCallback(CompletableFuture future) { + this.future = future; + } + + @Override + public void accept(String errString) { + if (ErrorUtil.containsError(errString)) { + future.completeExceptionally(new RuntimeException(errString)); + } else { + future.complete(null); + } + } + } } From b8f333d1e5829ea5edee64fc5fe4f667870894db Mon Sep 17 00:00:00 2001 From: alexradzin Date: Sun, 30 Jun 2024 18:09:12 +0300 Subject: [PATCH 2/2] fixed indentation --- .../arrow/datafusion/DefaultDataFrame.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/datafusion-java/src/main/java/org/apache/arrow/datafusion/DefaultDataFrame.java b/datafusion-java/src/main/java/org/apache/arrow/datafusion/DefaultDataFrame.java index 0e055d1..40b5789 100644 --- a/datafusion-java/src/main/java/org/apache/arrow/datafusion/DefaultDataFrame.java +++ b/datafusion-java/src/main/java/org/apache/arrow/datafusion/DefaultDataFrame.java @@ -114,20 +114,20 @@ void doClose(long pointer) { DataFrames.destroyDataFrame(pointer); } - private static class RuntimeExceptionCallback implements Consumer { - private final CompletableFuture future; + private static class RuntimeExceptionCallback implements Consumer { + private final CompletableFuture future; - private RuntimeExceptionCallback(CompletableFuture future) { - this.future = future; - } + private RuntimeExceptionCallback(CompletableFuture future) { + this.future = future; + } - @Override - public void accept(String errString) { - if (ErrorUtil.containsError(errString)) { - future.completeExceptionally(new RuntimeException(errString)); - } else { - future.complete(null); - } - } + @Override + public void accept(String errString) { + if (ErrorUtil.containsError(errString)) { + future.completeExceptionally(new RuntimeException(errString)); + } else { + future.complete(null); + } } + } }