Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@
import org.opensearch.datafusion.jni.NativeBridge;
import org.opensearch.vectorized.execution.jni.RefCountedNativeHandle;

import java.io.Closeable;

/**
* Reference-counted handle for native reader.
*/
public final class ReaderHandle extends RefCountedNativeHandle {

public ReaderHandle(String path, String[] files) {
private final Runnable onClose;

public ReaderHandle(String path, String[] files, Runnable onClose) {
super(NativeBridge.createDatafusionReader(path, files));
this.onClose = onClose;
}

@Override
protected void doClose() {
NativeBridge.closeDatafusionReader(ptr);
onClose.run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public DatafusionReader(String directoryPath, CompositeEngine.ReleasableRef<Cata
}
System.out.println("File names: " + Arrays.toString(fileNames));
System.out.println("Directory path: " + directoryPath);
this.readerHandle = new ReaderHandle(directoryPath, fileNames);
this.readerHandle = new ReaderHandle(directoryPath, fileNames, this::releaseCatalogSnapshot);
}

/**
Expand Down Expand Up @@ -91,6 +91,9 @@ public int getRefCount() {
@Override
public void close() {
readerHandle.close();
}

private void releaseCatalogSnapshot() {
try {
if (catalogSnapshotRef != null)
catalogSnapshotRef.close();
Expand Down
Loading