@@ -73,6 +73,14 @@ public ResultSetLatestIT() {
73
73
super (queryResultFormat );
74
74
}
75
75
76
+ private String createTableSql =
77
+ "Create or replace table get_object_for_numeric_types (c1 INT, c2 BIGINT, c3 SMALLINT, c4 TINYINT) " ;
78
+ private String insertStmt =
79
+ "Insert into get_object_for_numeric_types (c1, c2, c3, c4) values (1000000000, 2000000000000000000000000, 3, 4)" ;
80
+ private String selectQuery = "Select * from get_object_for_numeric_types" ;
81
+ private String setJdbcTreatDecimalAsIntFalse =
82
+ "alter session set JDBC_TREAT_DECIMAL_AS_INT = false" ;
83
+
76
84
/**
77
85
* Test that when closing of results is interrupted by Thread.Interrupt(), the memory is released
78
86
* safely before driver execution ends.
@@ -971,4 +979,94 @@ public void testLargeStringRetrieval() throws SQLException {
971
979
fail ("executeQuery should not fail" );
972
980
}
973
981
}
982
+
983
+ private static void assertAllColumnsAreLongButBigIntIsBigDecimal (ResultSet rs )
984
+ throws SQLException {
985
+ while (rs .next ()) {
986
+ assertEquals (java .lang .Long .class , rs .getObject (1 ).getClass ());
987
+ assertEquals (java .math .BigDecimal .class , rs .getObject (2 ).getClass ());
988
+ assertEquals (java .lang .Long .class , rs .getObject (3 ).getClass ());
989
+ assertEquals (java .lang .Long .class , rs .getObject (4 ).getClass ());
990
+ }
991
+ }
992
+
993
+ private static void assertAllColumnsAreBigDecimal (ResultSet rs ) throws SQLException {
994
+ while (rs .next ()) {
995
+ assertEquals (java .math .BigDecimal .class , rs .getObject (1 ).getClass ());
996
+ assertEquals (java .math .BigDecimal .class , rs .getObject (2 ).getClass ());
997
+ assertEquals (java .math .BigDecimal .class , rs .getObject (3 ).getClass ());
998
+ assertEquals (java .math .BigDecimal .class , rs .getObject (4 ).getClass ());
999
+ }
1000
+ }
1001
+
1002
+ // Test setting new connection property JDBC_ARROW_TREAT_DECIMAL_AS_INT=false. Connection property
1003
+ // introduced after version 3.15.0.
1004
+ @ Test
1005
+ public void testGetObjectForArrowResultFormatJDBCArrowDecimalAsIntFalse () throws SQLException {
1006
+ Properties properties = new Properties ();
1007
+ properties .put ("JDBC_ARROW_TREAT_DECIMAL_AS_INT" , false );
1008
+ try (Connection con = getConnection (properties );
1009
+ Statement stmt = con .createStatement ()) {
1010
+ stmt .execute ("alter session set jdbc_query_result_format = 'ARROW'" );
1011
+ stmt .execute (createTableSql );
1012
+ stmt .execute (insertStmt );
1013
+
1014
+ // Test with JDBC_ARROW_TREAT_DECIMAL_AS_INT=false and JDBC_TREAT_DECIMAL_AS_INT=true
1015
+ try (ResultSet rs = stmt .executeQuery (selectQuery )) {
1016
+ assertAllColumnsAreLongButBigIntIsBigDecimal (rs );
1017
+ }
1018
+
1019
+ // Test with JDBC_ARROW_TREAT_DECIMAL_AS_INT=false and JDBC_TREAT_DECIMAL_AS_INT=false
1020
+ stmt .execute (setJdbcTreatDecimalAsIntFalse );
1021
+ try (ResultSet rs = stmt .executeQuery (selectQuery )) {
1022
+ assertAllColumnsAreBigDecimal (rs );
1023
+ }
1024
+ }
1025
+ }
1026
+
1027
+ // Test default setting of new connection property JDBC_ARROW_TREAT_DECIMAL_AS_INT=true.
1028
+ // Connection property introduced after version 3.15.0.
1029
+ @ Test
1030
+ public void testGetObjectForArrowResultFormatJDBCArrowDecimalAsIntTrue () throws SQLException {
1031
+ try (Connection con = BaseJDBCTest .getConnection ();
1032
+ Statement stmt = con .createStatement ()) {
1033
+ stmt .execute ("alter session set jdbc_query_result_format = 'ARROW'" );
1034
+ stmt .execute (createTableSql );
1035
+ stmt .execute (insertStmt );
1036
+
1037
+ // Test with JDBC_ARROW_TREAT_DECIMAL_AS_INT=true and JDBC_TREAT_DECIMAL_AS_INT=true
1038
+ try (ResultSet rs = stmt .executeQuery (selectQuery )) {
1039
+ assertAllColumnsAreLongButBigIntIsBigDecimal (rs );
1040
+ }
1041
+
1042
+ // Test with JDBC_ARROW_TREAT_DECIMAL_AS_INT=true and JDBC_TREAT_DECIMAL_AS_INT=false
1043
+ stmt .execute (setJdbcTreatDecimalAsIntFalse );
1044
+ try (ResultSet rs = stmt .executeQuery (selectQuery )) {
1045
+ assertAllColumnsAreLongButBigIntIsBigDecimal (rs );
1046
+ }
1047
+ }
1048
+ }
1049
+
1050
+ // Test getObject for numeric types when JDBC_TREAT_DECIMAL_AS_INT is set and using JSON result
1051
+ // format.
1052
+ @ Test
1053
+ public void testGetObjectForJSONResultFormatUsingJDBCDecimalAsInt () throws SQLException {
1054
+ try (Connection con = BaseJDBCTest .getConnection ();
1055
+ Statement stmt = con .createStatement ()) {
1056
+ stmt .execute ("alter session set jdbc_query_result_format = 'JSON'" );
1057
+ stmt .execute (createTableSql );
1058
+ stmt .execute (insertStmt );
1059
+
1060
+ // Test with JDBC_TREAT_DECIMAL_AS_INT=true (default value)
1061
+ try (ResultSet rs = stmt .executeQuery (selectQuery )) {
1062
+ assertAllColumnsAreLongButBigIntIsBigDecimal (rs );
1063
+ }
1064
+
1065
+ // Test with JDBC_TREAT_DECIMAL_AS_INT=false
1066
+ stmt .execute (setJdbcTreatDecimalAsIntFalse );
1067
+ try (ResultSet rs = stmt .executeQuery (selectQuery )) {
1068
+ assertAllColumnsAreBigDecimal (rs );
1069
+ }
1070
+ }
1071
+ }
974
1072
}
0 commit comments