Java Code Examples for org.apache.arrow.vector.Float4Vector#allocateNew()

The following examples show how to use org.apache.arrow.vector.Float4Vector#allocateNew() . 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: TestData.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private Pair<Float4Vector, ResultVerifier> testFloat4Vector() {
  final String colName = "colFloat4";
  final List<Float> values = asList(20.0f, 50.023f, -238423f, null, 0f);

  Float4Vector valuesVector = new Float4Vector(colName, allocator);
  valuesVector.allocateNew(values.size());
  for (int i = 0; i < values.size(); i++) {
    if (values.get(i) == null) {
      valuesVector.setNull(i);
    } else {
      valuesVector.set(i, values.get(i));
    }
  }

  ResultVerifier verifier = new ResultVerifier() {
    @Override
    public void verify(DataPOJO output) {
      verifyDoubleValues(values, output, colName, 0.01f);
    }
  };

  return Pair.of(valuesVector, verifier);
}
 
Example 2
Source File: TestArrowFloatConnector.java    From yosegi with Apache License 2.0 5 votes vote down vote up
@Test
public void T_convert_1() throws IOException{
  BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 );
  Float4Vector vector = new Float4Vector( "test" , allocator );
  vector.allocateNew();
  vector.setSafe( 0 , (float)0 ); 
  vector.setSafe( 1 , (float)1 ); 
  vector.setSafe( 2 , (float)0 ); 
  vector.setNull( 3 );
  vector.setSafe( 4 , (float)1 );
  vector.setSafe( 5 , (float)1 );
  vector.setSafe( 6 , (float)1 );
  vector.setNull( 7 );
  vector.setValueCount( 8 );

  IColumn column = ArrowColumnFactory.convert( "test" , vector );
  assertEquals( column.getColumnName() , "test" );
  assertEquals( column.size() , 8 );
  assertTrue( ( column.getColumnType() == ColumnType.FLOAT ) );
  assertEquals( ( (PrimitiveObject)( column.get(0).getRow() ) ).getFloat() , (float)0  );
  assertEquals( ( (PrimitiveObject)( column.get(1).getRow() ) ).getFloat() , (float)1  );
  assertEquals( ( (PrimitiveObject)( column.get(2).getRow() ) ).getFloat() , (float)0  );
  assertEquals( column.get(3).getRow() , null  );
  assertEquals( ( (PrimitiveObject)( column.get(4).getRow() ) ).getFloat() , (float)1 );
  assertEquals( ( (PrimitiveObject)( column.get(5).getRow() ) ).getFloat() , (float)1 );
  assertEquals( ( (PrimitiveObject)( column.get(6).getRow() ) ).getFloat() , (float)1 );
  assertEquals( column.get(7).getRow() , null  );
}
 
Example 3
Source File: TestArrowFloatConnector.java    From multiple-dimension-spread with Apache License 2.0 5 votes vote down vote up
@Test
public void T_convert_1() throws IOException{
  BufferAllocator allocator = new RootAllocator( 1024 * 1024 * 10 );
  Float4Vector vector = new Float4Vector( "test" , allocator );
  vector.allocateNew();
  vector.setSafe( 0 , (float)0 );  
  vector.setSafe( 1 , (float)1 );  
  vector.setSafe( 2 , (float)0 );  
  vector.setNull( 3 );  
  vector.setSafe( 4 , (float)1 );  
  vector.setSafe( 5 , (float)1 );  
  vector.setSafe( 6 , (float)1 );  
  vector.setNull( 7 );  
  vector.setValueCount( 8 );

  IColumn column = ArrowColumnFactory.convert( "test" , vector );
  assertEquals( column.getColumnName() , "test" );
  assertEquals( column.size() , 8 );
  assertTrue( ( column.getColumnType() == ColumnType.FLOAT ) );
  assertEquals( ( (PrimitiveObject)( column.get(0).getRow() ) ).getFloat() , (float)0  );
  assertEquals( ( (PrimitiveObject)( column.get(1).getRow() ) ).getFloat() , (float)1  );
  assertEquals( ( (PrimitiveObject)( column.get(2).getRow() ) ).getFloat() , (float)0  );
  assertEquals( column.get(3).getRow() , null  );
  assertEquals( ( (PrimitiveObject)( column.get(4).getRow() ) ).getFloat() , (float)1 );
  assertEquals( ( (PrimitiveObject)( column.get(5).getRow() ) ).getFloat() , (float)1 );
  assertEquals( ( (PrimitiveObject)( column.get(6).getRow() ) ).getFloat() , (float)1 );
  assertEquals( column.get(7).getRow() , null  );
}
 
Example 4
Source File: Twister2ArrowFileWriter.java    From twister2 with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends FieldVector> void generate(T floatVector1, int from, int items, int isSet) {
  Float4Vector floatVector = (Float4Vector) floatVector1;
  floatVector.setInitialCapacity(items);
  floatVector.allocateNew();
  for (int i = 0; i < items; i++) {
    floatVector.setSafe(i, isSet, (float) dataList.get(from + i));
  }
  floatVector.setValueCount(items);
}
 
Example 5
Source File: GlobalDictionaryBuilder.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static VectorContainer buildFloatGlobalDictionary(List<Dictionary> dictionaries, VectorContainer existingDict, ColumnDescriptor columnDescriptor, BufferAllocator bufferAllocator) {
  final Field field = new Field(SchemaPath.getCompoundPath(columnDescriptor.getPath()).getAsUnescapedPath(), true, new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), null);
  final VectorContainer input = new VectorContainer(bufferAllocator);
  final Float4Vector floatVector = input.addOrGet(field);
  floatVector.allocateNew();
  SortedSet<Float> values = Sets.newTreeSet();
  for (Dictionary dictionary : dictionaries) {
    for (int i = 0; i <= dictionary.getMaxId(); ++i) {
      values.add(dictionary.decodeToFloat(i));
    }
  }
  if (existingDict != null) {
    final Float4Vector existingDictValues = existingDict.getValueAccessorById(Float4Vector.class, 0).getValueVector();
    for (int i = 0; i < existingDict.getRecordCount(); ++i) {
      values.add(existingDictValues.get(i));
    }
  }
  final Iterator<Float> iter = values.iterator();
  int recordCount = 0;
  while (iter.hasNext()) {
    floatVector.setSafe(recordCount++, iter.next());
  }
  floatVector.setValueCount(recordCount);
  input.setRecordCount(recordCount);
  input.buildSchema(BatchSchema.SelectionVectorMode.NONE);
  return input;
}
 
Example 6
Source File: TestVectorizedHashAggPartitionSerializable.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void populateFloat(Float4Vector vector, Float[] data) {
  vector.allocateNew();
  Random r = new Random();
  for(int i =0; i < data.length; i++){
    Float val = data[i];
    if(val != null){
      vector.setSafe(i, val);
    } else {
      vector.setSafe(i, 0, r.nextFloat());
    }
  }
  vector.setValueCount(data.length);
}
 
Example 7
Source File: ArrowFloatMemoryAllocator.java    From yosegi with Apache License 2.0 4 votes vote down vote up
public ArrowFloatMemoryAllocator( final Float4Vector vector , final int rowCount ) {
  vector.allocateNew( rowCount );
  this.vector = vector;
}
 
Example 8
Source File: ArrowFloatMemoryAllocator.java    From multiple-dimension-spread with Apache License 2.0 4 votes vote down vote up
public ArrowFloatMemoryAllocator( final Float4Vector vector , final int rowCount ){
  vector.allocateNew( rowCount );
  this.vector = vector;
}