Java Code Examples for org.apache.arrow.vector.BitVector#setNull()

The following examples show how to use org.apache.arrow.vector.BitVector#setNull() . 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 static Pair<BitVector, ResultVerifier> testBitVector(final int startIndexInCurrentOutput, final int startIndexInJob) {
  BitVector colBitV = new BitVector("colBit", allocator);
  colBitV.allocateNew(5);
  colBitV.set(0, 1);
  colBitV.set(1, 0);
  colBitV.setNull(2);
  colBitV.set(3, 1);
  colBitV.set(4, 1);

  ResultVerifier verifier = new ResultVerifier() {
    @Override
    public void verify(DataPOJO output) {
      int index = startIndexInCurrentOutput;
      assertTrue((Boolean)output.extractValue("colBit", index++));
      assertFalse((Boolean)output.extractValue("colBit", index++));
      assertNull(output.extractValue("colBit", index++));
      assertTrue((Boolean)output.extractValue("colBit", index++));
      assertTrue((Boolean)output.extractValue("colBit", index));
    }
  };

  return Pair.of(colBitV, verifier);
}
 
Example 2
Source File: TestArrowBooleanConnector.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 );
  BitVector vector = new BitVector( "test" , allocator );
  vector.allocateNew();
  vector.setSafe( 0 , 0 );
  vector.setSafe( 1 , 1 );
  vector.setSafe( 2 , 0 );
  vector.setNull( 3 );
  vector.setSafe( 4 , 1 );
  vector.setSafe( 5 , 1 );
  vector.setSafe( 6 , 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.BOOLEAN ) );
  assertEquals( ( (PrimitiveObject)( column.get(0).getRow() ) ).getBoolean() , false  );
  assertEquals( ( (PrimitiveObject)( column.get(1).getRow() ) ).getBoolean() , true  );
  assertEquals( ( (PrimitiveObject)( column.get(2).getRow() ) ).getBoolean() , false  );
  assertEquals( column.get(3).getRow() , null  );
  assertEquals( ( (PrimitiveObject)( column.get(4).getRow() ) ).getBoolean() , true  );
  assertEquals( ( (PrimitiveObject)( column.get(5).getRow() ) ).getBoolean() , true  );
  assertEquals( ( (PrimitiveObject)( column.get(6).getRow() ) ).getBoolean() , true  );
  assertEquals( column.get(7).getRow() , null  );
}
 
Example 3
Source File: TestArrowBooleanConnector.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 );
  BitVector vector = new BitVector( "test" , allocator );
  vector.allocateNew();
  vector.setSafe( 0 , 0 );  
  vector.setSafe( 1 , 1 );  
  vector.setSafe( 2 , 0 );  
  vector.setNull( 3 );  
  vector.setSafe( 4 , 1 );  
  vector.setSafe( 5 , 1 );  
  vector.setSafe( 6 , 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.BOOLEAN ) );
  assertEquals( ( (PrimitiveObject)( column.get(0).getRow() ) ).getBoolean() , false  );
  assertEquals( ( (PrimitiveObject)( column.get(1).getRow() ) ).getBoolean() , true  );
  assertEquals( ( (PrimitiveObject)( column.get(2).getRow() ) ).getBoolean() , false  );
  assertEquals( column.get(3).getRow() , null  );
  assertEquals( ( (PrimitiveObject)( column.get(4).getRow() ) ).getBoolean() , true  );
  assertEquals( ( (PrimitiveObject)( column.get(5).getRow() ) ).getBoolean() , true  );
  assertEquals( ( (PrimitiveObject)( column.get(6).getRow() ) ).getBoolean() , true  );
  assertEquals( column.get(7).getRow() , null  );
}
 
Example 4
Source File: TestQueryReAttempt.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private BitVector bitVector(String name) {
  BitVector vec = new BitVector(name, getAllocator());
  vec.allocateNew(COUNT);
  vec.set(0, 1);
  vec.set(1, 0);
  vec.setNull(2);
  vec.set(3, 1);
  vec.set(4, 1);

  vec.setValueCount(COUNT);
  return vec;
}
 
Example 5
Source File: TestArrowFileReader.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/** Helper method which creates a test bit vector */
private static BitVector testBitVector(BufferAllocator allocator) {
  BitVector colBitV = new BitVector("colBit", allocator);
  colBitV.allocateNew(5);
  for(int i=0; i<TEST_BIT_VALUES.size(); i++) {
    if (TEST_BIT_VALUES.get(i) == null) {
      colBitV.setNull(i);
    } else {
      colBitV.set(i, TEST_BIT_VALUES.get(i) ? 1 : 0);
    }
  }

  return colBitV;
}
 
Example 6
Source File: BitToBooleanConverterTest.java    From snowflake-jdbc with Apache License 2.0 4 votes vote down vote up
@Test
public void testConvertToString() throws SFException
{
  final int rowCount = 1000;
  List<Boolean> expectedValues = new ArrayList<>();
  Set<Integer> nullValIndex = new HashSet<>();
  for (int i = 0; i < rowCount; i++)
  {
    expectedValues.add(random.nextBoolean());
  }

  Map<String, String> customFieldMeta = new HashMap<>();
  customFieldMeta.put("logicalType", "BOOLEAN");

  FieldType fieldType = new FieldType(true,
                                      Types.MinorType.BIT.getType(),
                                      null, customFieldMeta);

  BitVector vector = new BitVector("col_one", fieldType,
                                   allocator);
  for (int i = 0; i < rowCount; i++)
  {
    boolean isNull = random.nextBoolean();
    if (isNull)
    {
      vector.setNull(i);
      nullValIndex.add(i);
    }
    else
    {
      vector.setSafe(i, expectedValues.get(i) ? 1 : 0);
    }
  }

  ArrowVectorConverter converter = new BitToBooleanConverter(vector, 0, this);

  for (int i = 0; i < rowCount; i++)
  {
    boolean boolVal = converter.toBoolean(i);
    Object objectVal = converter.toObject(i);
    String stringVal = converter.toString(i);

    if (nullValIndex.contains(i))
    {
      assertThat(boolVal, is(false));
      assertThat(objectVal, is(nullValue())); // current behavior
      assertThat(stringVal, is(nullValue())); // current behavior
      assertThat(converter.toBytes(i), is(nullValue()));
    }
    else
    {
      assertThat(boolVal, is(expectedValues.get(i)));
      assertThat(objectVal, is(expectedValues.get(i)));
      assertThat(stringVal, is(expectedValues.get(i).toString().toUpperCase()));
      if (boolVal)
      {
        assertThat((byte) 0x1, is(converter.toBytes(i)[0]));
      }
      else
      {
        assertThat((byte) 0x0, is(converter.toBytes(i)[0]));
      }
    }
  }
  vector.clear();
}