com.clickzetta.client.jdbc.arrow.CZArrowResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clickzetta-java Show documentation
Show all versions of clickzetta-java Show documentation
The java SDK for clickzetta's Lakehouse
package com.clickzetta.client.jdbc.arrow;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.util.AutoCloseables;
import org.apache.arrow.vector.VectorSchemaRoot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class CZArrowResult implements CloseableVectorSchemaRootIterator {
private static final Logger logger = LoggerFactory.getLogger(CZArrowResult.class);
protected BufferAllocator allocator;
private ArrowVectorIterator vectorSchemaRootIterator;
public CZArrowResult(BufferAllocator allocator) {
this.allocator = allocator;
}
@Override
public boolean hasNext() {
if (vectorSchemaRootIterator != null && vectorSchemaRootIterator.hasNext()) {
return true;
}
try {
AutoCloseables.close(vectorSchemaRootIterator);
vectorSchemaRootIterator = null;
} catch (Exception e) {
logger.error("Failed to close vectorSchemaRootIterator.", e);
throw new RuntimeException(e);
}
if (hasNextFile()) {
vectorSchemaRootIterator = readNextFile();
return hasNext();
} else {
return false;
}
}
@Override
public VectorSchemaRoot next() {
// The returned VectorSchemaRoot will be closed by vectorSchemaRootIterator
return vectorSchemaRootIterator.next();
}
protected abstract boolean hasNextFile();
protected abstract ArrowVectorIterator readNextFile();
@Override
public void close() throws Exception {
AutoCloseables.close(vectorSchemaRootIterator);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy