@Override public void encode(final BsonWriter writer, final BsonDecimal128 value, final EncoderContext encoderContext) { writer.writeDecimal128(value.getValue()); }
@Override public Decimal128 doReadDecimal128() { return currentValue.asDecimal128().getValue(); }
colValue = keyvalueforStruct.getValue().asDecimal128().getValue().toString(); break; list.add(temp); } else if (arrValue.getBsonType() == BsonType.DECIMAL128 && valueType == BsonType.DECIMAL128) { String temp = arrValue.asDecimal128().getValue().toString(); list.add(temp); } else if (arrValue.getBsonType() == BsonType.TIMESTAMP && valueType == BsonType.TIMESTAMP) {
break; case DECIMAL128: writeDecimal128(value.asDecimal128().getValue()); break; case MIN_KEY:
public static Object extractValueEx(BsonValue value) { switch (value.getBsonType()) { case DOUBLE: return value.asDouble().getValue(); case STRING: return value.asString().getValue(); case OBJECT_ID: return value.asObjectId().getValue(); case INT32: return value.asInt32().getValue(); case INT64: return value.asInt64().getValue(); case DECIMAL128: return value.asDecimal128().getValue(); case NULL: return null; } throw new IllegalArgumentException("Unsupported ID type: " + value.getClass()); }
@TestFactory @DisplayName("tests for logical type decimal field conversions (new)") public List<DynamicTest> testDecimalFieldConverterNew() { SinkFieldConverter converter = new DecimalFieldConverter(); List<DynamicTest> tests = new ArrayList<>(); new ArrayList<>(Arrays.asList( new BigDecimal("-1234567890.09876543210"), BigDecimal.ZERO, new BigDecimal("+1234567890.09876543210") )).forEach( el -> tests.add(dynamicTest("conversion with " + converter.getClass().getSimpleName() + " for "+el, () -> assertEquals(el, ((BsonDecimal128)converter.toBson(el)).getValue().bigDecimalValue()) )) ); tests.add(dynamicTest("optional type conversions", () -> { Schema valueOptionalDefault = Decimal.builder(0).optional().defaultValue(BigDecimal.ZERO); assertAll("checks", () -> assertThrows(DataException.class, () -> converter.toBson(null, Decimal.schema(0))), () -> assertEquals(new BsonNull(), converter.toBson(null, Decimal.builder(0).optional())), () -> assertEquals(valueOptionalDefault.defaultValue(), ((BsonDecimal128)converter.toBson(null,valueOptionalDefault)).getValue().bigDecimalValue()) ); })); return tests; }