Skip to content
This repository was archived by the owner on Oct 22, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.pingcap.tikv.meta.TiColumnInfo;
import com.pingcap.tikv.types.Converter;
import com.pingcap.tikv.types.DataType;
import com.pingcap.tikv.types.DecimalType;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.sql.Date;
Expand Down Expand Up @@ -220,7 +221,8 @@ private void encodeValue(CodecDataOutput cdo, Object value, DataType tp) {
encodeString(cdo, value);
break;
case TypeNewDecimal:
encodeDecimal(cdo, value);
DecimalType decimalType = (DecimalType) tp;
encodeDecimal(cdo, value, (int) decimalType.getLength(), decimalType.getDecimal());
break;
case TypeBit:
encodeBit(cdo, value);
Expand Down Expand Up @@ -333,17 +335,14 @@ private void encodeString(CodecDataOutput cdo, Object value) {
}
}

private void encodeDecimal(CodecDataOutput cdo, Object value) {
private void encodeDecimal(CodecDataOutput cdo, Object value, int precision, int frac) {
if (value instanceof MyDecimal) {
MyDecimal dec = (MyDecimal) value;
DecimalCodec.writeDecimal(cdo, dec, dec.precision(), dec.frac());
DecimalCodec.writeDecimal(cdo, dec, precision, frac);
} else if (value instanceof BigDecimal) {
MyDecimal dec = new MyDecimal();
BigDecimal decimal = (BigDecimal) value;
int prec = decimal.precision();
int frac = decimal.scale();
dec.fromString(((BigDecimal) value).toPlainString());
DecimalCodec.writeDecimal(cdo, dec, prec, frac);
DecimalCodec.writeDecimal(cdo, dec, precision, frac);
} else {
throw new CodecException("invalid decimal type " + value.getClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void testColumnDataType() {
new int[] {128, 0, 1, 0, 0, 0, 1, 5, 0, 6, 4, 139, 38, 172},
MetaUtils.TableBuilder.newBuilder()
.name("t")
.addColumn("c1", DecimalType.DECIMAL)
.addColumn("c1", new DecimalType(6, 4))
.build(),
new Object[] {new BigDecimal("11.9900")}),
// test bit
Expand Down Expand Up @@ -248,7 +248,7 @@ public void testNewRowTypes() {
.addColumn("c5", StringType.CHAR, 25)
.addColumn("c6", TimestampType.TIMESTAMP, 5)
.addColumn("c7", TimeType.TIME, 16)
.addColumn("c8", DecimalType.DECIMAL, 8)
.addColumn("c8", new DecimalType(6, 4), 8)
.addColumn("c9", IntegerType.YEAR, 12)
.addColumn("c10", TEST_ENUM_TYPE, 9)
// .addColumn("c11", JsonType.JSON, 14)
Expand Down