11package tech .ydb .jdbc .impl ;
22
33import java .math .BigDecimal ;
4- import java .math .BigInteger ;
54import java .sql .Connection ;
65import java .sql .Date ;
76import java .sql .PreparedStatement ;
@@ -1230,10 +1229,16 @@ private void assertNextDate(ResultSet rs, int key, LocalDate ld) throws SQLExcep
12301229 public void decimalTest (SqlQueries .JdbcQuery query ) throws SQLException {
12311230 String upsert = TEST_TABLE .upsertOne (query , "c_Decimal" , "Decimal(22, 9)" );
12321231
1233- // YDB partially ignores Decimal(22, 9) limit, but have hard limit to 35 digits
1234- String maxValue = "9999999999" + "9999999999" + "9999999999" + "99999" ;
1235- BigDecimal closeToInf = new BigDecimal (new BigInteger (maxValue ), 9 );
1236- BigDecimal closeToNegInf = new BigDecimal (new BigInteger (maxValue ).negate (), 9 );
1232+ BigDecimal closeToInf = new BigDecimal ("9999999999999.999999999" );
1233+ BigDecimal closeToNegInf = new BigDecimal ("-9999999999999.999999999" );
1234+
1235+ // YDB partially ignores Decimal(22, 9) limit, but have hard limit to 35 digits
1236+ // BigDecimal inf = closeToInf.add(BigDecimal.valueOf(1, 9));
1237+ // BigDecimal negInf = closeToNegInf.subtract(BigDecimal.valueOf(1, 9));
1238+ BigDecimal inf = new BigDecimal ("100000000000000000000000000.000000000" );
1239+ BigDecimal negInf = new BigDecimal ("-100000000000000000000000000.000000000" );
1240+ BigDecimal nan = new BigDecimal ("100000000000000000000000000.000000001" );
1241+
12371242 try (PreparedStatement ps = jdbc .connection ().prepareStatement (upsert )) {
12381243 ps .setInt (1 , 1 );
12391244 ps .setBigDecimal (2 , BigDecimal .valueOf (1.5d ));
@@ -1254,20 +1259,20 @@ public void decimalTest(SqlQueries.JdbcQuery query) throws SQLException {
12541259 ps .setInt (1 , 5 );
12551260 ExceptionAssert .sqlException (""
12561261 + "Cannot cast to decimal type Decimal(22, 9): "
1257- + "[class java.math.BigDecimal: 100000000000000000000000000.000000000 ] is Infinite" ,
1258- () -> ps .setBigDecimal (2 , closeToInf . add ( BigDecimal . valueOf ( 1 , 9 )) )
1262+ + "[class java.math.BigDecimal: " + inf + " ] is Infinite" ,
1263+ () -> ps .setBigDecimal (2 , inf )
12591264 );
12601265
12611266 ExceptionAssert .sqlException (""
12621267 + "Cannot cast to decimal type Decimal(22, 9): "
1263- + "[class java.math.BigDecimal: -100000000000000000000000000.000000000 ] is -Infinite" ,
1264- () -> ps .setBigDecimal (2 , closeToNegInf . subtract ( BigDecimal . valueOf ( 1 , 9 )) )
1268+ + "[class java.math.BigDecimal: " + negInf + " ] is -Infinite" ,
1269+ () -> ps .setBigDecimal (2 , negInf )
12651270 );
12661271
12671272 ExceptionAssert .sqlException (""
12681273 + "Cannot cast to decimal type Decimal(22, 9): "
1269- + "[class java.math.BigDecimal: 100000000000000000000000000.000000001 ] is NaN" ,
1270- () -> ps .setBigDecimal (2 , closeToInf . add ( BigDecimal . valueOf ( 2 , 9 )) )
1274+ + "[class java.math.BigDecimal: " + nan + " ] is NaN" ,
1275+ () -> ps .setBigDecimal (2 , nan )
12711276 );
12721277 }
12731278
0 commit comments