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

The following examples show how to use org.apache.arrow.vector.VarCharVector#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(VarCharVector 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: VarCharConverterTest.java    From snowflake-jdbc with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetBoolean() throws SFException
{
  Map<String, String> customFieldMeta = new HashMap<>();
  customFieldMeta.put("logicalType", "FIXED");

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

  VarCharVector vector = new VarCharVector("col_one", fieldType, allocator);
  vector.setSafe(0, "0".getBytes(StandardCharsets.UTF_8));
  vector.setSafe(1, "1".getBytes(StandardCharsets.UTF_8));
  vector.setNull(2);
  vector.setSafe(3, "5".getBytes(StandardCharsets.UTF_8));

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

  assertThat(false, is(converter.toBoolean(0)));
  assertThat(true, is(converter.toBoolean(1)));
  assertThat(false, is(converter.toBoolean(2)));
  TestUtil.assertSFException(invalidConversionErrorCode,
                             () -> converter.toBoolean(3));

  vector.close();
}
 
Example 3
Source File: TestArrowFileReader.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/** Helper method which creates a test varchar vector */
private static VarCharVector testVarCharVector(BufferAllocator allocator) {
  VarCharVector colVarCharV = new VarCharVector("colVarChar", allocator);
  colVarCharV.allocateNew(500, 5);
  for(int i=0; i<TEST_VARCHAR_VALUES.size(); i++) {
    if (TEST_VARCHAR_VALUES.get(i) == null) {
      colVarCharV.setNull(i);
    } else {
      colVarCharV.set(i, TEST_VARCHAR_VALUES.get(i).getBytes());
    }
  }

  return colVarCharV;
}
 
Example 4
Source File: TestData.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private static Pair<VarCharVector, ResultVerifier> testVarCharVector(final int startIndexInCurrentOutput, final int startIndexInJob) {
  VarCharVector colVarCharV = new VarCharVector("colVarChar", allocator);
  colVarCharV.allocateNew(500, 5);
  colVarCharV.set(0, "value1".getBytes());
  colVarCharV.set(1,
      "long long long long long long long long long long long long long long long long value".getBytes()
  );
  colVarCharV.set(2, "long long long long value".getBytes());
  colVarCharV.setNull(3);
  colVarCharV.set(4, "l".getBytes());

  ResultVerifier verifier = new ResultVerifier() {
    @Override
    public void verify(DataPOJO output) {
      int index = startIndexInCurrentOutput;
      int uIndex = startIndexInJob;
      assertEquals("value1", output.extractValue("colVarChar", index));
      assertNull(output.extractUrl("colVarChar", index++));
      uIndex++;

      assertEquals("long long long long long long ", output.extractValue("colVarChar", index));
      assertEquals(cellUrl(uIndex++, "colVarChar"), output.extractUrl("colVarChar", index++));

      assertEquals("long long long long value", output.extractValue("colVarChar", index));
      assertNull(output.extractUrl("colVarChar", index++));

      assertNull(output.extractValue("colVarChar", index));
      assertNull(output.extractUrl("colVarChar", index++));

      assertEquals("l", output.extractValue("colVarChar", index));
      assertNull(output.extractUrl("colVarChar", index++));
    }
  };

  return Pair.of(colVarCharV, verifier);
}
 
Example 5
Source File: VarCharConverterTest.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<String> expectedValues = new ArrayList<>();
  Set<Integer> nullValIndex = new HashSet<>();
  for (int i = 0; i < rowCount; i++)
  {
    expectedValues.add(RandomStringUtils.random(20));
  }

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

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

  VarCharVector vector = new VarCharVector("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).getBytes(StandardCharsets.UTF_8));
    }
  }

  ArrowVectorConverter converter = new VarCharConverter(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()));
    }
    else
    {
      assertThat(stringVal, is(expectedValues.get(i)));
      assertThat(objectVal, is(expectedValues.get(i)));
      assertThat(bytesVal,
                 is(expectedValues.get(i).getBytes(StandardCharsets.UTF_8)));
    }
  }
  vector.clear();
}