org.apache.arrow.vector.VarBinaryVector Java Examples

The following examples show how to use org.apache.arrow.vector.VarBinaryVector. 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: TestVarBinaryPivot.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
static void populate(VarBinaryVector vector, byte[][] values){
  vector.allocateNew();
  Random r = new Random();
  for(int i =0; i < values.length; i++){
    byte[] val = values[i];
    if(val != null){
      vector.setSafe(i, val, 0, val.length);
    } else {
      // add noise. this confirms that after pivot, noise is gone.
      byte[] bytes = new byte[r.nextInt(15)];
      r.nextBytes(bytes);
      vector.setSafe(i, bytes, 0, bytes.length);
      vector.setNull(i);
    }
  }
  vector.setValueCount(values.length);
}
 
Example #2
Source File: BaseNdvAccumulatorNoSpill.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void output(int batchIndex) {
  HllAccumHolder ah = accumulators[batchIndex];

  HllSketch[] sketches = ah.getAccums();

  int total_size = 0;
  for (int i = 0; i < sketches.length; ++i) {
    total_size += sketches[i].getCompactSerializationBytes();
  }

  ((VariableWidthVector) output).allocateNew(total_size, LBlockHashTableNoSpill.MAX_VALUES_PER_BATCH);
  VarBinaryVector outVec = (VarBinaryVector) output;

  for (int i = 0; i < sketches.length; ++i) {
    byte[] ba = sketches[i].toCompactByteArray();
    outVec.setSafe(i, ba, 0, ba.length);
  }
}
 
Example #3
Source File: BaseNdvUnionAccumulatorNoSpill.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void output(int batchIndex) {
  HllUnionAccumHolder ah = accumulators[batchIndex];

  Union[] sketches = ah.getAccums();

  int total_size = 0;
  for (int i = 0; i < sketches.length; ++i) {
    total_size += sketches[i].getCompactSerializationBytes();
  }

  ((VariableWidthVector) output).allocateNew(total_size, LBlockHashTableNoSpill.MAX_VALUES_PER_BATCH);
  VarBinaryVector outVec = (VarBinaryVector) output;

  for (int i = 0; i < sketches.length; ++i) {
    byte[] ba = sketches[i].toCompactByteArray();
    outVec.setSafe(i, ba, 0, ba.length);
  }
}
 
Example #4
Source File: VectorizedHashAggOperator.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Create pivot definition. This operation is independent of
 * partitioning and needs to be done once during setup and not
 * per partition. Populates the outgoing vector container
 * with target vectors and builds set of FieldVectorPair
 * <inputVector, outputVector> for creating the pivot
 * definition.
 *
 * @return vector pivot definition for the incoming GROUP BY
 * expressions.
 */
private PivotDef createPivot(){
  final List<NamedExpression> groupByExpressions = popConfig.getGroupByExprs();
  final ImmutableList.Builder<FieldVector> validationVectors = ImmutableList.builder();

  final List<FieldVectorPair> fvps = new ArrayList<>();
  for (int i = 0; i < groupByExpressions.size(); i++) {
    final NamedExpression ne = groupByExpressions.get(i);
    final LogicalExpression expr = context.getClassProducer().materialize(ne.getExpr(), incoming);

    if(expr == null){
      throw unsup("Unable to resolve group by expression: " + ne.getExpr().toString());
    }
    if( !(expr instanceof ValueVectorReadExpression) ){
      throw unsup("Group by expression is non-trivial: " + ne.getExpr().toString());
    }

    final ValueVectorReadExpression vvread = (ValueVectorReadExpression) expr;
    final FieldVector inputVector = incoming.getValueAccessorById(FieldVector.class, vvread.getFieldId().getFieldIds()).getValueVector();
    if(inputVector instanceof VarCharVector || inputVector instanceof VarBinaryVector){
      validationVectors.add(inputVector);
    }
    final FieldVector outputVector = TypeHelper.getNewVector(expr.getCompleteType().toField(ne.getRef()), outputAllocator);
    outgoing.add(outputVector);
    fvps.add(new FieldVectorPair(inputVector, outputVector));
  }

  this.vectorsToValidate = validationVectors.build();
  return PivotBuilder.getBlockDefinition(fvps);
}
 
Example #5
Source File: ColumnReaderFactory.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
static VarLengthValuesColumn<?> getReader(DeprecatedParquetVectorizedReader parentReader, int allocateSize, ColumnDescriptor descriptor,
                                          ColumnChunkMetaData columnChunkMetaData, boolean fixedLength, ValueVector v,
                                          SchemaElement schemaElement
) throws ExecutionSetupException {
  ConvertedType convertedType = schemaElement.getConverted_type();
  switch (descriptor.getMaxDefinitionLevel()) {
    case 0:
      if (convertedType == null) {
        return new VarLengthColumnReaders.VarBinaryColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarBinaryVector) v, schemaElement);
      }
      switch (convertedType) {
        case UTF8:
          return new VarLengthColumnReaders.VarCharColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarCharVector) v, schemaElement);
        case DECIMAL:
          return new VarLengthColumnReaders.Decimal28Column(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (DecimalVector) v, schemaElement);
        default:
          return new VarLengthColumnReaders.VarBinaryColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarBinaryVector) v, schemaElement);
      }
    default:
      if (convertedType == null) {
        return new VarLengthColumnReaders.NullableVarBinaryColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarBinaryVector) v, schemaElement);
      }

      switch (convertedType) {
        case UTF8:
          return new VarLengthColumnReaders.NullableVarCharColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarCharVector) v, schemaElement);
        case DECIMAL:
          return new NullableDecimalColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (DecimalVector) v, schemaElement);
        default:
          return new VarLengthColumnReaders.NullableVarBinaryColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarBinaryVector) v, schemaElement);
      }
  }
}
 
Example #6
Source File: GlobalDictionaryBuilder.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static VectorContainer buildBinaryGlobalDictionary(List<Dictionary> dictionaries, VectorContainer existingDict, ColumnDescriptor columnDescriptor, BufferAllocator bufferAllocator) {
  final Field field = new Field(SchemaPath.getCompoundPath(columnDescriptor.getPath()).getAsUnescapedPath(), true, new ArrowType.Binary(), null);
  final VectorContainer input = new VectorContainer(bufferAllocator);
  final VarBinaryVector binaryVector = input.addOrGet(field);
  binaryVector.allocateNew();
  final SortedSet<Binary> values = new TreeSet<>();
  for (Dictionary dictionary : dictionaries) {
    for (int i = 0; i <= dictionary.getMaxId(); ++i) {
      values.add(dictionary.decodeToBinary(i));
    }
  }
  if (existingDict != null) {
    final VarBinaryVector existingDictValues = existingDict.getValueAccessorById(VarBinaryVector.class, 0).getValueVector();
    for (int i = 0; i < existingDict.getRecordCount(); ++i) {
      values.add(Binary.fromConstantByteArray(existingDictValues.get(i)));
    }
  }
  final Iterator<Binary> iter = values.iterator();
  int recordCount = 0;
  while (iter.hasNext()) {
    final byte[] data = iter.next().getBytes();
    binaryVector.setSafe(recordCount++, data, 0, data.length);
  }
  binaryVector.setValueCount(recordCount);
  input.setRecordCount(recordCount);
  input.buildSchema(BatchSchema.SelectionVectorMode.NONE);
  return input;
}
 
Example #7
Source File: VectorizedHashAggOperatorNoSpill.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private PivotDef createPivot(){
  final List<NamedExpression> groupByExpressions = popConfig.getGroupByExprs();
  final ImmutableList.Builder<FieldVector> validationVectors = ImmutableList.builder();

  final List<FieldVectorPair> fvps = new ArrayList<>();
  //final FieldVector[] readVectors = new FieldVector[]
  for (int i = 0; i < groupByExpressions.size(); i++) {
    final NamedExpression ne = groupByExpressions.get(i);
    final LogicalExpression expr = context.getClassProducer().materialize(ne.getExpr(), incoming);

    if(expr == null){
      throw unsup("Unable to resolve group by expression: " + ne.getExpr().toString());
    }
    if( !(expr instanceof ValueVectorReadExpression) ){
      throw unsup("Group by expression is non-trivial: " + ne.getExpr().toString());
    }

    final ValueVectorReadExpression vvread = (ValueVectorReadExpression) expr;
    final FieldVector inputVector = incoming.getValueAccessorById(FieldVector.class, vvread.getFieldId().getFieldIds()).getValueVector();
    if(inputVector instanceof VarCharVector || inputVector instanceof VarBinaryVector){
      validationVectors.add(inputVector);
    }
    final FieldVector outputVector = TypeHelper.getNewVector(expr.getCompleteType().toField(ne.getRef()), context.getAllocator());
    outgoing.add(outputVector);
    fvps.add(new FieldVectorPair(inputVector, outputVector));
  }

  this.vectorsToValidate = validationVectors.build();
  return PivotBuilder.getBlockDefinition(fvps);
}
 
Example #8
Source File: TestData.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static Pair<VarBinaryVector, ResultVerifier> testVarBinaryVector(final int startIndexInCurrentOutput, final int startIndexInJob) {
  VarBinaryVector colVarBinaryV = new VarBinaryVector("colVarBinary", allocator);
  colVarBinaryV.allocateNew(500, 5);
  colVarBinaryV.set(0, "value1".getBytes());
  colVarBinaryV.set(1,
      "long long long long long long long long long long long long long long long value".getBytes()
  );
  colVarBinaryV.set(2, "long long long long value".getBytes());
  colVarBinaryV.setNull(3);
  colVarBinaryV.set(4, "l".getBytes());

  ResultVerifier verifier = new ResultVerifier() {
    @Override
    public void verify(DataPOJO output) {
      int index = startIndexInCurrentOutput;
      int uIndex = startIndexInJob;
      assertEquals("dmFsdWUx", output.extractValue("colVarBinary", index));
      assertNull(output.extractUrl("colVarBinary", index++));
      uIndex++;

      assertEquals("bG9uZyBsb25nIGxvbmcgbG9uZyBsb25nIGxvbmcg", output.extractValue("colVarBinary", index));
      assertEquals(cellUrl(uIndex++, "colVarBinary"), output.extractUrl("colVarBinary", index++));

      assertEquals("bG9uZyBsb25nIGxvbmcgbG9uZyB2YWx1ZQ==", output.extractValue("colVarBinary", index));
      assertNull(output.extractUrl("colVarBinary", index++));
      uIndex++;

      assertNull(output.extractValue("colVarBinary", index));
      assertNull(output.extractUrl("colVarBinary", index++));
      uIndex++;

      assertEquals("bA==", output.extractValue("colVarBinary", index));
      assertNull(output.extractUrl("colVarBinary", index++));
      uIndex++;
    }
  };

  return Pair.of(colVarBinaryV, verifier);
}
 
Example #9
Source File: VectorizedParquetDefinitionLevelReader.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private static void setBinaryInVector(
    VarBinaryVector vector,
    int typeWidth,
    ValuesAsBytesReader valuesReader,
    int bufferIdx, NullabilityHolder nullabilityHolder) {
  ByteBuffer buffer = valuesReader.getBuffer(typeWidth);
  vector.setSafe(bufferIdx, buffer.array(), buffer.position() + buffer.arrayOffset(),
      buffer.limit() - buffer.position());
  nullabilityHolder.setNotNull(bufferIdx);
}
 
Example #10
Source File: VectorizedParquetDefinitionLevelReader.java    From iceberg with Apache License 2.0 5 votes vote down vote up
public void readBatchOfFixedWidthBinary(
    final FieldVector vector, final int startOffset,
    final int typeWidth, final int numValsToRead, NullabilityHolder nullabilityHolder,
    ValuesAsBytesReader valuesReader) {
  int bufferIdx = startOffset;
  int left = numValsToRead;
  while (left > 0) {
    if (this.currentCount == 0) {
      this.readNextGroup();
    }
    int num = Math.min(left, this.currentCount);
    switch (mode) {
      case RLE:
        if (currentValue == maxDefLevel) {
          for (int i = 0; i < num; i++) {
            setBinaryInVector((VarBinaryVector) vector, typeWidth, valuesReader, bufferIdx, nullabilityHolder);
            bufferIdx++;
          }
        } else {
          setNulls(nullabilityHolder, bufferIdx, num, vector.getValidityBuffer());
          bufferIdx += num;
        }
        break;
      case PACKED:
        for (int i = 0; i < num; i++) {
          if (packedValuesBuffer[packedValuesBufferIdx++] == maxDefLevel) {
            setBinaryInVector((VarBinaryVector) vector, typeWidth, valuesReader, bufferIdx, nullabilityHolder);
          } else {
            setNull(nullabilityHolder, bufferIdx, vector.getValidityBuffer());
          }
          bufferIdx++;
        }
        break;
    }
    left -= num;
    currentCount -= num;
  }
}
 
Example #11
Source File: ArrowVectorAccessors.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@NotNull
@SuppressWarnings("checkstyle:CyclomaticComplexity")
private static ArrowVectorAccessor getPlainVectorAccessor(FieldVector vector) {
  if (vector instanceof BitVector) {
    return new BooleanAccessor((BitVector) vector);
  } else if (vector instanceof IntVector) {
    return new IntAccessor((IntVector) vector);
  } else if (vector instanceof BigIntVector) {
    return new LongAccessor((BigIntVector) vector);
  } else if (vector instanceof Float4Vector) {
    return new FloatAccessor((Float4Vector) vector);
  } else if (vector instanceof Float8Vector) {
    return new DoubleAccessor((Float8Vector) vector);
  } else if (vector instanceof IcebergArrowVectors.DecimalArrowVector) {
    return new DecimalAccessor((IcebergArrowVectors.DecimalArrowVector) vector);
  } else if (vector instanceof IcebergArrowVectors.VarcharArrowVector) {
    return new StringAccessor((IcebergArrowVectors.VarcharArrowVector) vector);
  } else if (vector instanceof VarBinaryVector) {
    return new BinaryAccessor((VarBinaryVector) vector);
  } else if (vector instanceof DateDayVector) {
    return new DateAccessor((DateDayVector) vector);
  } else if (vector instanceof TimeStampMicroTZVector) {
    return new TimestampAccessor((TimeStampMicroTZVector) vector);
  } else if (vector instanceof ListVector) {
    ListVector listVector = (ListVector) vector;
    return new ArrayAccessor(listVector);
  } else if (vector instanceof StructVector) {
    StructVector structVector = (StructVector) vector;
    return new StructAccessor(structVector);
  }
  throw new UnsupportedOperationException("Unsupported vector: " + vector.getClass());
}
 
Example #12
Source File: OutgoingBatch.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
OutgoingBatch(int batchIdx, int nextBatchIdx, int maxRecords, final VectorAccessible incoming,
              BufferAllocator allocator, AccountingExecTunnel tunnel, HashPartitionSender config,
              OperatorContext context, int oppositeMinorFragmentId, OperatorStats stats) {
  Preconditions.checkArgument(maxRecords <= Character.MAX_VALUE, "maxRecords cannot exceed " + Character.MAX_VALUE);
  this.batchIdx = batchIdx;
  this.nextBatchIdx = nextBatchIdx;
  this.maxRecords = maxRecords;

  this.tunnel = tunnel;
  this.config = config;
  this.context = context;
  this.oppositeMinorFragmentId = oppositeMinorFragmentId;

  this.stats = stats;

  for (VectorWrapper<?> v : incoming) {
    ValueVector outgoingVector = TypeHelper.getNewVector(v.getField(), allocator);
    outgoingVector.setInitialCapacity(maxRecords);
    add(outgoingVector);

    if (outgoingVector instanceof VarBinaryVector) {
      varbins.add(((VarBinaryVector) outgoingVector));
    } else if (outgoingVector instanceof VarCharVector) {
      varchars.add(((VarCharVector) outgoingVector));
    }
  }
}
 
Example #13
Source File: RowVarBinaryWriter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void doWrite(Row value, int ordinal) {
	if (value.getField(ordinal) == null) {
		((VarBinaryVector) getValueVector()).setNull(getCount());
	} else {
		((VarBinaryVector) getValueVector()).setSafe(getCount(), (byte[]) value.getField(ordinal));
	}
}
 
Example #14
Source File: Reallocators.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static Reallocator getReallocator(FieldVector vect){
  if(vect instanceof VarCharVector){
    return new VarCharReallocator(((VarCharVector) vect));
  }else if(vect instanceof VarBinaryVector){
    return new VarBinaryReallocator(((VarBinaryVector) vect));
  }else{
    throw new IllegalStateException("Invalid vector: " + Describer.describe(vect.getField()));
  }
}
 
Example #15
Source File: LocalJobsService.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void execDataArrived(RpcOutcomeListener<Ack> outcomeListener, QueryWritableBatch result) {
  try (TimedBlock b = Timer.time("dataMetadataArrived");
      QueryDataBatch dataBatch = LocalUserUtil.acquireData(allocator, outcomeListener, result);
      RecordBatchLoader loader = new RecordBatchLoader(allocator)) {
    b.addID("attempt=" + attemptId);
    loader.load(dataBatch.getHeader().getDef(), dataBatch.getData());

    // Query output just contains the batch unique id and number of records in the batch.
    try (RecordBatchData batch = new RecordBatchData(loader, allocator)) {
      List<ValueVector> vectors = batch.getVectors();

      if (vectors.size() < 4 || !(vectors.get(3) instanceof VarBinaryVector) ) {
        throw UserException.unsupportedError()
            .message("Job output contains invalid data")
            .build(logger);
      }

      VarBinaryVector metadataVector = (VarBinaryVector) vectors.get(3);

      for (int i = 0; i < batch.getRecordCount(); i++) {
        final ArrowFileFormat.ArrowFileMetadata metadata =
            ArrowFileFormat.ArrowFileMetadata.parseFrom(metadataVector.getObject(i));
        job.getJobAttempt().getInfo().getResultMetadataList().add(ArrowFileReader.toBean(metadata));
      }
      storeJob(job);
    }
  } catch (Exception ex) {
    exception.addException(ex);
  }
}
 
Example #16
Source File: VarBinaryWriter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void doWrite(T in, int ordinal) {
	if (isNullAt(in, ordinal)) {
		((VarBinaryVector) getValueVector()).setNull(getCount());
	} else {
		((VarBinaryVector) getValueVector()).setSafe(getCount(), readBinary(in, ordinal));
	}
}
 
Example #17
Source File: TestVarBinaryPivot.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void testVarBinaryPivot(){
  final byte[][] vectA = {b("hello"), null, b("my friend"), null, b("take a joy ride")};
  final byte[][] vectB = {null, b("you fool"), null, b("Cinderella"), b("Story")};

  try(
      VarBinaryVector col1 = new VarBinaryVector("col1", allocator);
      VarBinaryVector col2 = new VarBinaryVector("col2", allocator);){
    PivotDef pivot = PivotBuilder.getBlockDefinition(
        new FieldVectorPair(col1, col1),
        new FieldVectorPair(col2, col2));
    populate(col1, vectA);
    populate(col2, vectB);

    assertEquals(8, pivot.getBlockWidth());

    try(
        FixedBlockVector fixed = new FixedBlockVector(allocator, pivot.getBlockWidth());
        VariableBlockVector variable = new VariableBlockVector(allocator, pivot.getVariableCount());
        ){
      Pivots.pivot(pivot, 5, fixed, variable);
      validateVarBinaryValues(pivot.getBlockWidth(), pivot.getVectorPivots().get(0), fixed, variable, vectA);
      validateVarBinaryValues(pivot.getBlockWidth(), pivot.getVectorPivots().get(1), fixed, variable, vectB);
    }
  }

}
 
Example #18
Source File: VarBinaryWriter.java    From flink with Apache License 2.0 4 votes vote down vote up
private VarBinaryWriter(VarBinaryVector varBinaryVector) {
	super(varBinaryVector);
}
 
Example #19
Source File: SqlAccessorBuilder.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static SqlAccessor getSqlAccessor(ValueVector vector, TimeZone defaultTz) {
  final MinorType type = org.apache.arrow.vector.types.Types.getMinorTypeForArrowType(vector.getField().getType());
  switch(type){
  case UNION:
    return new UnionSqlAccessor((UnionVector) vector);
  case TINYINT:
    return new TinyIntAccessor((TinyIntVector) vector);
  case UINT1:
    return new UInt1Accessor((UInt1Vector) vector);
  case UINT2:
    return new UInt2Accessor((UInt2Vector) vector);
  case SMALLINT:
    return new SmallIntAccessor((SmallIntVector) vector);
  case INT:
    return new IntAccessor((IntVector) vector);
  case UINT4:
    return new UInt4Accessor((UInt4Vector) vector);
  case FLOAT4:
    return new Float4Accessor((Float4Vector) vector);
  case INTERVALYEAR:
    return new IntervalYearAccessor((IntervalYearVector) vector);
  case TIMEMILLI:
    return new TimeMilliAccessor((TimeMilliVector) vector, defaultTz);
  case BIGINT:
    return new BigIntAccessor((BigIntVector) vector);
  case UINT8:
    return new UInt8Accessor((UInt8Vector) vector);
  case FLOAT8:
    return new Float8Accessor((Float8Vector) vector);
  case DATEMILLI:
    return new DateMilliAccessor((DateMilliVector) vector, defaultTz);
  case TIMESTAMPMILLI:
    return new TimeStampMilliAccessor((TimeStampMilliVector) vector, defaultTz);
  case INTERVALDAY:
    return new IntervalDayAccessor((IntervalDayVector) vector);
  case DECIMAL:
    return new DecimalAccessor((DecimalVector) vector);
  case FIXEDSIZEBINARY:
    return new FixedSizeBinaryAccessor((FixedSizeBinaryVector) vector);
  case VARBINARY:
    return new VarBinaryAccessor((VarBinaryVector) vector);
  case VARCHAR:
    return new VarCharAccessor((VarCharVector) vector);
  case BIT:
    return new BitAccessor((BitVector) vector);
  case STRUCT:
  case LIST:
    return new GenericAccessor(vector);
  }
  throw new UnsupportedOperationException(String.format("Unable to find sql accessor for minor type [%s]", type));
}
 
Example #20
Source File: ArrowUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
public static ArrowFieldReader createRowArrowFieldReader(ValueVector vector, LogicalType fieldType) {
	if (vector instanceof TinyIntVector) {
		return new TinyIntFieldReader((TinyIntVector) vector);
	} else if (vector instanceof SmallIntVector) {
		return new SmallIntFieldReader((SmallIntVector) vector);
	} else if (vector instanceof IntVector) {
		return new IntFieldReader((IntVector) vector);
	} else if (vector instanceof BigIntVector) {
		return new BigIntFieldReader((BigIntVector) vector);
	} else if (vector instanceof BitVector) {
		return new BooleanFieldReader((BitVector) vector);
	} else if (vector instanceof Float4Vector) {
		return new FloatFieldReader((Float4Vector) vector);
	} else if (vector instanceof Float8Vector) {
		return new DoubleFieldReader((Float8Vector) vector);
	} else if (vector instanceof VarCharVector) {
		return new VarCharFieldReader((VarCharVector) vector);
	} else if (vector instanceof VarBinaryVector) {
		return new VarBinaryFieldReader((VarBinaryVector) vector);
	} else if (vector instanceof DecimalVector) {
		return new DecimalFieldReader((DecimalVector) vector);
	} else if (vector instanceof DateDayVector) {
		return new DateFieldReader((DateDayVector) vector);
	} else if (vector instanceof TimeSecVector || vector instanceof TimeMilliVector ||
		vector instanceof TimeMicroVector || vector instanceof TimeNanoVector) {
		return new TimeFieldReader(vector);
	} else if (vector instanceof TimeStampVector && ((ArrowType.Timestamp) vector.getField().getType()).getTimezone() == null) {
		return new TimestampFieldReader(vector);
	} else if (vector instanceof ListVector) {
		ListVector listVector = (ListVector) vector;
		LogicalType elementType = ((ArrayType) fieldType).getElementType();
		return new ArrayFieldReader(listVector,
			createRowArrowFieldReader(listVector.getDataVector(), elementType),
			elementType);
	} else if (vector instanceof StructVector) {
		StructVector structVector = (StructVector) vector;
		ArrowFieldReader[] fieldReaders = new ArrowFieldReader[structVector.size()];
		for (int i = 0; i < fieldReaders.length; i++) {
			fieldReaders[i] = createRowArrowFieldReader(structVector.getVectorById(i), ((RowType) fieldType).getTypeAt(i));
		}
		return new RowFieldReader(structVector, fieldReaders);
	} else {
		throw new UnsupportedOperationException(String.format(
			"Unsupported type %s.", fieldType));
	}
}
 
Example #21
Source File: GeneratedRowWriter.java    From aws-athena-query-federation with Apache License 2.0 4 votes vote down vote up
private FieldWriter makeFieldWriter(FieldVector vector)
{
    Field field = vector.getField();
    String fieldName = field.getName();
    Types.MinorType fieldType = Types.getMinorTypeForArrowType(field.getType());
    Extractor extractor = extractors.get(fieldName);
    ConstraintProjector constraint = constraints.get(fieldName);
    FieldWriterFactory factory = fieldWriterFactories.get(fieldName);

    if (factory != null) {
        return factory.create(vector, extractor, constraint);
    }

    if (extractor == null) {
        throw new IllegalStateException("Missing extractor for field[" + fieldName + "]");
    }

    switch (fieldType) {
        case INT:
            return new IntFieldWriter((IntExtractor) extractor, (IntVector) vector, constraint);
        case BIGINT:
            return new BigIntFieldWriter((BigIntExtractor) extractor, (BigIntVector) vector, constraint);
        case DATEMILLI:
            return new DateMilliFieldWriter((DateMilliExtractor) extractor, (DateMilliVector) vector, constraint);
        case DATEDAY:
            return new DateDayFieldWriter((DateDayExtractor) extractor, (DateDayVector) vector, constraint);
        case TINYINT:
            return new TinyIntFieldWriter((TinyIntExtractor) extractor, (TinyIntVector) vector, constraint);
        case SMALLINT:
            return new SmallIntFieldWriter((SmallIntExtractor) extractor, (SmallIntVector) vector, constraint);
        case FLOAT4:
            return new Float4FieldWriter((Float4Extractor) extractor, (Float4Vector) vector, constraint);
        case FLOAT8:
            return new Float8FieldWriter((Float8Extractor) extractor, (Float8Vector) vector, constraint);
        case DECIMAL:
            return new DecimalFieldWriter((DecimalExtractor) extractor, (DecimalVector) vector, constraint);
        case BIT:
            return new BitFieldWriter((BitExtractor) extractor, (BitVector) vector, constraint);
        case VARCHAR:
            return new VarCharFieldWriter((VarCharExtractor) extractor, (VarCharVector) vector, constraint);
        case VARBINARY:
            return new VarBinaryFieldWriter((VarBinaryExtractor) extractor, (VarBinaryVector) vector, constraint);
        default:
            throw new RuntimeException(fieldType + " is not supported");
    }
}
 
Example #22
Source File: VarBinaryWriter.java    From flink with Apache License 2.0 4 votes vote down vote up
private VarBinaryWriterForRow(VarBinaryVector varBinaryVector) {
	super(varBinaryVector);
}
 
Example #23
Source File: VarBinaryWriter.java    From flink with Apache License 2.0 4 votes vote down vote up
public static VarBinaryWriter<RowData> forRow(VarBinaryVector varBinaryVector) {
	return new VarBinaryWriterForRow(varBinaryVector);
}
 
Example #24
Source File: RowVarBinaryWriter.java    From flink with Apache License 2.0 4 votes vote down vote up
public RowVarBinaryWriter(VarBinaryVector varBinaryVector) {
	super(varBinaryVector);
}
 
Example #25
Source File: ArrowUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
public static ColumnVector createColumnVector(ValueVector vector, LogicalType fieldType) {
	if (vector instanceof TinyIntVector) {
		return new ArrowTinyIntColumnVector((TinyIntVector) vector);
	} else if (vector instanceof SmallIntVector) {
		return new ArrowSmallIntColumnVector((SmallIntVector) vector);
	} else if (vector instanceof IntVector) {
		return new ArrowIntColumnVector((IntVector) vector);
	} else if (vector instanceof BigIntVector) {
		return new ArrowBigIntColumnVector((BigIntVector) vector);
	} else if (vector instanceof BitVector) {
		return new ArrowBooleanColumnVector((BitVector) vector);
	} else if (vector instanceof Float4Vector) {
		return new ArrowFloatColumnVector((Float4Vector) vector);
	} else if (vector instanceof Float8Vector) {
		return new ArrowDoubleColumnVector((Float8Vector) vector);
	} else if (vector instanceof VarCharVector) {
		return new ArrowVarCharColumnVector((VarCharVector) vector);
	} else if (vector instanceof VarBinaryVector) {
		return new ArrowVarBinaryColumnVector((VarBinaryVector) vector);
	} else if (vector instanceof DecimalVector) {
		return new ArrowDecimalColumnVector((DecimalVector) vector);
	} else if (vector instanceof DateDayVector) {
		return new ArrowDateColumnVector((DateDayVector) vector);
	} else if (vector instanceof TimeSecVector || vector instanceof TimeMilliVector ||
		vector instanceof TimeMicroVector || vector instanceof TimeNanoVector) {
		return new ArrowTimeColumnVector(vector);
	} else if (vector instanceof TimeStampVector && ((ArrowType.Timestamp) vector.getField().getType()).getTimezone() == null) {
		return new ArrowTimestampColumnVector(vector);
	} else if (vector instanceof ListVector) {
		ListVector listVector = (ListVector) vector;
		return new ArrowArrayColumnVector(listVector,
			createColumnVector(listVector.getDataVector(), ((ArrayType) fieldType).getElementType()));
	} else if (vector instanceof StructVector) {
		StructVector structVector = (StructVector) vector;
		ColumnVector[] fieldColumns = new ColumnVector[structVector.size()];
		for (int i = 0; i < fieldColumns.length; ++i) {
			fieldColumns[i] = createColumnVector(structVector.getVectorById(i), ((RowType) fieldType).getTypeAt(i));
		}
		return new ArrowRowColumnVector(structVector, fieldColumns);
	} else {
		throw new UnsupportedOperationException(String.format(
			"Unsupported type %s.", fieldType));
	}
}
 
Example #26
Source File: VarBinaryWriter.java    From flink with Apache License 2.0 4 votes vote down vote up
public static VarBinaryWriter<ArrayData> forArray(VarBinaryVector varBinaryVector) {
	return new VarBinaryWriterForArray(varBinaryVector);
}
 
Example #27
Source File: HiveFieldConverter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) {
  final byte[] value = ((BinaryObjectInspector)oi).getPrimitiveJavaObject(hiveFieldValue);
  checkSizeLimit(value.length);
  ((VarBinaryVector) outputVV).setSafe(outputIndex, value, 0, value.length);
}
 
Example #28
Source File: VarBinaryAccessor.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public VarBinaryAccessor(VarBinaryVector vector) {
  this.ac = vector;
}
 
Example #29
Source File: VarBinaryFieldReader.java    From flink with Apache License 2.0 4 votes vote down vote up
public VarBinaryFieldReader(VarBinaryVector varBinaryVector) {
	super(varBinaryVector);
}
 
Example #30
Source File: HiveFieldConverter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) {
  final byte[] value = ((BinaryObjectInspector)oi).getPrimitiveJavaObject(hiveFieldValue);
  checkSizeLimit(value.length);
  ((VarBinaryVector) outputVV).setSafe(outputIndex, value, 0, value.length);
}