value = (((BigDecimal) PDecimal.INSTANCE.toObject(ptr, type, sortOrder)).multiply(QueryConstants.BD_MILLIS_IN_DAY)).setScale(6, RoundingMode.HALF_UP); } else if (type.isCoercibleTo(PDouble.INSTANCE)) { value = ((BigDecimal.valueOf(type.getCodec().decodeDouble(ptr, sortOrder))).multiply(QueryConstants.BD_MILLIS_IN_DAY)).setScale(6, RoundingMode.HALF_UP); } else { value = BigDecimal.valueOf(type.getCodec().decodeLong(ptr, sortOrder));
@Override public int signum(byte[] bytes, int offset, int length, SortOrder sortOrder, Integer maxLength, Integer scale) { double d = getCodec().decodeDouble(bytes, offset, sortOrder); if (Double.isNaN(d)) { throw new IllegalDataException(); } return (d > 0) ? 1 : ((d < 0) ? -1 : 0); }
value = (((BigDecimal) PDecimal.INSTANCE.toObject(ptr, type, sortOrder)).multiply(BD_MILLIS_IN_DAY)).setScale(6, RoundingMode.HALF_UP); } else if (type.isCoercibleTo(PDouble.INSTANCE)) { value = ((BigDecimal.valueOf(type.getCodec().decodeDouble(ptr, sortOrder))).multiply(BD_MILLIS_IN_DAY)).setScale(6, RoundingMode.HALF_UP); } else { value = BigDecimal.valueOf(type.getCodec().decodeLong(ptr, sortOrder));
@Override public int signum(byte[] bytes, int offset, int length, SortOrder sortOrder, Integer maxLength, Integer scale) { double d = getCodec().decodeDouble(bytes, offset, sortOrder); if (Double.isNaN(d)) { throw new IllegalDataException(); } return (d > 0) ? 1 : ((d < 0) ? -1 : 0); }
@Override public void abs(byte[] bytes, int offset, int length, SortOrder sortOrder, ImmutableBytesWritable outPtr) { double d = getCodec().decodeDouble(bytes, offset, sortOrder); getCodec().encodeDouble(Math.abs(d), outPtr); } }
.decodeLong(rhs, rhsOffset, rhsSortOrder)); } else if (isDoubleOrFloat(this) && isDoubleOrFloat(rhsType)) { // native double to double comparison return Doubles.compare(this.getCodec().decodeDouble(lhs, lhsOffset, lhsSortOrder), rhsType.getCodec() .decodeDouble(rhs, rhsOffset, rhsSortOrder)); } else { // native float/double to long comparison float fvalue = 0.0F; fvalue = this.getCodec().decodeFloat(lhs, lhsOffset, lhsSortOrder); } else if (this.isCoercibleTo(PDouble.INSTANCE)) { dvalue = this.getCodec().decodeDouble(lhs, lhsOffset, lhsSortOrder); } else if (rhsType.isCoercibleTo(PDouble.INSTANCE)) { invert = -1; dvalue = rhsType.getCodec().decodeDouble(rhs, rhsOffset, rhsSortOrder);
ImmutableBytesWritable ptr = new ImmutableBytesWritable(); ptr.set(b); nb = PDouble.INSTANCE.getCodec().decodeDouble(ptr, SortOrder.DESC); assertEquals(na,nb); ba = PDouble.INSTANCE.toBytes(na); bb = PDouble.INSTANCE.toBytes(nb); double nna = PDouble.INSTANCE.getCodec().decodeDouble(ba, 0, SortOrder.DESC); double nnb = PDouble.INSTANCE.getCodec().decodeDouble(bb, 0, SortOrder.DESC); assertTrue(Double.compare(nna, nnb) < 0);
ImmutableBytesWritable ptr = new ImmutableBytesWritable(); ptr.set(b); nb = PUnsignedDouble.INSTANCE.getCodec().decodeDouble(ptr, SortOrder.DESC); assertEquals(na,nb);
return BigDecimal.valueOf(actualType.getCodec().decodeFloat(b, o, sortOrder)); } else if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE)) { return BigDecimal.valueOf(actualType.getCodec().decodeDouble(b, o, sortOrder)); } else if (equalsAny(actualType, PTimestamp.INSTANCE, PUnsignedTimestamp.INSTANCE)) { long millisPart = DateUtil.getCodecFor(actualType).decodeLong(b, o, sortOrder);
value = type.getCodec().decodeLong(ptr, sortOrder) * QueryConstants.MILLIS_IN_DAY; } else if (type.isCoercibleTo(PDouble.INSTANCE)) { value = (long)(type.getCodec().decodeDouble(ptr, sortOrder) * QueryConstants.MILLIS_IN_DAY); } else { value = type.getCodec().decodeLong(ptr, sortOrder);
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { double result = 0.0; for (int i = 0; i < children.size(); i++) { Expression child = children.get(i); if (!child.evaluate(tuple, ptr)) { return false; } if (ptr.getLength() == 0) { return true; } double childvalue = child.getDataType().getCodec() .decodeDouble(ptr, child.getSortOrder()); if (!Double.isNaN(childvalue) && childvalue != Double.NEGATIVE_INFINITY && childvalue != Double.POSITIVE_INFINITY) { if (i == 0) { result = childvalue; } else { result /= childvalue; } } else { return false; } } byte[] resultPtr = new byte[getDataType().getByteSize()]; getDataType().getCodec().encodeDouble(result, resultPtr, 0); ptr.set(resultPtr); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { double result = 0.0; for (int i = 0; i < children.size(); i++) { Expression child = children.get(i); if (!child.evaluate(tuple, ptr)) { return false; } if (ptr.getLength() == 0) { return true; } double childvalue = child.getDataType().getCodec() .decodeDouble(ptr, child.getSortOrder()); if (!Double.isNaN(childvalue) && childvalue != Double.NEGATIVE_INFINITY && childvalue != Double.POSITIVE_INFINITY) { if (i == 0) { result = childvalue; } else { result -= childvalue; } } else { return false; } } byte[] resultPtr = new byte[getDataType().getByteSize()]; getDataType().getCodec().encodeDouble(result, resultPtr, 0); ptr.set(resultPtr); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { double result = 0.0; for (int i = 0; i < children.size(); i++) { Expression child = children.get(i); if (!child.evaluate(tuple, ptr)) { return false; } if (ptr.getLength() == 0) { return true; } double childvalue = child.getDataType().getCodec() .decodeDouble(ptr, child.getSortOrder()); if (!Double.isNaN(childvalue) && childvalue != Double.NEGATIVE_INFINITY && childvalue != Double.POSITIVE_INFINITY) { result += childvalue; } else { return false; } } byte[] resultPtr = new byte[getDataType().getByteSize()]; getDataType().getCodec().encodeDouble(result, resultPtr, 0); ptr.set(resultPtr); return true; }
@Override public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) { double result = 1.0; for (int i = 0; i < children.size(); i++) { Expression child = children.get(i); if (!child.evaluate(tuple, ptr)) { return false; } if (ptr.getLength() == 0) { return true; } double childvalue = child.getDataType().getCodec() .decodeDouble(ptr, child.getSortOrder()); if (!Double.isNaN(childvalue) && childvalue != Double.NEGATIVE_INFINITY && childvalue != Double.POSITIVE_INFINITY) { result *= childvalue; } else { return false; } } byte[] resultPtr = new byte[getDataType().getByteSize()]; getDataType().getCodec().encodeDouble(result, resultPtr, 0); ptr.set(resultPtr); return true; }
value = type.getCodec().decodeLong(ptr, sortOrder) * QueryConstants.MILLIS_IN_DAY; } else if (type.isCoercibleTo(PDouble.INSTANCE)) { value = (long)(type.getCodec().decodeDouble(ptr, sortOrder) * QueryConstants.MILLIS_IN_DAY); } else { value = type.getCodec().decodeLong(ptr, sortOrder);
@Override public Double toObject(byte[] b, int o, int l, PDataType actualType, SortOrder sortOrder, Integer maxLength, Integer scale) { if (l <= 0) { return null; } if (equalsAny(actualType, PDouble.INSTANCE, PUnsignedDouble.INSTANCE, PFloat.INSTANCE, PUnsignedFloat.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE, PInteger.INSTANCE, PUnsignedInt.INSTANCE, PSmallint.INSTANCE, PUnsignedSmallint.INSTANCE, PTinyint.INSTANCE, PUnsignedTinyint.INSTANCE)) { return actualType.getCodec().decodeDouble(b, o, sortOrder); } else if (actualType == PDecimal.INSTANCE) { BigDecimal bd = (BigDecimal) actualType.toObject(b, o, l, actualType, sortOrder); return bd.doubleValue(); } throwConstraintViolationException(actualType, this); return null; }
public DoubleSumAggregator(SortOrder sortOrder, ImmutableBytesWritable ptr) { super(sortOrder); if (ptr != null) { initBuffer(); sum = PDouble.INSTANCE.getCodec().decodeDouble(ptr, sortOrder); } }
static double getArg(Expression exp, ImmutableBytesWritable ptr) { if (exp.getDataType() == PDecimal.INSTANCE) { return ((BigDecimal) exp.getDataType().toObject(ptr, exp.getSortOrder())).doubleValue(); } else { return exp.getDataType().getCodec().decodeDouble(ptr, exp.getSortOrder()); } }
@Override public void abs(byte[] bytes, int offset, int length, SortOrder sortOrder, ImmutableBytesWritable outPtr) { double d = getCodec().decodeDouble(bytes, offset, sortOrder); getCodec().encodeDouble(Math.abs(d), outPtr); } }
@Override public void aggregate(Tuple tuple, ImmutableBytesWritable ptr) { double value = getInputDataType().getCodec().decodeDouble(ptr, sortOrder); sum += value; if (buffer == null) { initBuffer(); } }