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

com.clickzetta.client.jdbc.arrow.accessor.ArrowTimeStampVectorGetter Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.clickzetta.client.jdbc.arrow.accessor;

import org.apache.arrow.vector.TimeStampMicroTZVector;
import org.apache.arrow.vector.TimeStampMicroVector;
import org.apache.arrow.vector.TimeStampMilliTZVector;
import org.apache.arrow.vector.TimeStampMilliVector;
import org.apache.arrow.vector.TimeStampNanoTZVector;
import org.apache.arrow.vector.TimeStampNanoVector;
import org.apache.arrow.vector.TimeStampSecTZVector;
import org.apache.arrow.vector.TimeStampSecVector;
import org.apache.arrow.vector.TimeStampVector;
import org.apache.arrow.vector.holders.NullableTimeStampMicroHolder;
import org.apache.arrow.vector.holders.NullableTimeStampMicroTZHolder;
import org.apache.arrow.vector.holders.NullableTimeStampMilliHolder;
import org.apache.arrow.vector.holders.NullableTimeStampMilliTZHolder;
import org.apache.arrow.vector.holders.NullableTimeStampNanoHolder;
import org.apache.arrow.vector.holders.NullableTimeStampNanoTZHolder;
import org.apache.arrow.vector.holders.NullableTimeStampSecHolder;
import org.apache.arrow.vector.holders.NullableTimeStampSecTZHolder;

/**
 * Auxiliary class used to unify data access on TimeStampVectors.
 */
final class ArrowTimeStampVectorGetter {

  private ArrowTimeStampVectorGetter() {
    // Prevent instantiation.
  }

  static Getter createGetter(TimeStampVector vector) {
    if (vector instanceof TimeStampNanoVector) {
      return createGetter((TimeStampNanoVector) vector);
    } else if (vector instanceof TimeStampNanoTZVector) {
      return createGetter((TimeStampNanoTZVector) vector);
    } else if (vector instanceof TimeStampMicroVector) {
      return createGetter((TimeStampMicroVector) vector);
    } else if (vector instanceof TimeStampMicroTZVector) {
      return createGetter((TimeStampMicroTZVector) vector);
    } else if (vector instanceof TimeStampMilliVector) {
      return createGetter((TimeStampMilliVector) vector);
    } else if (vector instanceof TimeStampMilliTZVector) {
      return createGetter((TimeStampMilliTZVector) vector);
    } else if (vector instanceof TimeStampSecVector) {
      return createGetter((TimeStampSecVector) vector);
    } else if (vector instanceof TimeStampSecTZVector) {
      return createGetter((TimeStampSecTZVector) vector);
    }

    throw new UnsupportedOperationException("Unsupported Timestamp vector type");
  }

  private static Getter createGetter(TimeStampNanoVector vector) {
    NullableTimeStampNanoHolder auxHolder = new NullableTimeStampNanoHolder();
    return (index, holder) -> {
      vector.get(index, auxHolder);
      holder.isSet = auxHolder.isSet;
      holder.value = auxHolder.value;
    };
  }

  private static Getter createGetter(TimeStampNanoTZVector vector) {
    NullableTimeStampNanoTZHolder auxHolder = new NullableTimeStampNanoTZHolder();
    return (index, holder) -> {
      vector.get(index, auxHolder);
      holder.isSet = auxHolder.isSet;
      holder.value = auxHolder.value;
    };
  }

  private static Getter createGetter(TimeStampMicroVector vector) {
    NullableTimeStampMicroHolder auxHolder = new NullableTimeStampMicroHolder();
    return (index, holder) -> {
      vector.get(index, auxHolder);
      holder.isSet = auxHolder.isSet;
      holder.value = auxHolder.value;
    };
  }

  private static Getter createGetter(TimeStampMicroTZVector vector) {
    NullableTimeStampMicroTZHolder auxHolder = new NullableTimeStampMicroTZHolder();
    return (index, holder) -> {
      vector.get(index, auxHolder);
      holder.isSet = auxHolder.isSet;
      holder.value = auxHolder.value;
    };
  }

  private static Getter createGetter(TimeStampMilliVector vector) {
    NullableTimeStampMilliHolder auxHolder = new NullableTimeStampMilliHolder();
    return (index, holder) -> {
      vector.get(index, auxHolder);
      holder.isSet = auxHolder.isSet;
      holder.value = auxHolder.value;
    };
  }

  private static Getter createGetter(TimeStampMilliTZVector vector) {
    NullableTimeStampMilliTZHolder auxHolder = new NullableTimeStampMilliTZHolder();
    return (index, holder) -> {
      vector.get(index, auxHolder);
      holder.isSet = auxHolder.isSet;
      holder.value = auxHolder.value;
    };
  }

  private static Getter createGetter(TimeStampSecVector vector) {
    NullableTimeStampSecHolder auxHolder = new NullableTimeStampSecHolder();
    return (index, holder) -> {
      vector.get(index, auxHolder);
      holder.isSet = auxHolder.isSet;
      holder.value = auxHolder.value;
    };
  }

  private static Getter createGetter(TimeStampSecTZVector vector) {
    NullableTimeStampSecTZHolder auxHolder = new NullableTimeStampSecTZHolder();
    return (index, holder) -> {
      vector.get(index, auxHolder);
      holder.isSet = auxHolder.isSet;
      holder.value = auxHolder.value;
    };
  }

  /**
   * Functional interface used to unify TimeStamp*Vector#get implementations.
   */
  @FunctionalInterface
  interface Getter {
    void get(int index, Holder holder);
  }

  /**
   * Auxiliary class meant to unify TimeStamp*Vector#get implementations with different classes of ValueHolders.
   */
  static class Holder {
    int isSet; // Tells if value is set; 0 = not set, 1 = set
    long value; // Holds actual value in its respective timeunit
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy