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

The following examples show how to use org.apache.arrow.vector.VarBinaryVector#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: 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: 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 3
Source File: VarBinaryToBinaryConverterTest.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<byte[]> expectedValues = new ArrayList<>();
  Set<Integer> nullValIndex = new HashSet<>();
  for (int i = 0; i < rowCount; i++)
  {
    expectedValues.add(RandomStringUtils.random(20).getBytes());
  }

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

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

  VarBinaryVector vector = new VarBinaryVector("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));
    }
  }

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

  for (int i = 0; i < rowCount; i++)
  {
    String stringVal = converter.toString(i);
    Object objectVal = converter.toObject(i);
    byte[] bytesVal = converter.toBytes(i);

    if (nullValIndex.contains(i))
    {
      assertThat(stringVal, is(nullValue()));
      assertThat(objectVal, is(nullValue()));
      assertThat(bytesVal, is(nullValue()));
      assertThat(false, is(converter.toBoolean(i)));
    }
    else
    {
      String base64Expected =
          Base64.getEncoder().encodeToString(expectedValues.get(i));
      assertThat(stringVal, is(base64Expected));
      assertThat(bytesVal, is(expectedValues.get(i)));
      assertThat(objectVal, is(expectedValues.get(i)));
      final int x = i;
      TestUtil.assertSFException(invalidConversionErrorCode,
                                 () -> converter.toBoolean(x));
    }
  }
  vector.clear();
}