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

The following examples show how to use org.apache.arrow.vector.Float4Vector#setSafe() . 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: 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 2
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 3
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 4
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 5
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 6
Source File: UserDefinedFunctionHandlerTest.java    From aws-athena-query-federation with Apache License 2.0 4 votes vote down vote up
private void writeColumn(FieldVector fieldVector, int idx)
{
    if (fieldVector instanceof IntVector) {
        IntVector intVector = (IntVector) fieldVector;
        intVector.setSafe(idx, idx + 100);
        return;
    }

    if (fieldVector instanceof Float4Vector) {
        Float4Vector float4Vector = (Float4Vector) fieldVector;
        float4Vector.setSafe(idx, idx + 100.1f);
        return;
    }

    if (fieldVector instanceof Float8Vector) {
        Float8Vector float8Vector = (Float8Vector) fieldVector;
        float8Vector.setSafe(idx, idx + 100.2);
        return;
    }

    if (fieldVector instanceof VarCharVector) {
        VarCharVector varCharVector = (VarCharVector) fieldVector;
        varCharVector.setSafe(idx, new Text(idx + "-my-varchar"));
        return;
    }

    if (fieldVector instanceof ListVector) {
        BlockUtils.setComplexValue(fieldVector,
                idx,
                FieldResolver.DEFAULT,
                ImmutableList.of(idx + 100, idx + 200, idx + 300));
        return;
    }

    if (fieldVector instanceof StructVector) {
        Map<String, Object> input = ImmutableMap.of("intVal", idx + 100, "doubleVal", idx + 200.2);
        BlockUtils.setComplexValue(fieldVector,
                idx,
                FieldResolver.DEFAULT,
                input);
        return;
    }

    throw new IllegalArgumentException("Unsupported fieldVector " + fieldVector.getClass().getCanonicalName());
}