@Override final double getDouble(int rowId) { return accessor.get(rowId); } }
/** * * @param allocator * @param name * @param data * @return */ public static Float8Vector vectorFor(BufferAllocator allocator,String name,double[] data) { Float8Vector float8Vector = new Float8Vector(name,allocator); float8Vector.allocateNew(data.length); for(int i = 0; i < data.length; i++) { float8Vector.setSafe(i,data[i]); } float8Vector.setValueCount(data.length); return float8Vector; }
/** * Same as {@link #set(int, NullableFloat8Holder)} except that it handles the * case when index is greater than or equal to existing * value capacity {@link #getValueCapacity()}. * * @param index position of element * @param holder nullable data holder for value of element */ public void setSafe(int index, NullableFloat8Holder holder) throws IllegalArgumentException { handleSafe(index); set(index, holder); }
public void populate(final int count){ for (int i = 0; i < count; i++) { if(value != null) { ((Float8Vector) vector).setSafe(i, value); } } vector.setValueCount(count); }
private static VectorContainer buildDoubleGlobalDictionary(List<Dictionary> dictionaries, VectorContainer existingDict, ColumnDescriptor columnDescriptor, BufferAllocator bufferAllocator) { final Field field = new Field(SchemaPath.getCompoundPath(columnDescriptor.getPath()).getAsUnescapedPath(), true, new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), null); final VectorContainer input = new VectorContainer(bufferAllocator); final Float8Vector doubleVector = input.addOrGet(field); doubleVector.allocateNew(); SortedSet<Double> values = Sets.newTreeSet(); for (Dictionary dictionary : dictionaries) { for (int i = 0; i <= dictionary.getMaxId(); ++i) { values.add(dictionary.decodeToDouble(i)); } } if (existingDict != null) { final Float8Vector existingDictValues = existingDict.getValueAccessorById(Float8Vector.class, 0).getValueVector(); for (int i = 0; i < existingDict.getRecordCount(); ++i) { values.add(existingDictValues.get(i)); } } final Iterator<Double> iter = values.iterator(); int recordCount = 0; while (iter.hasNext()) { doubleVector.setSafe(recordCount++, iter.next()); } doubleVector.setValueCount(recordCount); input.setRecordCount(recordCount); input.buildSchema(BatchSchema.SelectionVectorMode.NONE); return input; }
final Float8Vector float8Vector = new Float8Vector("float8", allocator); final StructVector mapVector = new StructVector("map", allocator, mapType, null); final ArrowBuf tempBuf = allocator.buffer(2048)) { for (int i = 0; i < records; i++) { intVector.set(i, intBaseValue + i); float8Vector.set(i, doubleBaseValue + i); float8Vector.setValueCount(records); mapVector.setValueCount(records); assertEquals(doubleBaseValue + i, float8Vector.get(i), 0); assertEquals( mapOf(
private void populateDouble(Float8Vector vector, Double[] data) { vector.allocateNew(); Random r = new Random(); for(int i =0; i < data.length; i++){ Double val = data[i]; if(val != null){ vector.setSafe(i, val); } else { vector.setSafe(i, 0, r.nextDouble()); } } vector.setValueCount(data.length); }
private static Pair<Float8Vector, ResultVerifier> testFloat8Vector(final int startIndexInCurrentOutput, final int startIndexInJob) { Float8Vector colFloat8V = new Float8Vector("colFloat8", allocator); colFloat8V.allocateNew(5); colFloat8V.set(0, 20.2345234d); colFloat8V.set(1, 503453.023d); colFloat8V.set(2, -238423.3453453d); colFloat8V.set(3, 3273452.345324563245d); colFloat8V.setNull(4); ResultVerifier verifier = new ResultVerifier() { @Override public void verify(DataPOJO output) { int index = startIndexInCurrentOutput; assertEquals(20.2345234d, ((Double)output.extractValue("colFloat8", index++)).doubleValue(), 0.01f); assertEquals(503453.023d, ((Double)output.extractValue("colFloat8", index++)).doubleValue(), 0.01f); assertEquals(-238423.3453453d, ((Double)output.extractValue("colFloat8", index++)).doubleValue(), 0.01f); assertEquals(3273452.345324563245d, ((Double)output.extractValue("colFloat8", index++)).doubleValue(), 0.01f); assertNull(output.extractValue("colFloat8", 4)); } }; return Pair.of(colFloat8V, verifier); }
/** * * @param allocator * @param name * @param length the length of the vector * @return */ public static Float8Vector doubleVectorOf(BufferAllocator allocator,String name,int length) { Float8Vector float8Vector = new Float8Vector(name,allocator); float8Vector.allocateNew(); float8Vector.setValueCount(length); return float8Vector; }
@Override public void writeField(Object pojo, int outboundIndex) throws IllegalArgumentException, IllegalAccessException { Double o = (Double) field.get(pojo); if (o != null) { vector.setSafe(outboundIndex, o); } }
@Override public FieldVector getNewVector( String name, FieldType fieldType, BufferAllocator allocator, CallBack schemaChangeCallback) { return new Float8Vector(name, fieldType, allocator); }
@Override public void copy(int inputIdx, int count, int outputIdx) { final double[] input = inputVector.vector; if (inputVector.isRepeating) { if (inputVector.isNull[0]) { return; // If all repeating values are null, then there is no need to write anything to vector } final double value = input[0]; for (int i = 0; i < count; i++, outputIdx++) { outputVector.set(outputIdx, value); } // We can't rely noNulls flag due to the bug/hive shenanigans here (they set the noNulls flag wrong): // https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java#L656 // } else if (inputVector.noNulls) { // for (int i = 0; i < count; i++, inputIdx++, outputIdx++) { // outputVector.set(outputIdx, input[inputIdx]); // } } else { final boolean isNull[] = inputVector.isNull; for (int i = 0; i < count; i++, inputIdx++, outputIdx++) { if (!isNull[inputIdx]) { outputVector.set(outputIdx, input[inputIdx]); } } } } }
Float8Vector in3SumOutputVector = new Float8Vector("float-sum", allocator); final SumAccumulators.FloatSumAccumulator in3SumAccum = new SumAccumulators.FloatSumAccumulator(in3, in3SumOutputVector, in3SumOutputVector, MAX_VALUES_PER_BATCH, allocator); postSpillAccumulatorVectorFields.add(in3SumOutputVector.getField()); Float8Vector in4SumOutputVector = new Float8Vector("double-sum", allocator); final SumAccumulators.DoubleSumAccumulator in4SumAccum = new SumAccumulators.DoubleSumAccumulator(in4, in4SumOutputVector, in4SumOutputVector, MAX_VALUES_PER_BATCH, allocator); postSpillAccumulatorVectorFields.add(in4SumOutputVector.getField()); Float8Vector in4MaxOutputVector = new Float8Vector("double-max", allocator); final MaxAccumulators.DoubleMaxAccumulator in4MaxAccum = new MaxAccumulators.DoubleMaxAccumulator(in4, in4MaxOutputVector, in4MaxOutputVector, MAX_VALUES_PER_BATCH, allocator); postSpillAccumulatorVectorFields.add(in4MaxOutputVector.getField()); Float8Vector in4MinOutputVector = new Float8Vector("double-min", allocator); final MinAccumulators.DoubleMinAccumulator in4MinAccum = new MinAccumulators.DoubleMinAccumulator(in4, in4MinOutputVector, in4MinOutputVector, MAX_VALUES_PER_BATCH, allocator); postSpillAccumulatorVectorFields.add(in4MinOutputVector.getField());
assertEquals(valueCount, ac9New.getValueCount()); assertEquals(valueCount, ac10New.getValueCount()); assertEquals(valueCount, ac11New.getValueCount()); assertEquals(valueCount, ac12New.getValueCount()); assertEquals(valueCount, ac13New.getValueCount()); assertEquals(valueCount, ac14New.getValueCount()); assertEquals(valueCount, ac15New.getValueCount()); assertEquals(valueCount, ac16New.getValueCount()); assertEquals(valueCount, ac17New.getValueCount()); assertTrue(ac10New.isNull(i)); assertTrue(ac14New.isNull(i)); } else { assertEquals(sum.floatOut[i], ac10New.getObject(i), 0.1D); assertEquals(sum.doubleOut[i], ac14New.getObject(i), 0.1D); assertEquals(counts[i], ac13New.get(i)); assertEquals(max.doubleOut[i], ac15New.getObject(i)); assertEquals(min.doubleOut[i], ac16New.getObject(i)); assertEquals(counts[i], ac17New.get(i));
public void loadData(SerializedField metadata, ArrowBuf buffer) { /* clear the current buffers (if any) */ vector.clear(); /* get the metadata children */ final SerializedField bitsField = metadata.getChild(0); final SerializedField valuesField = metadata.getChild(1); final int valuesLength = buffer.capacity(); vector.allocateNew(metadata.getValueCount()); /* set inner validity buffer */ setValidityBuffer(bitsField); /* load inner value buffer */ vector.valueBuffer.close(); loadDataBuffer(valuesField, buffer.slice(0, valuesLength)); }
public void writeNull() { vector.setNull(idx()); vector.setValueCount(idx()+1); } }
@Override public void allocate() { vector.allocateNew(); }