68
68
import static io .trino .spi .type .BigintType .BIGINT ;
69
69
import static io .trino .spi .type .BooleanType .BOOLEAN ;
70
70
import static io .trino .spi .type .DoubleType .DOUBLE ;
71
+ import static io .trino .spi .type .RealType .REAL ;
71
72
import static io .trino .spi .type .VarcharType .VARCHAR ;
72
73
import static io .trino .spi .type .VarcharType .createVarcharType ;
73
74
import static io .trino .type .InternalTypeManager .TESTING_TYPE_MANAGER ;
75
+ import static java .lang .Float .floatToIntBits ;
74
76
import static java .lang .String .format ;
75
77
import static org .assertj .core .api .Assertions .assertThat ;
76
78
@@ -93,6 +95,13 @@ public class TestPostgreSqlClient
93
95
.setJdbcTypeHandle (new JdbcTypeHandle (Types .DOUBLE , Optional .of ("double" ), Optional .empty (), Optional .empty (), Optional .empty (), Optional .empty ()))
94
96
.build ();
95
97
98
+ private static final JdbcColumnHandle REAL_COLUMN =
99
+ JdbcColumnHandle .builder ()
100
+ .setColumnName ("c_real" )
101
+ .setColumnType (REAL )
102
+ .setJdbcTypeHandle (new JdbcTypeHandle (Types .REAL , Optional .of ("real" ), Optional .empty (), Optional .empty (), Optional .empty (), Optional .empty ()))
103
+ .build ();
104
+
96
105
private static final JdbcColumnHandle VARCHAR_COLUMN =
97
106
JdbcColumnHandle .builder ()
98
107
.setColumnName ("c_varchar" )
@@ -235,15 +244,18 @@ public void testConvertOr()
235
244
Logical .Operator .OR ,
236
245
List .of (
237
246
new Comparison (Comparison .Operator .EQUAL , new Reference (BIGINT , "c_bigint_symbol" ), new Constant (BIGINT , 42L )),
238
- new Comparison (Comparison .Operator .EQUAL , new Reference (BIGINT , "c_bigint_symbol_2" ), new Constant (BIGINT , 415L ))))),
247
+ new Comparison (Comparison .Operator .EQUAL , new Reference (REAL , "c_real_symbol" ), new Constant (REAL , (long ) floatToIntBits (3.14f ))),
248
+ new Comparison (Comparison .Operator .EQUAL , new Reference (DOUBLE , "c_double_symbol" ), new Constant (DOUBLE , 3.14 ))))),
239
249
Map .of (
240
250
"c_bigint_symbol" , BIGINT_COLUMN ,
241
- "c_bigint_symbol_2" , BIGINT_COLUMN ))
251
+ "c_real_symbol" , REAL_COLUMN ,
252
+ "c_double_symbol" , DOUBLE_COLUMN ))
242
253
.orElseThrow ();
243
- assertThat (converted .expression ()).isEqualTo ("((\" c_bigint\" ) = (?)) OR ((\" c_bigint \" ) = (?))" );
254
+ assertThat (converted .expression ()).isEqualTo ("((\" c_bigint\" ) = (?)) OR ((\" c_real \" ) = (?)) OR (( \" c_double \" ) = (?))" );
244
255
assertThat (converted .parameters ()).isEqualTo (List .of (
245
256
new QueryParameter (BIGINT , Optional .of (42L )),
246
- new QueryParameter (BIGINT , Optional .of (415L ))));
257
+ new QueryParameter (REAL , Optional .of ((long ) floatToIntBits (3.14f ))),
258
+ new QueryParameter (DOUBLE , Optional .of (3.14 ))));
247
259
}
248
260
249
261
@ Test
@@ -279,8 +291,16 @@ public void testConvertComparison()
279
291
Optional <ParameterizedExpression > converted = JDBC_CLIENT .convertPredicate (
280
292
SESSION ,
281
293
translateToConnectorExpression (
282
- new Comparison (operator , new Reference (BIGINT , "c_bigint_symbol" ), new Constant (BIGINT , 42L ))),
283
- Map .of ("c_bigint_symbol" , BIGINT_COLUMN ));
294
+ new Logical (
295
+ Logical .Operator .OR ,
296
+ List .of (
297
+ new Comparison (operator , new Reference (BIGINT , "c_bigint_symbol" ), new Constant (BIGINT , 42L )),
298
+ new Comparison (operator , new Reference (REAL , "c_real_symbol" ), new Constant (REAL , (long ) floatToIntBits (3.14f ))),
299
+ new Comparison (operator , new Reference (DOUBLE , "c_double_symbol" ), new Constant (DOUBLE , 3.14 ))))),
300
+ Map .of (
301
+ "c_bigint_symbol" , BIGINT_COLUMN ,
302
+ "c_real_symbol" , REAL_COLUMN ,
303
+ "c_double_symbol" , DOUBLE_COLUMN ));
284
304
285
305
switch (operator ) {
286
306
case EQUAL :
@@ -290,8 +310,11 @@ public void testConvertComparison()
290
310
case GREATER_THAN :
291
311
case GREATER_THAN_OR_EQUAL :
292
312
assertThat (converted ).isPresent ();
293
- assertThat (converted .get ().expression ()).isEqualTo (format ("(\" c_bigint\" ) %s (?)" , operator .getValue ()));
294
- assertThat (converted .get ().parameters ()).isEqualTo (List .of (new QueryParameter (BIGINT , Optional .of (42L ))));
313
+ assertThat (converted .get ().expression ()).isEqualTo (format ("((\" c_bigint\" ) %1$s (?)) OR ((\" c_real\" ) %1$s (?)) OR ((\" c_double\" ) %1$s (?))" , operator .getValue ()));
314
+ assertThat (converted .get ().parameters ()).isEqualTo (List .of (
315
+ new QueryParameter (BIGINT , Optional .of (42L )),
316
+ new QueryParameter (REAL , Optional .of ((long ) floatToIntBits (3.14f ))),
317
+ new QueryParameter (DOUBLE , Optional .of (3.14 ))));
295
318
break ;
296
319
case IDENTICAL :
297
320
assertThat (converted ).isPresent ();
0 commit comments