public int getTypeScale() { return type.getScale(); }
public TopNCounterSerializer(DataType dataType) { this.precision = dataType.getPrecision(); this.scale = dataType.getScale(); if (scale < 0) { scale = DictionaryDimEnc.MAX_ENCODING_LENGTH; } }
@Override public void serialize(BigDecimal value, ByteBuffer out) { if (value == null) { BytesUtil.writeVInt(0, out); BytesUtil.writeVInt(-1, out); return; } if (value.scale() > type.getScale()) { if (avoidVerbose++ % 10000 == 0) { logger.warn("value's scale has exceeded the " + type.getScale() + ", cut it off, to ensure encoded value do not exceed maxLength " + maxLength + " times:" + (avoidVerbose)); } value = value.setScale(type.getScale(), BigDecimal.ROUND_HALF_EVEN); } byte[] bytes = value.unscaledValue().toByteArray(); if (bytes.length + 2 > maxLength) { throw new IllegalArgumentException("'" + value + "' exceeds the expected length for type " + type); } BytesUtil.writeVInt(value.scale(), out); BytesUtil.writeVInt(bytes.length, out); out.put(bytes); }
@Test public void testScaleOutOfRange() { BigDecimal input = new BigDecimal("1234.1234567890"); ByteBuffer buffer = ByteBuffer.allocate(256); buffer.mark(); bigDecimalSerializer.serialize(input, buffer); buffer.reset(); BigDecimal output = bigDecimalSerializer.deserialize(buffer); assertEquals(input.setScale(bigDecimalSerializer.type.getScale(), BigDecimal.ROUND_HALF_EVEN), output); }
int scale = dataType.getScale();
public int getTypeScale() { return type.getScale(); }
public int getTypeScale() { return type.getScale(); }
public FixedPointLongCodec(DataType type) { this.type = type; this.scale = Math.max(0, type.getScale()); }
public FixedPointLongCodec(DataType type) { this.type = type; this.scale = Math.max(0, type.getScale()); this.scalePower = new BigDecimal((long) Math.pow(10, scale)); }
public TopNCounterSerializer(DataType dataType) { this.precision = dataType.getPrecision(); this.scale = dataType.getScale(); if (scale < 0) { scale = DictionaryDimEnc.MAX_ENCODING_LENGTH; } }
@Override public void serialize(BigDecimal value, ByteBuffer out) { if (value.scale() > type.getScale()) { if (avoidVerbose++ % 10000 == 0) { logger.warn("value's scale has exceeded the " + type.getScale() + ", cut it off, to ensure encoded value do not exceed maxLength " + maxLength + " times:" + (avoidVerbose)); } value = value.setScale(type.getScale(), BigDecimal.ROUND_HALF_EVEN); } byte[] bytes = value.unscaledValue().toByteArray(); if (bytes.length + 2 > maxLength) { throw new IllegalArgumentException("'" + value + "' exceeds the expected length for type " + type); } BytesUtil.writeVInt(value.scale(), out); BytesUtil.writeVInt(bytes.length, out); out.put(bytes); }
@Override public void serialize(BigDecimal value, ByteBuffer out) { if (value == null) { BytesUtil.writeVInt(0, out); BytesUtil.writeVInt(-1, out); return; } if (value.scale() > type.getScale()) { if (avoidVerbose++ % 10000 == 0) { logger.warn("value's scale has exceeded the " + type.getScale() + ", cut it off, to ensure encoded value do not exceed maxLength " + maxLength + " times:" + (avoidVerbose)); } value = value.setScale(type.getScale(), BigDecimal.ROUND_HALF_EVEN); } byte[] bytes = value.unscaledValue().toByteArray(); if (bytes.length + 2 > maxLength) { throw new IllegalArgumentException("'" + value + "' exceeds the expected length for type " + type); } BytesUtil.writeVInt(value.scale(), out); BytesUtil.writeVInt(bytes.length, out); out.put(bytes); }
int scale = dataType.getScale();