Skip to content

Commit

Permalink
apacheGH-43996: [Java] Mark new allocated ArrowSchema as released (ap…
Browse files Browse the repository at this point in the history
…ache#43997)

### Rationale for this change

As described in apache#43996.

### What changes are included in this PR?

### Are these changes tested?

### Are there any user-facing changes?

* GitHub Issue: apache#43996

Authored-by: Liang-Chi Hsieh <[email protected]>
Signed-off-by: David Li <[email protected]>
  • Loading branch information
viirya authored Sep 10, 2024
1 parent b6316c0 commit fed5fcb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion java/c/src/main/java/org/apache/arrow/c/ArrowSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
*/
public class ArrowSchema implements BaseStruct {
private static final int SIZE_OF = 72;
private static final int INDEX_RELEASE_CALLBACK = 56;

private ArrowBuf data;

Expand Down Expand Up @@ -103,14 +104,21 @@ public static ArrowSchema wrap(long memoryAddress) {
* @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) {
checkNotNull(data, "ArrowSchema initialized with a null buffer");
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ void afterEach() {
allocator.close();
}

@Test
void arraySchemaInit() {
ArrowSchema schema = ArrowSchema.allocateNew(allocator);
assertThat(schema.snapshot().release).isEqualTo(0);
schema.close();
}

// ------------------------------------------------------------
// BufferImportTypeVisitor

Expand Down

0 comments on commit fed5fcb

Please sign in to comment.