|
35 | 35 | import io.trino.spi.type.LongTimestamp; |
36 | 36 | import io.trino.spi.type.LongTimestampWithTimeZone; |
37 | 37 | import io.trino.spi.type.MapType; |
| 38 | +import io.trino.spi.type.NumberType; |
38 | 39 | import io.trino.spi.type.RealType; |
39 | 40 | import io.trino.spi.type.RowType; |
40 | 41 | import io.trino.spi.type.SmallintType; |
| 42 | +import io.trino.spi.type.SqlNumber; |
41 | 43 | import io.trino.spi.type.StandardTypes; |
42 | 44 | import io.trino.spi.type.TimeType; |
43 | 45 | import io.trino.spi.type.TimeWithTimeZoneType; |
44 | 46 | import io.trino.spi.type.TimeZoneKey; |
45 | 47 | import io.trino.spi.type.TimestampType; |
46 | 48 | import io.trino.spi.type.TimestampWithTimeZoneType; |
47 | 49 | import io.trino.spi.type.TinyintType; |
| 50 | +import io.trino.spi.type.TrinoNumber; |
48 | 51 | import io.trino.spi.type.Type; |
49 | 52 | import io.trino.spi.type.VarcharType; |
50 | 53 |
|
@@ -170,6 +173,7 @@ private static TrinoType singletonType(Type type) |
170 | 173 | case StandardTypes.JSON -> TrinoType.JSON; |
171 | 174 | case StandardTypes.UUID -> TrinoType.UUID; |
172 | 175 | case StandardTypes.IPADDRESS -> TrinoType.IPADDRESS; |
| 176 | + case StandardTypes.NUMBER -> TrinoType.NUMBER; |
173 | 177 | default -> throw new TrinoException(NOT_SUPPORTED, "Unsupported type: " + type); |
174 | 178 | }; |
175 | 179 | } |
@@ -202,6 +206,15 @@ private static void javaToBinary(Type type, Object value, SliceOutput output) |
202 | 206 | : Decimals.toString((Int128) value, decimalType.getScale()); |
203 | 207 | writeVariableSlice(utf8Slice(decimalString), output); |
204 | 208 | } |
| 209 | + case NumberType _ -> { |
| 210 | + TrinoNumber number = (TrinoNumber) value; |
| 211 | + String stringValue = switch (number.toBigDecimal()) { |
| 212 | + case TrinoNumber.BigDecimalValue(BigDecimal bigDecimal) -> bigDecimal.toString(); |
| 213 | + case TrinoNumber.Infinity(boolean negative) -> negative ? "-Infinity" : "+Infinity"; |
| 214 | + case TrinoNumber.NotANumber() -> "NaN"; |
| 215 | + }; |
| 216 | + writeVariableSlice(utf8Slice(stringValue), output); |
| 217 | + } |
205 | 218 | case TimeWithTimeZoneType timeType -> { |
206 | 219 | if (timeType.isShort()) { |
207 | 220 | long time = (long) value; |
@@ -284,6 +297,15 @@ private static void blockToBinary(Type type, Block block, int position, SliceOut |
284 | 297 | : Decimals.toString((Int128) decimalType.getObject(block, position), decimalType.getScale()); |
285 | 298 | writeVariableSlice(utf8Slice(decimalString), output); |
286 | 299 | } |
| 300 | + case NumberType numberType -> { |
| 301 | + SqlNumber value = (SqlNumber) numberType.getObjectValue(block, position); |
| 302 | + String stringValue = switch (value.value()) { |
| 303 | + case TrinoNumber.BigDecimalValue(BigDecimal bigDecimal) -> bigDecimal.toString(); |
| 304 | + case TrinoNumber.Infinity(boolean negative) -> negative ? "-Infinity" : "+Infinity"; |
| 305 | + case TrinoNumber.NotANumber() -> "NaN"; |
| 306 | + }; |
| 307 | + writeVariableSlice(utf8Slice(stringValue), output); |
| 308 | + } |
287 | 309 | case DateType dateType -> output.writeInt(dateType.getInt(block, position)); |
288 | 310 | case TimeType timeType -> output.writeLong(picosToMicros(timeType.getLong(block, position))); |
289 | 311 | case TimeWithTimeZoneType timeType -> { |
@@ -394,6 +416,16 @@ public static Object binaryToJava(Type type, SliceInput input) |
394 | 416 | e); |
395 | 417 | } |
396 | 418 | } |
| 419 | + case NumberType _ -> { |
| 420 | + String stringUtf8 = input.readSlice(input.readInt()).toStringUtf8(); |
| 421 | + TrinoNumber.AsBigDecimal number = switch (stringUtf8) { |
| 422 | + case "NaN" -> new TrinoNumber.NotANumber(); |
| 423 | + case "+Infinity" -> new TrinoNumber.Infinity(false); |
| 424 | + case "-Infinity" -> new TrinoNumber.Infinity(true); |
| 425 | + default -> new TrinoNumber.BigDecimalValue(new BigDecimal(stringUtf8)); |
| 426 | + }; |
| 427 | + yield TrinoNumber.from(number); |
| 428 | + } |
397 | 429 | case TimeType timeType -> { |
398 | 430 | long micros = roundMicros(input.readLong(), timeType.getPrecision()) % MICROSECONDS_PER_DAY; |
399 | 431 | yield micros * PICOSECONDS_PER_MICROSECOND; |
|
0 commit comments