All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clickzetta.client.jdbc.arrow.CZArrowResult Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
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