deserializeTypeNumeric handles deserialization from the Dolt serialized format to our standard representation used by expressions and nodes. Note: this function is only used for values serialized by older clients, which is why it uses a decimal.Decimal. Newer clients will use Dolt's serialization, w
(ctx *sql.Context, t *DoltgresType, data []byte)
| 161 | // Newer clients will use Dolt's serialization, which uses apd.Decimal directly. |
| 162 | // Deprecated. |
| 163 | func deserializeTypeNumeric(ctx *sql.Context, t *DoltgresType, data []byte) (any, error) { |
| 164 | if len(data) == 0 { |
| 165 | return nil, nil |
| 166 | } |
| 167 | retVal := decimal.NewFromInt(0) |
| 168 | err := retVal.UnmarshalBinary(data) |
| 169 | if err != nil { |
| 170 | return nil, err |
| 171 | } |
| 172 | // Coefficient() returns a *big.Int; CoefficientInt64() would silently overflow for |
| 173 | // values whose coefficient exceeds int64 (e.g. large JSONB numbers in legacy format). |
| 174 | coeff := retVal.Coefficient() |
| 175 | d := new(apd.Decimal) |
| 176 | d.Exponent = retVal.Exponent() |
| 177 | if coeff.Sign() < 0 { |
| 178 | d.Negative = true |
| 179 | d.Coeff.SetMathBigInt(new(big.Int).Neg(coeff)) |
| 180 | } else { |
| 181 | d.Coeff.SetMathBigInt(coeff) |
| 182 | } |
| 183 | return d, nil |
| 184 | } |
| 185 | |
| 186 | // NumericCompare compares two *apd.Decimal values handling NaN separately. |
| 187 | func NumericCompare(ab, bb *apd.Decimal) int { |
nothing calls this directly
no test coverage detected