@Override protected void readField(long recordsToReadInThisPass) { recordsReadInThisIteration = Math.min(pageReader.currentPageCount - pageReader.valuesRead, recordsToReadInThisPass - valuesReadInCurrentPass); if (usingDictionary) { for (int i = 0; i < recordsReadInThisIteration; i++){ BigDecimal bigDecimal = new BigDecimal(BigInteger.valueOf(pageReader.dictionaryValueReader.readInteger())); DecimalUtility.writeBigDecimalToArrowBuf(bigDecimal, vectorData, valuesReadInCurrentPass + i); valueVec.setIndexDefined(valuesReadInCurrentPass + i); } } } }
@Override protected ArrowBuf read(BufferAllocator allocator, int count) throws IOException { final int size = count * DecimalVector.TYPE_WIDTH; ArrowBuf buf = allocator.buffer(size); for (int i = 0; i < count; i++) { parser.nextToken(); BigDecimal decimalValue = new BigDecimal(parser.readValueAs(String.class)); DecimalUtility.writeBigDecimalToArrowBuf(decimalValue, buf, i); } buf.writerIndex(size); return buf; } };
@Override public void eval() { java.math.BigDecimal bd = java.math.BigDecimal.valueOf(in.value).setScale((int) scale.value, java.math.RoundingMode.HALF_UP); try { org.apache.arrow.vector.util.DecimalUtility.writeBigDecimalToArrowBuf(bd, buffer, 0); } catch (RuntimeException e) { throw errorContext.error(e) .build(); } out.buffer = buffer; out.precision = (int) precision.value; out.scale = (int) scale.value; } }
@Override protected void readField(long recordsToReadInThisPass) { recordsReadInThisIteration = Math.min(pageReader.currentPageCount - pageReader.valuesRead, recordsToReadInThisPass - valuesReadInCurrentPass); for (int i = 0; i < recordsReadInThisIteration; i++){ try { BigDecimal bigDecimal = new BigDecimal(BigInteger.valueOf(pageReader.dictionaryValueReader.readLong())); DecimalUtility.writeBigDecimalToArrowBuf(bigDecimal, vectorData, valuesReadInCurrentPass + i); valueVec.setIndexDefined(valuesReadInCurrentPass + i); } catch ( Exception ex) { throw ex; } } } }
@Override public void eval() { java.math.BigDecimal bd = java.math.BigDecimal.valueOf(in.value).setScale((int) scale.value, java.math.RoundingMode.HALF_UP); try { org.apache.arrow.vector.util.DecimalUtility.writeBigDecimalToArrowBuf(bd, buffer, 0); } catch (RuntimeException e) { throw errorContext.error(e) .build(); } out.buffer = buffer; out.precision = (int) precision.value; out.scale = (int) scale.value; } }
@Override public void eval() { java.math.BigDecimal bd = java.math.BigDecimal.valueOf(in.value).setScale((int) scale.value, java.math.RoundingMode.HALF_UP); try { org.apache.arrow.vector.util.DecimalUtility.writeBigDecimalToArrowBuf(bd, buffer, 0); } catch (RuntimeException e) { throw errorContext.error(e) .build(); } out.buffer = buffer; out.precision = (int) precision.value; out.scale = (int) scale.value; } }
@Override public void eval() { out.isSet = 1; java.math.BigDecimal bd = java.math.BigDecimal.valueOf(in.value).setScale((int) scale.value, java.math.RoundingMode.HALF_UP); try { org.apache.arrow.vector.util.DecimalUtility.writeBigDecimalToArrowBuf(bd, buffer, 0); } catch (RuntimeException e) { throw errorContext.error(e) .build(); } out.buffer = buffer; out.precision = (int) precision.value; out.scale = (int) scale.value; } }
@Override protected void readField(long recordsToReadInThisPass) { if (usingDictionary) { for (int i = 0; i < recordsToReadInThisPass; i++){ BigDecimal bigDecimal = new BigDecimal(BigInteger.valueOf(pageReader.dictionaryValueReader.readInteger())); /* this will swap bytes as we are writing to the buffer of DecimalVector */ DecimalUtility.writeBigDecimalToArrowBuf(bigDecimal, vectorData, valuesReadInCurrentPass + i); valueVec.setIndexDefined(valuesReadInCurrentPass + i); } } else { for (int i = 0; i < recordsToReadInThisPass; i++){ BigDecimal bigDecimal = new BigDecimal(BigInteger.valueOf(pageReader.valueReader.readInteger())); /* this will swap bytes as we are writing to the buffer of DecimalVector */ DecimalUtility.writeBigDecimalToArrowBuf(bigDecimal, vectorData, valuesReadInCurrentPass + i); valueVec.setIndexDefined(valuesReadInCurrentPass + i); } } } }
@Override protected void readField(long recordsToReadInThisPass) { if (usingDictionary) { for (int i = 0; i < recordsToReadInThisPass; i++){ BigDecimal bigDecimal = new BigDecimal(BigInteger.valueOf(pageReader.dictionaryValueReader.readLong())); /* this will swap bytes as we are writing to the buffer of DecimalVector */ DecimalUtility.writeBigDecimalToArrowBuf(bigDecimal, vectorData, valuesReadInCurrentPass + i); valueVec.setIndexDefined(valuesReadInCurrentPass + i); } } else { for (int i = 0; i < recordsToReadInThisPass; i++){ BigDecimal bigDecimal = new BigDecimal(BigInteger.valueOf(pageReader.valueReader.readLong())); /* this will swap bytes as we are writing to the buffer of DecimalVector */ DecimalUtility.writeBigDecimalToArrowBuf(bigDecimal, vectorData, valuesReadInCurrentPass + i); valueVec.setIndexDefined(valuesReadInCurrentPass + i); } } } }
/** * Set the element at the given index to the given value. * * @param index position of element * @param value BigDecimal containing decimal value. */ public void set(int index, BigDecimal value) { BitVectorHelper.setValidityBitToOne(validityBuffer, index); DecimalUtility.checkPrecisionAndScale(value, precision, scale); DecimalUtility.writeBigDecimalToArrowBuf(value, valueBuffer, index); }
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { DecimalUtility.writeBigDecimalToArrowBuf(((HiveDecimalObjectInspector)oi).getPrimitiveJavaObject(hiveFieldValue).bigDecimalValue().setScale(holder.scale, RoundingMode.HALF_UP), holder.buffer, holder.start); ((DecimalVector) outputVV).setSafe(outputIndex, 1, 0, holder.buffer); } }
@Override public void eval() { String s = com.dremio.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(in.start, in.end, in.buffer); java.math.BigDecimal bd = new java.math.BigDecimal(s).setScale((int) scale.value, java.math.RoundingMode.HALF_UP); try { org.apache.arrow.vector.util.DecimalUtility.writeBigDecimalToArrowBuf(bd, buffer, 0); } catch (RuntimeException e) { throw errorContext.error(e) .build(); } out.buffer = buffer; out.precision = (int) precision.value; out.scale = (int) scale.value; } }
@Override void addNext(int start, int index) { /* data read from Parquet into the bytebuf is already in BE format, no need * swap bytes to construct BigDecimal. only when we write BigDecimal to * data buffer of decimal vector, we need to swap bytes which the DecimalUtility * function already does. */ BigDecimal intermediate = DecimalHelper.getBigDecimalFromBEArrowBuf(bytebuf, index, schemaElement.getScale()); /* this will swap bytes as we are writing to the buffer of DecimalVector */ DecimalUtility.writeBigDecimalToArrowBuf(intermediate, valueVec.getDataBuffer(), index); valueVec.setIndexDefined(index); } }
@Override void addNext(int start, int index) { /* data read from Parquet into the bytebuf is already in BE format, no need * swap bytes to construct BigDecimal. only when we write BigDecimal to * data buffer of decimal vector, we need to swap bytes which the DecimalUtility * function already does. */ BigDecimal intermediate = DecimalHelper.getBigDecimalFromBEArrowBuf(bytebuf, index, schemaElement.getScale()); /* this will swap bytes as we are writing to the buffer of DecimalVector */ DecimalUtility.writeBigDecimalToArrowBuf(intermediate, valueVec.getDataBuffer(), index); valueVec.setIndexDefined(index); } }
private static void insertIntoDecimalVector(int index, int value, BaseFixedWidthVector vector) { DecimalVector vec = (DecimalVector)vector; DecimalHolder holder = new DecimalHolder(); holder.buffer = vec.getDataBuffer(); DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(value), holder.buffer, 0); holder.start = 0; holder.scale = 0; holder.precision = 38; vec.setSafe(index, holder); }
private static Pair<DecimalVector, ResultVerifier> testDecimalVector(final int startIndexInCurrentOutput, final int startIndexInJob) { DecimalVector colDecimalV = new DecimalVector("colDecimal", allocator, 10, 10); colDecimalV.allocateNew(5); DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(25.03).setScale(5, RoundingMode.HALF_UP), tempBuf, 0); colDecimalV.set(0, tempBuf); DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(2524324.034534), tempBuf, 0); colDecimalV.set(1, tempBuf); colDecimalV.setNull(2); DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(2523423423424234243234.235), tempBuf, 0); colDecimalV.set(3, tempBuf); DecimalUtility.writeBigDecimalToArrowBuf(new BigDecimal(2523423423424234243234.23524324234234), tempBuf, 0); colDecimalV.set(4, tempBuf); ResultVerifier verifier = new ResultVerifier() { @Override public void verify(DataPOJO output) { int index = startIndexInCurrentOutput; assertEquals(2.503E-4, ((Double)output.extractValue("colDecimal", index++)).doubleValue(), 0.001f); assertEquals(2.524324034534E23, ((Double)output.extractValue("colDecimal", index++)).doubleValue(), 0.001f); assertNull(output.extractValue("colDecimal", index++)); assertEquals(2.523423423424234E11, ((Double)output.extractValue("colDecimal", index++)).doubleValue(), 0.001f); assertEquals(2.523423423424234E11, ((Double)output.extractValue("colDecimal", index++)).doubleValue(), 0.001f); } }; return Pair.of(colDecimalV, verifier); }
@Override public boolean setSafe(int index, ArrowBuf bytebuf, int start, int length) { /* data read from Parquet into the bytebuf is already in BE format, no need * swap bytes to construct BigDecimal. only when we write BigDecimal to * data buffer of decimal vector, we need to swap bytes which the DecimalUtility * function already does. */ BigDecimal intermediate = DecimalHelper.getBigDecimalFromBEArrowBuf(bytebuf, index, schemaElement.getScale()); if (index >= decimalVector.getValueCapacity()) { return false; } /* this will swap bytes as we are writing to the buffer of DecimalVector */ DecimalUtility.writeBigDecimalToArrowBuf(intermediate, decimalVector.getDataBuffer(), index); decimalVector.setIndexDefined(index); return true; }
@Override public boolean setSafe(int index, ArrowBuf bytebuf, int start, int length) { /* data read from Parquet into the bytebuf is already in BE format, no need * swap bytes to construct BigDecimal. only when we write BigDecimal to * data buffer of decimal vector, we need to swap bytes which the DecimalUtility * function already does. */ BigDecimal intermediate = DecimalHelper.getBigDecimalFromBEArrowBuf(bytebuf, index, schemaElement.getScale()); if (index >= decimalVector.getValueCapacity()) { return false; } /* this will swap bytes as we are writing to the buffer of DecimalVector */ DecimalUtility.writeBigDecimalToArrowBuf(intermediate, decimalVector.getDataBuffer(), index); decimalVector.setIndexDefined(index); return true; }
DecimalUtility.writeBigDecimalToArrowBuf(val, tempBuf, 0); in.set(i + j, tempBuf); if (j % 3 == 0) { BigDecimal val = new BigDecimal(i + j + ((double) (i + j) / count)).setScale(0, RoundingMode.HALF_UP); DecimalUtility.writeBigDecimalToArrowBuf(val, tempBuf, 0); in.set(i + j, tempBuf);