You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2024/09/10 07:31:00 UTC
(arrow) branch main updated: GH-43996: [Java] Mark new allocated ArrowSchema as released (#43997)
This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new fed5fcbbd5 GH-43996: [Java] Mark new allocated ArrowSchema as released (#43997)
fed5fcbbd5 is described below
commit fed5fcbbd5f1ca578f2eb3661a8260b4e21965ea
Author: Liang-Chi Hsieh <vi...@gmail.com>
AuthorDate: Tue Sep 10 00:30:54 2024 -0700
GH-43996: [Java] Mark new allocated ArrowSchema as released (#43997)
### Rationale for this change
As described in #43996.
### What changes are included in this PR?
### Are these changes tested?
### Are there any user-facing changes?
* GitHub Issue: #43996
Authored-by: Liang-Chi Hsieh <vi...@gmail.com>
Signed-off-by: David Li <li...@gmail.com>
---
java/c/src/main/java/org/apache/arrow/c/ArrowSchema.java | 10 +++++++++-
.../test/java/org/apache/arrow/c/ArrowArrayUtilityTest.java | 7 +++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/java/c/src/main/java/org/apache/arrow/c/ArrowSchema.java b/java/c/src/main/java/org/apache/arrow/c/ArrowSchema.java
index 06e401627e..ad9f16ae9c 100644
--- a/java/c/src/main/java/org/apache/arrow/c/ArrowSchema.java
+++ b/java/c/src/main/java/org/apache/arrow/c/ArrowSchema.java
@@ -52,6 +52,7 @@ import org.apache.arrow.memory.util.MemoryUtil;
*/
public class ArrowSchema implements BaseStruct {
private static final int SIZE_OF = 72;
+ private static final int INDEX_RELEASE_CALLBACK = 56;
private ArrowBuf data;
@@ -103,7 +104,9 @@ public class ArrowSchema implements BaseStruct {
* @return A new ArrowSchema instance
*/
public static ArrowSchema allocateNew(BufferAllocator allocator) {
- return new ArrowSchema(allocator.buffer(ArrowSchema.SIZE_OF));
+ ArrowSchema schema = new ArrowSchema(allocator.buffer(ArrowSchema.SIZE_OF));
+ schema.markReleased();
+ return schema;
}
ArrowSchema(ArrowBuf data) {
@@ -111,6 +114,11 @@ public class ArrowSchema implements BaseStruct {
this.data = data;
}
+ /** Mark the schema as released. */
+ public void markReleased() {
+ directBuffer().putLong(INDEX_RELEASE_CALLBACK, NULL);
+ }
+
@Override
public long memoryAddress() {
checkNotNull(data, "ArrowSchema is already closed");
diff --git a/java/c/src/test/java/org/apache/arrow/c/ArrowArrayUtilityTest.java b/java/c/src/test/java/org/apache/arrow/c/ArrowArrayUtilityTest.java
index 1d4cb411fa..511358a5e6 100644
--- a/java/c/src/test/java/org/apache/arrow/c/ArrowArrayUtilityTest.java
+++ b/java/c/src/test/java/org/apache/arrow/c/ArrowArrayUtilityTest.java
@@ -50,6 +50,13 @@ class ArrowArrayUtilityTest {
allocator.close();
}
+ @Test
+ void arraySchemaInit() {
+ ArrowSchema schema = ArrowSchema.allocateNew(allocator);
+ assertThat(schema.snapshot().release).isEqualTo(0);
+ schema.close();
+ }
+
// ------------------------------------------------------------
// BufferImportTypeVisitor