org.apache.arrow.vector.holders.NullableVarCharHolder Java Examples

The following examples show how to use org.apache.arrow.vector.holders.NullableVarCharHolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MutableVarcharVector.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Get the variable length element at specified index and sets the state
 * in provided holder.
 *
 * @param index  position of element to get
 * @param holder data holder to be populated by this function
 */
public void get(int index, NullableVarCharHolder holder) {
  assert index >= 0;

  if (fwdIndex.isSet(index) == 0) {
    holder.isSet = 0;
    return;
  }

  final int actualIndex = fwdIndex.get(index);
  assert actualIndex >= 0;

  if (super.isSet(actualIndex) == 0) {
    throw new IllegalStateException("Value at actualIndex is null ");
  }

  holder.isSet = 1;
  holder.start = getstartOffset(actualIndex);
  holder.end = offsetBuffer.getInt((actualIndex + 1) * OFFSET_WIDTH);
  holder.buffer = valueBuffer;
}
 
Example #2
Source File: MutableVarcharVector.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Set the variable length element at the specified index to the data
 * buffer supplied in the holder.
 *
 * @param index  position of the element to set
 * @param holder holder that carries data buffer.
 */
public void set(int index, NullableVarCharHolder holder) {
  assert index >= 0;

  updateGarbageAndCompact(index);

  //update the index
  fwdIndex.setSafe(index, head);

  //append at the end
  fillHoles(head);
  BitVectorHelper.setValidityBit(validityBuffer, head, holder.isSet);
  final int dataLength = holder.end - holder.start;
  final int startOffset = getstartOffset(head);
  offsetBuffer.setInt((head + 1) * OFFSET_WIDTH, startOffset + dataLength);
  valueBuffer.setBytes(startOffset, holder.buffer, holder.start, dataLength);
  lastSet = head;

  ++head;
}
 
Example #3
Source File: MutableVarcharVector.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Same as {@link #set(int, NullableVarCharHolder)} except that it handles the
 * case where index and length of new element are beyond the existing
 * capacity of the vector.
 *
 * @param index  position of the element to set
 * @param holder holder that carries data buffer.
 */
public void setSafe(int index, NullableVarCharHolder holder) {
  assert index >= 0;

  updateGarbageAndCompact(index);

  //update the index
  fwdIndex.setSafe(index, head);

  //append at the end
  final int dataLength = holder.end - holder.start;
  fillEmpties(head);
  handleSafe(head, dataLength);
  BitVectorHelper.setValidityBit(validityBuffer, head, holder.isSet);
  final int startOffset = getstartOffset(head);
  offsetBuffer.setInt((head + 1) * OFFSET_WIDTH, startOffset + dataLength);
  valueBuffer.setBytes(startOffset, holder.buffer, holder.start, dataLength);
  lastSet = head;

  ++head;
}
 
Example #4
Source File: ExtractPattern.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static IndexType initType(NullableVarCharHolder indexType, FunctionErrorContext errCtx) {
  final String indexName = toStringFromUTF8(indexType.start, indexType.end, indexType.buffer);
  try {
    return IndexType.valueOf(indexName);
  } catch (IllegalArgumentException e) {
    throw errCtx.error()
      .message("Illegal indexType '%s'", indexName)
      .build();
  }
}
 
Example #5
Source File: ValueHolderHelper.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static NullableVarCharHolder getNullableVarCharHolder(ArrowBuf buf, String s){
  NullableVarCharHolder vch = new NullableVarCharHolder();

  byte[] b = s.getBytes(Charsets.UTF_8);
  vch.start = 0;
  vch.end = b.length;
  vch.buffer = buf.reallocIfNeeded(b.length);
  vch.buffer.setBytes(0, b);
  vch.isSet = 1;
  return vch;
}
 
Example #6
Source File: InExpression.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public BytesSet(NullableVarCharHolder[] holders) {
  for(NullableVarCharHolder h : holders) {
    if(h.isSet == 0) {
      // one null is never equal to another null.
      continue;
    }
    byteArraySet.add(new BytesHolder(h.start, h.end, h.buffer));
  }
}
 
Example #7
Source File: VarCharAccessor.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public InputStream getStream(int index) {
  if (ac.isNull(index)) {
    return null;
  }
  NullableVarCharHolder h = new NullableVarCharHolder();
  ac.get(index, h);
  return new ByteBufInputStream(h.buffer.slice(h.start, h.end).asNettyBuffer());
}
 
Example #8
Source File: MatchPattern.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static ReplaceMatcher initMatcher(NullableVarCharHolder patternStr, ReplaceSelectionType selectionType, Boolean ignoreCase) {
  String pattern = toStringFromUTF8(patternStr.start, patternStr.end, patternStr.buffer);
  return ReplaceRecommender.getMatcher(
      new ReplacePatternRule(selectionType)
          .setIgnoreCase(ignoreCase)
          .setSelectionPattern(pattern));
}
 
Example #9
Source File: ExtractPattern.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static Matcher initMatcher(NullableVarCharHolder pattern, FunctionErrorContext errCtx) {
  return compilePattern(
      toStringFromUTF8(pattern.start, pattern.end, pattern.buffer), errCtx)
      .matcher("");
}
 
Example #10
Source File: BasicTypeHelper.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static ValueHolder getValueHolderForType(MinorType type) {

    switch (type) {
    case TINYINT:
      return new NullableTinyIntHolder();
    case UINT1:
      return new NullableUInt1Holder();
    case UINT2:
      return new NullableUInt2Holder();
    case SMALLINT:
      return new NullableSmallIntHolder();
    case INT:
      return new NullableIntHolder();
    case UINT4:
      return new NullableUInt4Holder();
    case FLOAT4:
      return new NullableFloat4Holder();
    case INTERVALYEAR:
      return new NullableIntervalYearHolder();
    case TIMEMILLI:
      return new NullableTimeMilliHolder();
    case BIGINT:
      return new NullableBigIntHolder();
    case UINT8:
      return new NullableUInt8Holder();
    case FLOAT8:
      return new NullableFloat8Holder();
    case DATEMILLI:
      return new NullableDateMilliHolder();
    case TIMESTAMPMILLI:
      return new NullableTimeStampMilliHolder();
    case INTERVALDAY:
      return new NullableIntervalDayHolder();
    case DECIMAL:
      return new NullableDecimalHolder();
    case FIXEDSIZEBINARY:
      return new NullableFixedSizeBinaryHolder();
    case VARBINARY:
      return new NullableVarBinaryHolder();
    case VARCHAR:
      return new NullableVarCharHolder();
    case BIT:
      return new NullableBitHolder();
    }
    throw new UnsupportedOperationException(
        String.format("%s is not supported for 'getValueHolderForType' method.", type));

  }
 
Example #11
Source File: SplitPattern.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static Matcher initMatcher(NullableVarCharHolder pattern) {
  return Pattern.compile(
      toStringFromUTF8(pattern.start, pattern.end, pattern.buffer)
  ).matcher("");
}
 
Example #12
Source File: SplitPattern.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static SplitPositionType initPositionType(NullableVarCharHolder value) {
  return SplitPositionType.valueOf(toStringFromUTF8(value.start, value.end, value.buffer));
}
 
Example #13
Source File: MatchPattern.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static ReplaceSelectionType initSelectionType(NullableVarCharHolder value) {
  return ReplaceSelectionType.valueOf(StringFunctionHelpers.toStringFromUTF8(value.start, value.end, value.buffer));
}
 
Example #14
Source File: CleanData.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static DataType initType(NullableVarCharHolder dataType) {
  return DataType.valueOf(toStringFromUTF8(dataType.start, dataType.end, dataType.buffer));
}
 
Example #15
Source File: CompleteType.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static <T extends ValueHolder> CompleteType fromHolderClass(Class<T> holderClass){
    if (holderClass.equals(IntHolder.class)) {
      return CompleteType.INT;
    } else if (holderClass.equals(NullableIntHolder.class)) {
      return CompleteType.INT;
    } else if (holderClass.equals(Float4Holder.class)) {
      return CompleteType.FLOAT;
    } else if (holderClass.equals(NullableFloat4Holder.class)) {
      return CompleteType.FLOAT;
    } else if (holderClass.equals(IntervalYearHolder.class)) {
      return CompleteType.INTERVAL_YEAR_MONTHS;
    } else if (holderClass.equals(NullableIntervalYearHolder.class)) {
      return CompleteType.INTERVAL_YEAR_MONTHS;
    } else if (holderClass.equals(TimeMilliHolder.class)) {
      return CompleteType.TIME;
    } else if (holderClass.equals(NullableTimeMilliHolder.class)) {
      return CompleteType.TIME;
    } else if (holderClass.equals(BigIntHolder.class)) {
      return CompleteType.BIGINT;
    } else if (holderClass.equals(NullableBigIntHolder.class)) {
      return CompleteType.BIGINT;
    } else if (holderClass.equals(Float8Holder.class)) {
      return CompleteType.DOUBLE;
    } else if (holderClass.equals(NullableFloat8Holder.class)) {
      return CompleteType.DOUBLE;
    } else if (holderClass.equals(DateMilliHolder.class)) {
      return CompleteType.DATE;
    } else if (holderClass.equals(NullableDateMilliHolder.class)) {
      return CompleteType.DATE;
    } else if (holderClass.equals(TimeStampMilliHolder.class)) {
      return CompleteType.TIMESTAMP;
    } else if (holderClass.equals(NullableTimeStampMilliHolder.class)) {
      return CompleteType.TIMESTAMP;
    } else if (holderClass.equals(IntervalDayHolder.class)) {
      return CompleteType.INTERVAL_DAY_SECONDS;
    } else if (holderClass.equals(NullableIntervalDayHolder.class)) {
      return CompleteType.INTERVAL_DAY_SECONDS;
    } else if (holderClass.equals(DecimalHolder.class)) {
      return CompleteType.fromDecimalPrecisionScale(0, 0);
    } else if (holderClass.equals(NullableDecimalHolder.class)) {
      return CompleteType.fromDecimalPrecisionScale(0, 0);
    } else if (holderClass.equals(VarBinaryHolder.class)) {
      return CompleteType.VARBINARY;
    } else if (holderClass.equals(NullableVarBinaryHolder.class)) {
      return CompleteType.VARBINARY;
    } else if (holderClass.equals(VarCharHolder.class)) {
      return CompleteType.VARCHAR;
    } else if (holderClass.equals(NullableVarCharHolder.class)) {
      return CompleteType.VARCHAR;
    } else if (holderClass.equals(BitHolder.class)) {
      return CompleteType.BIT;
    } else if (holderClass.equals(NullableBitHolder.class)) {
      return CompleteType.BIT;
    } else if (holderClass.equals(ObjectHolder.class)) {
      return CompleteType.OBJECT;
    } else if (holderClass.equals(UnionHolder.class)) {
      return new CompleteType(new Union(UnionMode.Sparse, new int[0]));
    } else if (holderClass.equals(NullableFixedSizeBinaryHolder.class)) {
      return CompleteType.FIXEDSIZEBINARY;
    }

    throw new UnsupportedOperationException(String.format("%s is not supported for 'getValueHolderType' method.", holderClass.getName()));

}
 
Example #16
Source File: BasicTypeHelper.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static ValueHolder createValueHolder(MinorType type) {
  switch (type) {
  case TINYINT:
    return new NullableTinyIntHolder();
  case UINT1:
    return new NullableUInt1Holder();
  case UINT2:
    return new NullableUInt2Holder();
  case SMALLINT:
    return new NullableSmallIntHolder();
  case INT:
    return new NullableIntHolder();
  case UINT4:
    return new NullableUInt4Holder();
  case FLOAT4:
    return new NullableFloat4Holder();
  case INTERVALYEAR:
    return new NullableIntervalYearHolder();
  case TIMEMILLI:
    return new NullableTimeMilliHolder();
  case BIGINT:
    return new NullableBigIntHolder();
  case UINT8:
    return new NullableUInt8Holder();
  case FLOAT8:
    return new NullableFloat8Holder();
  case DATEMILLI:
    return new NullableDateMilliHolder();
  case TIMESTAMPMILLI:
    return new NullableTimeStampMilliHolder();
  case INTERVALDAY:
    return new NullableIntervalDayHolder();
  case DECIMAL:
    return new NullableDecimalHolder();
  case FIXEDSIZEBINARY:
    return new NullableFixedSizeBinaryHolder();
  case VARBINARY:
    return new NullableVarBinaryHolder();
  case VARCHAR:
    return new NullableVarCharHolder();
  case BIT:
    return new NullableBitHolder();
  default:
    throw new UnsupportedOperationException(buildErrorMessage("create value holder", type));
  }
}
 
Example #17
Source File: BasicTypeHelper.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static MinorType getValueHolderType(ValueHolder holder) {

    if (0 == 1) {
      return null;
    } else if (holder instanceof TinyIntHolder) {
      return MinorType.TINYINT;
    } else if (holder instanceof NullableTinyIntHolder) {
      return MinorType.TINYINT;
    } else if (holder instanceof UInt1Holder) {
      return MinorType.UINT1;
    } else if (holder instanceof NullableUInt1Holder) {
      return MinorType.UINT1;
    } else if (holder instanceof UInt2Holder) {
      return MinorType.UINT2;
    } else if (holder instanceof NullableUInt2Holder) {
      return MinorType.UINT2;
    } else if (holder instanceof SmallIntHolder) {
      return MinorType.SMALLINT;
    } else if (holder instanceof NullableSmallIntHolder) {
      return MinorType.SMALLINT;
    } else if (holder instanceof IntHolder) {
      return MinorType.INT;
    } else if (holder instanceof NullableIntHolder) {
      return MinorType.INT;
    } else if (holder instanceof UInt4Holder) {
      return MinorType.UINT4;
    } else if (holder instanceof NullableUInt4Holder) {
      return MinorType.UINT4;
    } else if (holder instanceof Float4Holder) {
      return MinorType.FLOAT4;
    } else if (holder instanceof NullableFloat4Holder) {
      return MinorType.FLOAT4;
    } else if (holder instanceof IntervalYearHolder) {
      return MinorType.INTERVALYEAR;
    } else if (holder instanceof NullableIntervalYearHolder) {
      return MinorType.INTERVALYEAR;
    } else if (holder instanceof TimeMilliHolder) {
      return MinorType.TIMEMILLI;
    } else if (holder instanceof NullableTimeMilliHolder) {
      return MinorType.TIMEMILLI;
    } else if (holder instanceof BigIntHolder) {
      return MinorType.BIGINT;
    } else if (holder instanceof NullableBigIntHolder) {
      return MinorType.BIGINT;
    } else if (holder instanceof UInt8Holder) {
      return MinorType.UINT8;
    } else if (holder instanceof NullableUInt8Holder) {
      return MinorType.UINT8;
    } else if (holder instanceof Float8Holder) {
      return MinorType.FLOAT8;
    } else if (holder instanceof NullableFloat8Holder) {
      return MinorType.FLOAT8;
    } else if (holder instanceof DateMilliHolder) {
      return MinorType.DATEMILLI;
    } else if (holder instanceof NullableDateMilliHolder) {
      return MinorType.DATEMILLI;
    } else if (holder instanceof TimeStampMilliHolder) {
      return MinorType.TIMESTAMPMILLI;
    } else if (holder instanceof NullableTimeStampMilliHolder) {
      return MinorType.TIMESTAMPMILLI;
    } else if (holder instanceof IntervalDayHolder) {
      return MinorType.INTERVALDAY;
    } else if (holder instanceof NullableIntervalDayHolder) {
      return MinorType.INTERVALDAY;
    } else if (holder instanceof DecimalHolder) {
      return MinorType.DECIMAL;
    } else if (holder instanceof NullableDecimalHolder) {
      return MinorType.DECIMAL;
    } else if (holder instanceof FixedSizeBinaryHolder) {
      return MinorType.FIXEDSIZEBINARY;
    } else if (holder instanceof NullableFixedSizeBinaryHolder) {
      return MinorType.FIXEDSIZEBINARY;
    } else if (holder instanceof VarBinaryHolder) {
      return MinorType.VARBINARY;
    } else if (holder instanceof NullableVarBinaryHolder) {
      return MinorType.VARBINARY;
    } else if (holder instanceof VarCharHolder) {
      return MinorType.VARCHAR;
    } else if (holder instanceof NullableVarCharHolder) {
      return MinorType.VARCHAR;
    } else if (holder instanceof BitHolder) {
      return MinorType.BIT;
    } else if (holder instanceof NullableBitHolder) {
      return MinorType.BIT;
    }

    throw new UnsupportedOperationException("ValueHolder is not supported for 'getValueHolderType' method.");

  }