org.apache.arrow.vector.VarCharVector Java Examples
The following examples show how to use
org.apache.arrow.vector.VarCharVector.
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: TestConvertFunctions.java From dremio-oss with Apache License 2.0 | 6 votes |
protected Object[] getRunResult(QueryType queryType, String planString) throws Exception { List<QueryDataBatch> resultList = testRunAndReturn(queryType, planString); List<Object> res = new ArrayList<>(); RecordBatchLoader loader = new RecordBatchLoader(getAllocator()); for(QueryDataBatch result : resultList) { if (result.getData() != null) { loader.load(result.getHeader().getDef(), result.getData()); ValueVector v = loader.iterator().next().getValueVector(); for (int j = 0; j < v.getValueCount(); j++) { if (v instanceof VarCharVector) { res.add(new String(((VarCharVector) v).get(j))); } else { res.add(v.getObject(j)); } } loader.clear(); result.release(); } } return res.toArray(); }
Example #2
Source File: TestAllocate.java From dremio-oss with Apache License 2.0 | 6 votes |
@Test public void testAllocateVarLenReAlloc() { boolean allocatePassed = false; try (BufferAllocator child = allocator.newChildAllocator("test", 0, 128 * 1024)) { try (final ValueVector vector = new VarCharVector("ints", child)) { vector.allocateNew(); allocatePassed = true; // realloc will fail after some iterations. while (true) { vector.reAlloc(); } } } catch (Exception e) { assertTrue(e instanceof OutOfMemoryException); assertTrue(((OutOfMemoryException)e).getOutcomeDetails().isPresent()); assertTrue(allocatePassed); } }
Example #3
Source File: TestArrowFileReader.java From dremio-oss with Apache License 2.0 | 6 votes |
/** Helper method to get the values in given range in colVarChar vector used in this test class. */ private static List<String> getVarCharValues(VectorContainer container, int start, int end) { FieldReader reader = container.getValueAccessorById(VarCharVector.class, 1).getValueVector().getReader(); List<String> values = Lists.newArrayList(); for(int i=start; i<end; i++) { reader.setPosition(i); if (reader.isSet()) { final Text val = reader.readText(); values.add(val == null ? null : val.toString()); } else { values.add(null); } } return values; }
Example #4
Source File: VarCharConverterTest.java From snowflake-jdbc with Apache License 2.0 | 6 votes |
@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 #5
Source File: TestVarBinaryPivot.java From dremio-oss with Apache License 2.0 | 6 votes |
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 #6
Source File: TestBoundedPivots.java From dremio-oss with Apache License 2.0 | 5 votes |
static String[] populateVarCharValues(VarCharVector vector, int size){ vector.allocateNew(); String values[] = new String[size]; for(int i =0; i < values.length; i++){ if (RAND.nextBoolean()) { values[i] = RandomStringUtils.randomAlphanumeric(RAND.nextInt(25)); vector.setSafe(i, values[i].getBytes(Charsets.UTF_8)); } } vector.setValueCount(values.length); return values; }
Example #7
Source File: RowVarCharWriter.java From flink with Apache License 2.0 | 5 votes |
@Override public void doWrite(Row value, int ordinal) { if (value.getField(ordinal) == null) { ((VarCharVector) getValueVector()).setNull(getCount()); } else { ((VarCharVector) getValueVector()).setSafe( getCount(), StringUtf8Utils.encodeUTF8(((String) value.getField(ordinal)))); } }
Example #8
Source File: TestBoundedPivots.java From dremio-oss with Apache License 2.0 | 5 votes |
@Test public void fixedVariable(){ try(IntVector col1 = new IntVector("col1", allocator); BigIntVector col2 = new BigIntVector("col2", allocator); VarCharVector col3 = new VarCharVector("col3", allocator);){ PivotDef pivot = PivotBuilder.getBlockDefinition( new FieldVectorPair(col1, col1), new FieldVectorPair(col2, col2), new FieldVectorPair(col3, col3) ); Integer col1Val[] = populate4ByteValues(col1, 4096); Long col2Val[] = populate8ByteValues(col2, 4096); String col3Val[] = populateVarCharValues(col3, 4096); assertEquals(20, pivot.getBlockWidth()); try(FixedBlockVector fixed = new FixedBlockVector(allocator, pivot.getBlockWidth(), 4096, true); VariableBlockVector variable = new VariableBlockVector(allocator, pivot.getVariableCount(), 4096 * 2, true)){ fixedVariableHelper(pivot, fixed, variable, 0, 4096, false, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 0, 128, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 0, 17, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 0, 76, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 5, 39, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 5, 189, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 5, 123, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 0, 1023, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 1023, 1023, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 2046, 1023, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 3069, 1023, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 4092, 4, true, col1Val, col2Val, col3Val); } } }
Example #9
Source File: BaseTestQuery.java From dremio-oss with Apache License 2.0 | 5 votes |
protected static String getValueInFirstRecord(String sql, String columnName) throws Exception { final List<QueryDataBatch> results = testSqlWithResults(sql); final RecordBatchLoader loader = new RecordBatchLoader(getSabotContext().getAllocator()); final StringBuilder builder = new StringBuilder(); final boolean silent = config != null && config.getBoolean(QueryTestUtil.TEST_QUERY_PRINTING_SILENT); for (final QueryDataBatch b : results) { if (!b.hasData()) { continue; } loader.load(b.getHeader().getDef(), b.getData()); final VectorWrapper<?> vw; try { vw = loader.getValueAccessorById( VarCharVector.class, loader.getValueVectorId(SchemaPath.getSimplePath(columnName)).getFieldIds()); } catch (Throwable t) { throw new Exception("Looks like you did not provide an explain plan query, please add EXPLAIN PLAN FOR to the beginning of your query."); } if (!silent) { System.out.println(vw.getValueVector().getField().getName()); } final ValueVector vv = vw.getValueVector(); for (int i = 0; i < vv.getValueCount(); i++) { final Object o = vv.getObject(i); builder.append(o); if (!silent) { System.out.println(o); } } loader.clear(); b.release(); } return builder.toString(); }
Example #10
Source File: CustomGenerator.java From dremio-oss with Apache License 2.0 | 5 votes |
public void assertIsSorted(VectorContainer container, int startIndex) { final IntVector idVector = container.addOrGet(ID); final VarCharVector valueVector = container.addOrGet(VALUE); int recordCount = container.getRecordCount(); int index = startIndex; for (int i = 0; i < recordCount; i++, index++) { int rowId = sortedRowIds.get(index); String value = values.get(rowId); assertEquals("non matching ID at row " + index, rowId, idVector.get(i)); assertEquals("non matching VALUE at row " + index, value, valueVector.getObject(i).toString()); } }
Example #11
Source File: TestArrowFileReader.java From dremio-oss with Apache License 2.0 | 5 votes |
/** 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 #12
Source File: TestBoundedPivots.java From dremio-oss with Apache License 2.0 | 5 votes |
static String[] populateVarCharValuesWithoutNull(VarCharVector vector, int size){ vector.allocateNew(); String values[] = new String[size]; for(int i =0; i < values.length; i++){ values[i] = RandomStringUtils.randomAlphanumeric(RAND.nextInt(25)); vector.setSafe(i, values[i].getBytes(Charsets.UTF_8)); } vector.setValueCount(values.length); return values; }
Example #13
Source File: BaseVarBinaryAccumulatorNoSpill.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public void output(int batchIndex) { MutableVarcharVector mv = (MutableVarcharVector) accumulators[batchIndex]; ((VariableWidthVector) output).allocateNew(mv.getUsedByteCapacity(), LBlockHashTableNoSpill.MAX_VALUES_PER_BATCH); mv.copyToVarchar((VarCharVector) output, 0, LBlockHashTableNoSpill.MAX_VALUES_PER_BATCH); }
Example #14
Source File: TestBoundedPivots.java From dremio-oss with Apache License 2.0 | 5 votes |
@Test public void fixedVariableWithoutNull(){ try(IntVector col1 = new IntVector("col1", allocator); BigIntVector col2 = new BigIntVector("col2", allocator); VarCharVector col3 = new VarCharVector("col3", allocator);){ PivotDef pivot = PivotBuilder.getBlockDefinition( new FieldVectorPair(col1, col1), new FieldVectorPair(col2, col2), new FieldVectorPair(col3, col3) ); Integer col1Val[] = populate4ByteValuesWithoutNull(col1, 4096); Long col2Val[] = populate8ByteValuesWithoutNull(col2, 4096); String col3Val[] = populateVarCharValuesWithoutNull(col3, 4096); assertEquals(20, pivot.getBlockWidth()); try(FixedBlockVector fixed = new FixedBlockVector(allocator, pivot.getBlockWidth(), 4096, true); VariableBlockVector variable = new VariableBlockVector(allocator, pivot.getVariableCount(), 4096 * 2, true)){ fixedVariableHelper(pivot, fixed, variable, 0, 4096, false, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 0, 128, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 0, 17, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 0, 76, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 5, 39, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 5, 189, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 5, 123, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 0, 1023, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 1023, 1023, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 2046, 1023, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 3069, 1023, true, col1Val, col2Val, col3Val); fixedVariableHelper(pivot, fixed, variable, 4092, 4, true, col1Val, col2Val, col3Val); } } }
Example #15
Source File: HiveFieldConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { final Text value = ((HiveVarcharObjectInspector)oi).getPrimitiveWritableObject(hiveFieldValue).getTextValue(); final int valueLen = value.getLength(); checkSizeLimit(valueLen); final byte[] valueBytes = value.getBytes(); ((VarCharVector) outputVV).setSafe(outputIndex, valueBytes, 0, valueLen); }
Example #16
Source File: StringFieldWriter.java From dremio-oss with Apache License 2.0 | 5 votes |
StringFieldWriter( Field field, OutputMutator outputMutator, Function<V, String> stringExtractor ) { this.managedBuffer = outputMutator.getManagedBuffer(); this.stringExtractor = stringExtractor; varCharVector = outputMutator.addField(field, VarCharVector.class); }
Example #17
Source File: HiveFieldConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { final Text value = ((StringObjectInspector)oi).getPrimitiveWritableObject(hiveFieldValue); final int len = value.getLength(); checkSizeLimit(len); final byte[] valueBytes = value.getBytes(); ((VarCharVector) outputVV).setSafe(outputIndex, valueBytes, 0, len); }
Example #18
Source File: TestData.java From dremio-oss with Apache License 2.0 | 5 votes |
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 #19
Source File: ColumnReaderFactory.java From dremio-oss with Apache License 2.0 | 5 votes |
static VarLengthValuesColumn<?> getReader(DeprecatedParquetVectorizedReader parentReader, int allocateSize, ColumnDescriptor descriptor, ColumnChunkMetaData columnChunkMetaData, boolean fixedLength, ValueVector v, SchemaElement schemaElement ) throws ExecutionSetupException { ConvertedType convertedType = schemaElement.getConverted_type(); switch (descriptor.getMaxDefinitionLevel()) { case 0: if (convertedType == null) { return new VarLengthColumnReaders.VarBinaryColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarBinaryVector) v, schemaElement); } switch (convertedType) { case UTF8: return new VarLengthColumnReaders.VarCharColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarCharVector) v, schemaElement); case DECIMAL: return new VarLengthColumnReaders.Decimal28Column(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (DecimalVector) v, schemaElement); default: return new VarLengthColumnReaders.VarBinaryColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarBinaryVector) v, schemaElement); } default: if (convertedType == null) { return new VarLengthColumnReaders.NullableVarBinaryColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarBinaryVector) v, schemaElement); } switch (convertedType) { case UTF8: return new VarLengthColumnReaders.NullableVarCharColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarCharVector) v, schemaElement); case DECIMAL: return new NullableDecimalColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (DecimalVector) v, schemaElement); default: return new VarLengthColumnReaders.NullableVarBinaryColumn(parentReader, allocateSize, descriptor, columnChunkMetaData, fixedLength, (VarBinaryVector) v, schemaElement); } } }
Example #20
Source File: VectorizedHashAggOperatorNoSpill.java From dremio-oss with Apache License 2.0 | 5 votes |
private PivotDef createPivot(){ final List<NamedExpression> groupByExpressions = popConfig.getGroupByExprs(); final ImmutableList.Builder<FieldVector> validationVectors = ImmutableList.builder(); final List<FieldVectorPair> fvps = new ArrayList<>(); //final FieldVector[] readVectors = new FieldVector[] for (int i = 0; i < groupByExpressions.size(); i++) { final NamedExpression ne = groupByExpressions.get(i); final LogicalExpression expr = context.getClassProducer().materialize(ne.getExpr(), incoming); if(expr == null){ throw unsup("Unable to resolve group by expression: " + ne.getExpr().toString()); } if( !(expr instanceof ValueVectorReadExpression) ){ throw unsup("Group by expression is non-trivial: " + ne.getExpr().toString()); } final ValueVectorReadExpression vvread = (ValueVectorReadExpression) expr; final FieldVector inputVector = incoming.getValueAccessorById(FieldVector.class, vvread.getFieldId().getFieldIds()).getValueVector(); if(inputVector instanceof VarCharVector || inputVector instanceof VarBinaryVector){ validationVectors.add(inputVector); } final FieldVector outputVector = TypeHelper.getNewVector(expr.getCompleteType().toField(ne.getRef()), context.getAllocator()); outgoing.add(outputVector); fvps.add(new FieldVectorPair(inputVector, outputVector)); } this.vectorsToValidate = validationVectors.build(); return PivotBuilder.getBlockDefinition(fvps); }
Example #21
Source File: HiveFieldConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { final Text value = ((HiveCharObjectInspector)oi).getPrimitiveWritableObject(hiveFieldValue).getStrippedValue(); final int valueLen = value.getLength(); checkSizeLimit(valueLen); final byte[] valueBytes = value.getBytes(); ((VarCharVector) outputVV).setSafe(outputIndex, valueBytes, 0, valueLen); }
Example #22
Source File: VectorizedHashAggOperator.java From dremio-oss with Apache License 2.0 | 5 votes |
/** * Create pivot definition. This operation is independent of * partitioning and needs to be done once during setup and not * per partition. Populates the outgoing vector container * with target vectors and builds set of FieldVectorPair * <inputVector, outputVector> for creating the pivot * definition. * * @return vector pivot definition for the incoming GROUP BY * expressions. */ private PivotDef createPivot(){ final List<NamedExpression> groupByExpressions = popConfig.getGroupByExprs(); final ImmutableList.Builder<FieldVector> validationVectors = ImmutableList.builder(); final List<FieldVectorPair> fvps = new ArrayList<>(); for (int i = 0; i < groupByExpressions.size(); i++) { final NamedExpression ne = groupByExpressions.get(i); final LogicalExpression expr = context.getClassProducer().materialize(ne.getExpr(), incoming); if(expr == null){ throw unsup("Unable to resolve group by expression: " + ne.getExpr().toString()); } if( !(expr instanceof ValueVectorReadExpression) ){ throw unsup("Group by expression is non-trivial: " + ne.getExpr().toString()); } final ValueVectorReadExpression vvread = (ValueVectorReadExpression) expr; final FieldVector inputVector = incoming.getValueAccessorById(FieldVector.class, vvread.getFieldId().getFieldIds()).getValueVector(); if(inputVector instanceof VarCharVector || inputVector instanceof VarBinaryVector){ validationVectors.add(inputVector); } final FieldVector outputVector = TypeHelper.getNewVector(expr.getCompleteType().toField(ne.getRef()), outputAllocator); outgoing.add(outputVector); fvps.add(new FieldVectorPair(inputVector, outputVector)); } this.vectorsToValidate = validationVectors.build(); return PivotBuilder.getBlockDefinition(fvps); }
Example #23
Source File: TestVarBinaryPivot.java From dremio-oss with Apache License 2.0 | 5 votes |
static void populate(VarCharVector vector, String[] values){ populate(vector, Arrays.stream(values).map(input -> { if (input == null) { return null; } return input.getBytes(Charsets.UTF_8); }).toArray(byte[][]::new)); }
Example #24
Source File: OutgoingBatch.java From dremio-oss with Apache License 2.0 | 5 votes |
OutgoingBatch(int batchIdx, int nextBatchIdx, int maxRecords, final VectorAccessible incoming, BufferAllocator allocator, AccountingExecTunnel tunnel, HashPartitionSender config, OperatorContext context, int oppositeMinorFragmentId, OperatorStats stats) { Preconditions.checkArgument(maxRecords <= Character.MAX_VALUE, "maxRecords cannot exceed " + Character.MAX_VALUE); this.batchIdx = batchIdx; this.nextBatchIdx = nextBatchIdx; this.maxRecords = maxRecords; this.tunnel = tunnel; this.config = config; this.context = context; this.oppositeMinorFragmentId = oppositeMinorFragmentId; this.stats = stats; for (VectorWrapper<?> v : incoming) { ValueVector outgoingVector = TypeHelper.getNewVector(v.getField(), allocator); outgoingVector.setInitialCapacity(maxRecords); add(outgoingVector); if (outgoingVector instanceof VarBinaryVector) { varbins.add(((VarBinaryVector) outgoingVector)); } else if (outgoingVector instanceof VarCharVector) { varchars.add(((VarCharVector) outgoingVector)); } } }
Example #25
Source File: HiveFieldConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { final Text value = ((HiveCharObjectInspector)oi).getPrimitiveWritableObject(hiveFieldValue).getStrippedValue(); final int valueLen = value.getLength(); checkSizeLimit(valueLen); final byte[] valueBytes = value.getBytes(); ((VarCharVector) outputVV).setSafe(outputIndex, valueBytes, 0, valueLen); }
Example #26
Source File: Reallocators.java From dremio-oss with Apache License 2.0 | 5 votes |
public static Reallocator getReallocator(FieldVector vect){ if(vect instanceof VarCharVector){ return new VarCharReallocator(((VarCharVector) vect)); }else if(vect instanceof VarBinaryVector){ return new VarBinaryReallocator(((VarBinaryVector) vect)); }else{ throw new IllegalStateException("Invalid vector: " + Describer.describe(vect.getField())); } }
Example #27
Source File: TestSplitAndTransfer.java From dremio-oss with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { final VarCharVector varCharVector = new VarCharVector("field", allocator); varCharVector.allocateNew(10000, 1000); final int valueCount = 500; final String[] compareArray = new String[valueCount]; for (int i = 0; i < valueCount; i += 3) { final String s = String.format("%010d", i); varCharVector.set(i, s.getBytes()); compareArray[i] = s; } varCharVector.setValueCount(valueCount); final TransferPair tp = varCharVector.getTransferPair(allocator); final VarCharVector newVarCharVector = (VarCharVector) tp.getTo(); final int[][] startLengths = {{0, 201}, {201, 200}, {401, 99}}; for (final int[] startLength : startLengths) { final int start = startLength[0]; final int length = startLength[1]; tp.splitAndTransfer(start, length); newVarCharVector.setValueCount(length); for (int i = 0; i < length; i++) { final boolean expectedSet = ((start + i) % 3) == 0; if (expectedSet) { final byte[] expectedValue = compareArray[start + i].getBytes(); assertFalse(newVarCharVector.isNull(i)); assertArrayEquals(expectedValue, newVarCharVector.get(i)); } else { assertTrue(newVarCharVector.isNull(i)); } } newVarCharVector.clear(); } varCharVector.close(); allocator.close(); }
Example #28
Source File: TestAllocate.java From dremio-oss with Apache License 2.0 | 5 votes |
@Test public void testAllocateVarLenNew() { try (BufferAllocator child = allocator.newChildAllocator("test", 0, 4 * 1024)) { try (final ValueVector vector = new VarCharVector("varchar", child)) { vector.allocateNew(); fail("expected allocation to fail"); } } catch (Exception e) { assertTrue(e instanceof OutOfMemoryException); assertTrue(((OutOfMemoryException)e).getOutcomeDetails().isPresent()); } }
Example #29
Source File: HiveFieldConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { final Text value = ((HiveVarcharObjectInspector)oi).getPrimitiveWritableObject(hiveFieldValue).getTextValue(); final int valueLen = value.getLength(); checkSizeLimit(valueLen); final byte[] valueBytes = value.getBytes(); ((VarCharVector) outputVV).setSafe(outputIndex, valueBytes, 0, valueLen); }
Example #30
Source File: TestPivotRoundtrip.java From dremio-oss with Apache License 2.0 | 5 votes |
@Test public void varcharRoundtrip() throws Exception { final int count = 1024; try ( VarCharVector in = new VarCharVector("in", allocator); VarCharVector out = new VarCharVector("out", allocator); ) { in.allocateNew(count * 8, count); for (int i = 0; i < count; i++) { if (i % 5 == 0) { byte[] data = ("hello-" + i).getBytes(Charsets.UTF_8); in.setSafe(i, data, 0, data.length); } } in.setValueCount(count); final PivotDef pivot = PivotBuilder.getBlockDefinition(new FieldVectorPair(in, out)); try ( final FixedBlockVector fbv = new FixedBlockVector(allocator, pivot.getBlockWidth()); final VariableBlockVector vbv = new VariableBlockVector(allocator, pivot.getVariableCount()); ) { fbv.ensureAvailableBlocks(count); Pivots.pivot(pivot, count, fbv, vbv); ValueVector[] ins = new ValueVector[]{in}; ValueVector[] outs = new ValueVector[]{out}; unpivotHelper(pivot, fbv, vbv, ins, outs, 0, count); unpivotHelper(pivot, fbv, vbv, ins, outs, 0, 100); unpivotHelper(pivot, fbv, vbv, ins, outs, 100, 924); } } }