org.apache.arrow.vector.complex.ListVector Java Examples

The following examples show how to use org.apache.arrow.vector.complex.ListVector. 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: TypeHelper.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public static void loadFromValidityAndDataBuffers(ValueVector v, SerializedField metadata, ArrowBuf dataBuffer,
    ArrowBuf validityBuffer) {
  if (v instanceof ZeroVector) {
    throw new UnsupportedOperationException(String.format("this loader is not supported for vector %s", v));
  } else if (v instanceof UnionVector) {
    throw new UnsupportedOperationException(String.format("this loader is not supported for vector %s", v));
  } else if (v instanceof ListVector) {
    throw new UnsupportedOperationException(String.format("this loader is not supported for vector %s", v));
  } else if (v instanceof StructVector) {
    throw new UnsupportedOperationException(String.format("this loader is not supported for vector %s", v));
  } else if (v instanceof NonNullableStructVector) {
    throw new UnsupportedOperationException(String.format("this loader is not supported for vector %s", v));
  }

  Optional<ValueVectorHelper> helper = getHelper(v);

  if (!helper.isPresent()) {
    throw new UnsupportedOperationException(String.format("no loader for vector %s", v));
  }

  helper.get().loadFromValidityAndDataBuffers(metadata, dataBuffer, validityBuffer);
}
 
Example #2
Source File: TypeHelper.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private static ValueVectorHelper getHelperNull(ValueVector v) {
  if (v instanceof ZeroVector) {
    return new ZeroVectorHelper((ZeroVector) v);
  } else if (v instanceof NullVector) {
    return new NullVectorHelper((NullVector) v);
  } else if (v instanceof UnionVector) {
    return new UnionVectorHelper((UnionVector) v);
  } else if (v instanceof ListVector) {
    return new ListVectorHelper((ListVector) v);
  } else if (v instanceof StructVector) {
    return new StructVectorHelper((StructVector) v);
  } else if (v instanceof NonNullableStructVector) {
    return new NonNullableStructVectorHelper((NonNullableStructVector) v);
  } else if (v instanceof BaseFixedWidthVector) {
    return new FixedWidthVectorHelper<BaseFixedWidthVector>((BaseFixedWidthVector) v);
  } else if (v instanceof BaseVariableWidthVector) {
    return new VariableWidthVectorHelper<BaseVariableWidthVector>((BaseVariableWidthVector) v);
  }

  return null;
}
 
Example #3
Source File: HiveParquetCopier.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public ListCopier(OperatorContext context, ValueVector in, ValueVector out,
                  TypeCoercion hiveTypeCoercion,
                  Stopwatch javaCodeGenWatch, Stopwatch gandivaCodeGenWatch) {
  inVector = (ListVector)in;
  outVector = (ListVector)out;

  //create a mutator for output child field vector
  outChildMutator = createChildMutator(context, outVector.getDataVector());

  // construct mutator for input child field vector
  inChildMutator = createChildMutator(context, inVector.getDataVector());

  // construct schema containing only child field
  BatchSchema targetSchema = outChildMutator.getContainer().getSchema();

  // recursively setup hive parquet reader for child vector
  childFieldParquetReader = new HiveParquetReader(inChildMutator,
    context, targetSchema.getFields().stream().map(f -> SchemaPath.getSimplePath(f.getName())).collect(Collectors.toList()),
    hiveTypeCoercion.getChildTypeCoercion(out.getName(), targetSchema),
    javaCodeGenWatch, gandivaCodeGenWatch,
    targetSchema);
}
 
Example #4
Source File: RepeatedVarCharOutput.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
/**
 * This method is a helper method added for DRILL-951
 * TextRecordReader to call this method to get field names out
 * @return array of field data strings
 */
public String [] getTextOutput () throws ExecutionSetupException {
  if (recordCount == 0 || fieldIndex == -1) {
    return null;
  }

  //Currently only first line header is supported. Return only first record.
  int retSize = fieldIndex+1;
  String [] out = new String [retSize];

  try {
    ListVector listVector = output.addField(new Field(COL_NAME, true, MinorType.LIST.getType(), null), ListVector.class);
    List outputlist = (List) listVector.getObject((int)(recordCount-1));

    for (int i=0; i<retSize; i++){
      out[i] = ((Text) outputlist.get(i)).toString();
    }
    return out;
  } catch (SchemaChangeException e) {
    throw new ExecutionSetupException(e);
  }
}
 
Example #5
Source File: Fixtures.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void set(ValueVector v, int index) {
  this.dataVector = ((ListVector)v).getDataVector();
  if(obj != null){
    UnionListWriter listWriter = ((ListVector)v).getWriter();
    listWriter.setPosition(index);
    List<Integer> list = obj;
    listWriter.startList();
    for (int i = 0; i < list.size(); i++) {
      listWriter.bigInt().writeBigInt(list.get(i));
    }
    listWriter.endList();
  }
}
 
Example #6
Source File: HiveParquetCopier.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * internal routine that pairs invector and outvector and returns a copier
 */
private static ParquetCopier createCopier(OperatorContext context, ValueVector inVector,
                                          ValueVector outVector,
                                          TypeCoercion hiveTypeCoercion,
                                          Stopwatch javaCodeGenWatch, Stopwatch gandivaCodeGenWatch) {
  Preconditions.checkArgument(outVector != null, "invalid argument");
  if (inVector == null) {
    // it is possible that table has extra fields and parquet file may not have those fields
    return new NoOpCopier();
  }

  // ListVector can be mapped to only ListVector
  if (outVector instanceof ListVector && inVector instanceof ListVector) {
      // return list copier
      return new ListCopier(context, inVector, outVector,
        hiveTypeCoercion, javaCodeGenWatch, gandivaCodeGenWatch);
  }

  // StructVector can be mapped to only StructVector
  if (outVector instanceof StructVector && inVector instanceof StructVector) {
      // return struct copier
      return new StructCopier(context, inVector, outVector,
        hiveTypeCoercion, javaCodeGenWatch, gandivaCodeGenWatch);
  }

  // control should not reach this place because of schema validation
  // that happens at the beginning of reader setup
  // returning NoOpCopier as a conservative measure, which results in null values
  return new NoOpCopier();
}
 
Example #7
Source File: HiveParquetCopier.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
ListCopier(ValueVector in, ValueVector out) {
  inVector = (ListVector)in;
  outVector = (ListVector)out;
  childFieldParquetReader = null;
  outChildMutator = null;
  inChildMutator = null;
}
 
Example #8
Source File: HiveParquetCopier.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(int count) {
  copyNonDataBufferRefs(count);

  // Now handle child field copy
  if (count > 0) {
    int childCount = outVector.getOffsetBuffer().getInt(count * ListVector.OFFSET_WIDTH);
    runProjector(childCount, inChildMutator.getContainer());
  }
}
 
Example #9
Source File: TestJsonReader.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void testExistentColumns(RecordBatchLoader batchLoader) throws SchemaChangeException {
  VectorWrapper<?> vw = batchLoader.getValueAccessorById(
      ListVector.class, //
      batchLoader.getValueVectorId(SchemaPath.getCompoundPath("field_1")).getFieldIds() //
  );
  assertEquals("[1]", vw.getValueVector().getObject(0).toString());
  assertEquals("[5]", vw.getValueVector().getObject(1).toString());
  assertEquals("[5,10,15]", vw.getValueVector().getObject(2).toString());

  vw = batchLoader.getValueAccessorById(
      IntVector.class, //
      batchLoader.getValueVectorId(SchemaPath.getCompoundPath("field_3", "inner_1")).getFieldIds() //
  );
  assertNull(vw.getValueVector().getObject(0));
  assertEquals(2l, vw.getValueVector().getObject(1));
  assertEquals(5l, vw.getValueVector().getObject(2));

  vw = batchLoader.getValueAccessorById(
      IntVector.class, //
      batchLoader.getValueVectorId(SchemaPath.getCompoundPath("field_3", "inner_2")).getFieldIds() //
  );
  assertNull(vw.getValueVector().getObject(0));
  assertNull(vw.getValueVector().getObject(1));
  assertEquals(3l, vw.getValueVector().getObject(2));

  vw = batchLoader.getValueAccessorById(
      ListVector.class, //
      batchLoader.getValueVectorId(SchemaPath.getCompoundPath("field_4", "inner_1")).getFieldIds() //
  );
  assertEquals("[1,2,3]", vw.getValueVector().getObject(1).toString());
  assertEquals("[4,5,6]", vw.getValueVector().getObject(2).toString());
}
 
Example #10
Source File: HiveParquetCopierTest.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void testListCopier() {
  int rowcount = 5000;
  try (final ListVector l1 = new ListVector("colList", allocator, null);
       final ListVector l2 = new ListVector("colList", allocator, null);
       final ArrowBuf tempBuf = allocator.buffer(rowcount * 16)) {
    l1.allocateNew();
    UnionListWriter listWriter = new UnionListWriter(l1);
    for (int i = 0; i < rowcount; i++) {
      if (i % 10 == 0) {
        continue;
      }
      listWriter.setPosition(i);
      listWriter.startList();
      for (int j = 0; j < i; j++) {
        byte[] varCharVal = String.format("%d", (i%10)).getBytes();
        tempBuf.setBytes(0, varCharVal);
        listWriter.writeVarChar(0, varCharVal.length, tempBuf);
      }
      listWriter.endList();
    }
    l1.setValueCount(rowcount);
    HiveParquetCopier.ListCopier listCopier = new HiveParquetCopier.ListCopier(l1, l2);
    listCopier.copyNonDataBufferRefs(rowcount);
    Assert.assertEquals(rowcount, l2.getValueCount());
    Assert.assertEquals(500, l1.getNullCount());
    Assert.assertEquals(500, l2.getNullCount());
    for(int i=0; i<rowcount; ++i) {
      Assert.assertEquals( i % 10 == 0, l2.isNull(i));
      Assert.assertEquals(i % 10 == 0 ? 0 : i,
        l2.getOffsetBuffer().getInt((i+1) * ListVector.OFFSET_WIDTH) -
          l2.getOffsetBuffer().getInt(i * ListVector.OFFSET_WIDTH));
    }
  }
}
 
Example #11
Source File: ArrowArrayColumnVector.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public ArrayData getArray(int i) {
	int index = i * ListVector.OFFSET_WIDTH;
	int start = listVector.getOffsetBuffer().getInt(index);
	int end = listVector.getOffsetBuffer().getInt(index + ListVector.OFFSET_WIDTH);
	return new ColumnarArrayData(elementVector, start, end - start);
}
 
Example #12
Source File: ArrayFieldReader.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Object[] read(int index) {
	if (getValueVector().isNull(index)) {
		return null;
	} else {
		int startIndex = index * ListVector.OFFSET_WIDTH;
		int start = getValueVector().getOffsetBuffer().getInt(startIndex);
		int end = getValueVector().getOffsetBuffer().getInt(startIndex + ListVector.OFFSET_WIDTH);
		Object[] result = (Object[]) Array.newInstance(elementClass, end - start);
		for (int i = 0; i < result.length; i++) {
			result[i] = arrayData.read(start + i);
		}
		return result;
	}
}
 
Example #13
Source File: TestArrowFileReader.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Test
public void writeAndReadEmptyListVectors() throws Exception {
  try (final BufferAllocator allocator = allocatorRule.newAllocator("test-arrow-file-reader", 0, Long.MAX_VALUE);
       final VectorContainer batchData = createBatch(1, testEmptyListVector(allocator))) {

    final Path basePath = new Path(dateGenFolder.getRoot().getPath());
    final ArrowFileMetadata metadata = writeArrowFile(batchData);
    try (final ArrowFileReader reader =
             new ArrowFileReader(HadoopFileSystem.getLocal(FS_CONF), com.dremio.io.file.Path.of(basePath.toUri()), metadata, allocator)) {

      final List<RecordBatchHolder> batchHolders = reader.read(0, 1);
      assertEquals(1, batchHolders.size());
      assertNotNull(batchHolders.get(0).getData());
      assertEquals(0, batchHolders.get(0).getStart());
      assertEquals(1, batchHolders.get(0).getEnd());

      final BatchSchema schema = batchHolders.get(0).getData().getContainer().getSchema();
      assertEquals(1, schema.getFieldCount());
      assertEquals("emptyListVector", schema.getColumn(0).getName());
      assertEquals(MinorType.LIST, Types.getMinorTypeForArrowType(schema.getColumn(0).getType()));

      final VectorContainer batchContainer = batchHolders.get(0).getData().getContainer();
      assertTrue(Iterators.size(batchContainer.iterator()) == 1);
      for (final VectorWrapper<?> wrapper : batchContainer) {
        assertTrue(wrapper.getValueVector() instanceof ListVector);
        assertTrue(((ListVector) (wrapper.getValueVector())).getDataVector() instanceof NullVector);
      }

      releaseBatches(batchHolders);
    }
  }
}
 
Example #14
Source File: TestArrowFileReader.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/** Helper method which creates a empty list vector */
private static ListVector testEmptyListVector(BufferAllocator allocator) {
  final ListVector vector =
      new ListVector("emptyListVector", allocator, FieldType.nullable(ArrowType.Null.INSTANCE), null);
  vector.allocateNew();
  return vector;
}
 
Example #15
Source File: SplitPattern.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public CompleteType getOutputType(CompleteType baseReturn, List<LogicalExpression> args) {
  return new CompleteType(
      ArrowType.List.INSTANCE,
      CompleteType.VARCHAR.toField(ListVector.DATA_VECTOR_NAME)
  );
}
 
Example #16
Source File: DremioUDFUtils.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public CompleteType getOutputType(CompleteType baseReturn, List<LogicalExpression> args) {
  return new CompleteType(
      ArrowType.List.INSTANCE,
      new CompleteType(
          ArrowType.Struct.INSTANCE,
          CompleteType.INT.toField(OFFSET_FIELD),
          CompleteType.INT.toField(LENGTH_FIELD)
      ).toField(ListVector.DATA_VECTOR_NAME)
  );
}
 
Example #17
Source File: TestData.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static Pair<ListVector, ResultVerifier> testListVector(final int startIndexInCurrentOutput, final int startIndexInJob) {
  ListVector colListV = new ListVector("colList", allocator, null);

  colListV.allocateNew();
  UnionListWriter listWriter = new UnionListWriter(colListV);
  for(int i=0; i<5; i++) {
    listWriter.setPosition(i);
    listWriter.startList();
    for(int j=0; j<5; j++) {
      byte[] varCharVal = String.format("item %d-%d", i, j).getBytes();
      tempBuf.setBytes(0, varCharVal);
      listWriter.writeVarChar(0, varCharVal.length, tempBuf);
    }
    listWriter.endList();
  }

  ResultVerifier verifier = new ResultVerifier() {
    @Override
    public void verify(DataPOJO output) {
      int index = startIndexInCurrentOutput;
      int uIndex = startIndexInJob;
      assertEquals("[item 0-0, item 0-1, item 0-2, item 0]", output.extractValue("colList", index).toString());
      assertEquals(cellUrl(uIndex++, "colList"), output.extractUrl("colList", index++));

      assertEquals("[item 1-0, item 1-1, item 1-2, item 1]", output.extractValue("colList", index).toString());
      assertEquals(cellUrl(uIndex++, "colList"), output.extractUrl("colList", index++));

      assertEquals("[item 2-0, item 2-1, item 2-2, item 2]", output.extractValue("colList", index).toString());
      assertEquals(cellUrl(uIndex++, "colList"), output.extractUrl("colList", index++));

      assertEquals("[item 3-0, item 3-1, item 3-2, item 3]", output.extractValue("colList", index).toString());
      assertEquals(cellUrl(uIndex++, "colList"), output.extractUrl("colList", index++));

      assertEquals("[item 4-0, item 4-1, item 4-2, item 4]", output.extractValue("colList", index).toString());
      assertEquals(cellUrl(uIndex++, "colList"), output.extractUrl("colList", index));
    }
  };

  return Pair.of(colListV, verifier);
}
 
Example #18
Source File: HiveORCCopiers.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(int inputIdx, int count, int outputIdx) {
  ensureHasRequiredCapacity(outputIdx + count);
  final ArrowBuf offsetBuffer = outputVector.getOffsetBuffer();
  int nextOffset = (outputIdx == 0) ? 0 : offsetBuffer.getInt(outputIdx * ListVector.OFFSET_WIDTH);

  //count the number of children that need to be skipped
  int childInputIdx = (int)countChildren(inputVector.noNulls, inputVector.lengths, 0, inputIdx);

  //count the number of children that need to be copied
  int childCount = (int)countChildren(inputVector.noNulls, inputVector.lengths, inputIdx, count);

  if (outputIdx == 0) {
    childOutputIdx = 0;
  }

  childCopier.copy(childInputIdx, childCount, childOutputIdx);
  childOutputIdx += childCount;

  for(int idx=0; idx<count; ++idx) {
    if (inputVector.isNull[inputIdx + idx]) {
      offsetBuffer.setInt((outputIdx + idx) * ListVector.OFFSET_WIDTH, nextOffset);
    } else {
      offsetBuffer.setInt((outputIdx + idx) * ListVector.OFFSET_WIDTH, nextOffset);
      nextOffset += (int)inputVector.lengths[inputIdx + idx];
      outputVector.setNotNull(outputIdx + idx);
    }
  }
  offsetBuffer.setInt((outputIdx + count) * ListVector.OFFSET_WIDTH, nextOffset);
}
 
Example #19
Source File: HiveORCCopiers.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void copy(int inputIdx, int count, int outputIdx) {
  ensureHasRequiredCapacity(outputIdx + count);
  final ArrowBuf offsetBuffer = outputVector.getOffsetBuffer();
  int nextOffset = (outputIdx == 0) ? 0 : offsetBuffer.getInt(outputIdx * ListVector.OFFSET_WIDTH);

  //count the number of children that need to be skipped
  int childInputIdx = (int)countChildren(inputVector.noNulls, inputVector.lengths, 0, inputIdx);

  //count the number of children that need to be copied
  int childCount = (int)countChildren(inputVector.noNulls, inputVector.lengths, inputIdx, count);

  if (outputIdx == 0) {
    childOutputIdx = 0;
  }

  childCopier.copy(childInputIdx, childCount, childOutputIdx);
  childOutputIdx += childCount;

  for(int idx=0; idx<count; ++idx) {
    if (inputVector.isNull[inputIdx + idx]) {
      offsetBuffer.setInt((outputIdx + idx) * ListVector.OFFSET_WIDTH, nextOffset);
    } else {
      offsetBuffer.setInt((outputIdx + idx) * ListVector.OFFSET_WIDTH, nextOffset);
      nextOffset += (int)inputVector.lengths[inputIdx + idx];
      outputVector.setNotNull(outputIdx + idx);
    }
  }
  offsetBuffer.setInt((outputIdx + count) * ListVector.OFFSET_WIDTH, nextOffset);
}
 
Example #20
Source File: TestArrowArrayMemoryAllocator.java    From multiple-dimension-spread with Apache License 2.0 5 votes vote down vote up
@Test
public void T_setArray_1() throws IOException{
  IColumn column = new ArrayColumn( "array" );
  List<Object> value = new ArrayList<Object>();
  value.add( new StringObj( "a" ) );
  value.add( new StringObj( "b" ) );
  value.add( new StringObj( "c" ) );
  column.add( ColumnType.ARRAY , value , 0 );
  column.add( ColumnType.ARRAY , value , 1 );
  column.add( ColumnType.ARRAY , value , 2 );
  column.add( ColumnType.ARRAY , value , 3 );
  column.add( ColumnType.ARRAY , value , 6 );

  ColumnBinaryMakerConfig defaultConfig = new ColumnBinaryMakerConfig();
  ColumnBinaryMakerCustomConfigNode configNode = new ColumnBinaryMakerCustomConfigNode( "root" , defaultConfig );

  IColumnBinaryMaker maker = new DumpArrayColumnBinaryMaker();
  ColumnBinary columnBinary = maker.toBinary( defaultConfig , null , column );

  BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 );
  SchemaChangeCallBack callBack = new SchemaChangeCallBack();
  StructVector parent = new StructVector("root", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack);
  parent.allocateNew();

  ListVector listVector = parent.addOrGetList( "target" );
  IMemoryAllocator memoryAllocator = new ArrowArrayMemoryAllocator( allocator , listVector , 7 );
  maker.loadInMemoryStorage( columnBinary , memoryAllocator );

  for( int i = 0 ; i < 7 ; i++ ){
    System.out.println( "count:" + listVector.getInnerValueCountAt(i) );
    System.out.println( "obj:" + listVector.getObject(i) );
  }
}
 
Example #21
Source File: ArrowFixedSchemaArrayMemoryAllocator.java    From yosegi with Apache License 2.0 5 votes vote down vote up
/**
 * Set the vector of Array and initialize it.
 */
public ArrowFixedSchemaArrayMemoryAllocator(
    final ArrayContainerField schema ,
    final BufferAllocator allocator ,
    final ListVector vector , final int rowCount ) {
  this.allocator = allocator;
  this.vector = vector;
  vector.allocateNew();
  childSchema = schema.getField();
}
 
Example #22
Source File: ArrowFixedSchemaMemoryAllocatorFactory.java    From multiple-dimension-spread with Apache License 2.0 5 votes vote down vote up
public static IMemoryAllocator getFromListVector( final IField schema , final String columnName , final BufferAllocator allocator , final ListVector vector , final int rowCount ) throws IOException{
  switch( schema.getFieldType() ){
    case UNION:
      return NullMemoryAllocator.INSTANCE;
    case ARRAY:
      AddOrGetResult<ListVector> listVector =  vector.addOrGetVector( new FieldType( true , ArrowType.List.INSTANCE , null , null ) );
      return new ArrowFixedSchemaArrayMemoryAllocator( (ArrayContainerField)schema , allocator , listVector.getVector() , rowCount );
    case MAP:
      AddOrGetResult<StructVector> mapVector =  vector.addOrGetVector( new FieldType( true , ArrowType.Struct.INSTANCE , null , null ) );
      return new ArrowFixedSchemaMapMemoryAllocator( (MapContainerField)schema , allocator , mapVector.getVector() , rowCount );
    case STRUCT:
      AddOrGetResult<StructVector> structVector =  vector.addOrGetVector( new FieldType( true , ArrowType.Struct.INSTANCE , null , null ) );
      return new ArrowFixedSchemaStructMemoryAllocator( (StructContainerField)schema , allocator , structVector.getVector() , rowCount );

    case BOOLEAN:
      return ArrowMemoryAllocatorFactory.getFromListVector( ColumnType.BOOLEAN , columnName ,  allocator , vector , rowCount );
    case BYTE:
      return ArrowMemoryAllocatorFactory.getFromListVector( ColumnType.BYTE , columnName ,  allocator , vector , rowCount );
    case SHORT:
      return ArrowMemoryAllocatorFactory.getFromListVector( ColumnType.SHORT , columnName ,  allocator , vector , rowCount );
    case INTEGER:
      return ArrowMemoryAllocatorFactory.getFromListVector( ColumnType.INTEGER , columnName ,  allocator , vector , rowCount );
    case LONG:
      return ArrowMemoryAllocatorFactory.getFromListVector( ColumnType.LONG , columnName ,  allocator , vector , rowCount );
    case FLOAT:
      return ArrowMemoryAllocatorFactory.getFromListVector( ColumnType.FLOAT , columnName ,  allocator , vector , rowCount );
    case DOUBLE:
      return ArrowMemoryAllocatorFactory.getFromListVector( ColumnType.DOUBLE , columnName ,  allocator , vector , rowCount );
    case STRING:
      return ArrowMemoryAllocatorFactory.getFromListVector( ColumnType.STRING , columnName ,  allocator , vector , rowCount );
    case BYTES:
      return ArrowMemoryAllocatorFactory.getFromListVector( ColumnType.BYTES , columnName ,  allocator , vector , rowCount );

    default:
      return NullMemoryAllocator.INSTANCE;
  }
}
 
Example #23
Source File: RowArrayWriter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void doWrite(Row row, int ordinal) {
	Object field = row.getField(ordinal);
	if (field != null) {
		((ListVector) getValueVector()).startNewValue(getCount());
		Object[] array = (Object[]) field;
		for (Object element : array) {
			elementWriter.write(Row.of(element), 0);
		}
		((ListVector) getValueVector()).endValue(getCount(), array.length);
	}
}
 
Example #24
Source File: ArrowVectorAccessors.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Override
final ColumnarArray getArray(int rowId) {
  ArrowBuf offsets = vector.getOffsetBuffer();
  int index = rowId * ListVector.OFFSET_WIDTH;
  int start = offsets.getInt(index);
  int end = offsets.getInt(index + ListVector.OFFSET_WIDTH);
  return new ColumnarArray(arrayData, start, end - start);
}
 
Example #25
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 #26
Source File: FlightArrowColumnVector.java    From flight-spark-source with Apache License 2.0 5 votes vote down vote up
@Override
final ColumnarArray getArray(int rowId) {
  ArrowBuf offsets = accessor.getOffsetBuffer();
  int index = rowId * ListVector.OFFSET_WIDTH;
  int start = offsets.getInt(index);
  int end = offsets.getInt(index + ListVector.OFFSET_WIDTH);
  return new ColumnarArray(arrayData, start, end - start);
}
 
Example #27
Source File: ArrayWriter.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)) {
		((ListVector) getValueVector()).startNewValue(getCount());
		ArrayData array = readArray(in, ordinal);
		for (int i = 0; i < array.size(); i++) {
			elementWriter.write(array, i);
		}
		((ListVector) getValueVector()).endValue(getCount(), array.size());
	}
}
 
Example #28
Source File: ArrowArrayMemoryAllocator.java    From yosegi with Apache License 2.0 5 votes vote down vote up
/**
 * Set the vector of Array and initialize it.
 */
public ArrowArrayMemoryAllocator(
    final BufferAllocator allocator , final ListVector vector , final int rowCount ) {
  this.allocator = allocator;
  this.vector = vector;
  vector.allocateNew();
}
 
Example #29
Source File: TestArrowArrayMemoryAllocator.java    From yosegi with Apache License 2.0 5 votes vote down vote up
@Test
public void T_setArray_1() throws IOException{
  IColumn column = new ArrayColumn( "array" );
  List<Object> value = new ArrayList<Object>();
  value.add( new StringObj( "a" ) );
  value.add( new StringObj( "b" ) );
  value.add( new StringObj( "c" ) );
  column.add( ColumnType.ARRAY , value , 0 );
  column.add( ColumnType.ARRAY , value , 1 );
  column.add( ColumnType.ARRAY , value , 2 );
  column.add( ColumnType.ARRAY , value , 3 );
  column.add( ColumnType.ARRAY , value , 6 );

  ColumnBinaryMakerConfig defaultConfig = new ColumnBinaryMakerConfig();
  ColumnBinaryMakerCustomConfigNode configNode = new ColumnBinaryMakerCustomConfigNode( "root" , defaultConfig );

  IColumnBinaryMaker maker = new DumpArrayColumnBinaryMaker();
  ColumnBinary columnBinary = maker.toBinary( defaultConfig , null , new CompressResultNode() , column );

  BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 );
  SchemaChangeCallBack callBack = new SchemaChangeCallBack();
  StructVector parent = new StructVector("root", allocator, new FieldType(false, Struct.INSTANCE, null, null), callBack);
  parent.allocateNew();

  ListVector listVector = parent.addOrGetList( "target" );
  IMemoryAllocator memoryAllocator = new ArrowArrayMemoryAllocator( allocator , listVector , 7 );
  maker.loadInMemoryStorage( columnBinary , memoryAllocator );

  for( int i = 0 ; i < 7 ; i++ ){
    System.out.println( "count:" + listVector.getInnerValueCountAt(i) );
    System.out.println( "obj:" + listVector.getObject(i) );
  }
}
 
Example #30
Source File: ArrayWriter.java    From flink with Apache License 2.0 4 votes vote down vote up
private ArrayWriterForArray(ListVector listVector, ArrowFieldWriter<ArrayData> elementWriter) {
	super(listVector, elementWriter);
}