From 0e4e3df338e151dfb88da2a45c0673ed5189ecdf Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Tue, 12 Mar 2024 00:10:16 -0700 Subject: [PATCH] Trying fix for failing tests --- .../client/jdbc/ResultSetArrowLatestIT.java | 75 +----------- .../client/jdbc/ResultSetLatestIT.java | 112 ++++++++++++++---- 2 files changed, 95 insertions(+), 92 deletions(-) diff --git a/src/test/java/net/snowflake/client/jdbc/ResultSetArrowLatestIT.java b/src/test/java/net/snowflake/client/jdbc/ResultSetArrowLatestIT.java index ab07ae3d5..5ac08c118 100644 --- a/src/test/java/net/snowflake/client/jdbc/ResultSetArrowLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ResultSetArrowLatestIT.java @@ -3,16 +3,17 @@ */ package net.snowflake.client.jdbc; -import static org.junit.Assert.assertEquals; +import net.snowflake.client.category.TestCategoryArrow; +import org.junit.Test; +import org.junit.experimental.categories.Category; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; -import net.snowflake.client.category.TestCategoryArrow; -import org.junit.Test; -import org.junit.experimental.categories.Category; + +import static org.junit.Assert.assertEquals; /** * ResultSet integration tests for the latest JDBC driver. This doesn't work for the oldest @@ -23,70 +24,4 @@ public class ResultSetArrowLatestIT extends ResultSetLatestIT { public ResultSetArrowLatestIT() { super("arrow"); } - - // Test setting new connection property jdbc_arrow_treat_decimal_as_int=false. Connection property - // introduced after version 3.15.0. - @Test - public void testGetObjectForArrowResultFormatJDBCArrowDecimalAsIntFalse() throws SQLException { - Properties properties = new Properties(); - properties.put("jdbc_arrow_treat_decimal_as_int", false); - try (Connection con = init(properties); - Statement stmt = con.createStatement()) { - stmt.execute(createTableSql); - stmt.execute(insertStmt); - - // Test with jdbc_arrow_treat_decimal_as_int=false and JDBC_TREAT_DECIMAL_AS_INT=true - try (ResultSet rs = stmt.executeQuery(selectQuery)) { - while (rs.next()) { - assertEquals(rs.getObject(1).getClass().toString(), "class java.lang.Long"); - assertEquals(rs.getObject(2).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(3).getClass().toString(), "class java.lang.Long"); - assertEquals(rs.getObject(4).getClass().toString(), "class java.lang.Long"); - } - } - - // Test with jdbc_arrow_treat_decimal_as_int=false and JDBC_TREAT_DECIMAL_AS_INT=false - stmt.execute(setJdbcTreatDecimalAsIntFalse); - try (ResultSet rs = stmt.executeQuery(selectQuery)) { - while (rs.next()) { - assertEquals(rs.getObject(1).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(2).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(3).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(4).getClass().toString(), "class java.math.BigDecimal"); - } - } - } - } - - // Test default setting of new connection property jdbc_arrow_treat_decimal_as_int=true. - // Connection property introduced after version 3.15.0. - @Test - public void testGetObjectForArrowResultFormatJDBCArrowDecimalAsIntTrue() throws SQLException { - try (Connection con = init(); - Statement stmt = con.createStatement()) { - stmt.execute(createTableSql); - stmt.execute(insertStmt); - - // Test with jdbc_arrow_treat_decimal_as_int=true and JDBC_TREAT_DECIMAL_AS_INT=true - try (ResultSet rs = stmt.executeQuery(selectQuery)) { - while (rs.next()) { - assertEquals(rs.getObject(1).getClass().toString(), "class java.lang.Long"); - assertEquals(rs.getObject(2).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(3).getClass().toString(), "class java.lang.Long"); - assertEquals(rs.getObject(4).getClass().toString(), "class java.lang.Long"); - } - } - - // Test with jdbc_arrow_treat_decimal_as_int=true and JDBC_TREAT_DECIMAL_AS_INT=false - stmt.execute(setJdbcTreatDecimalAsIntFalse); - try (ResultSet rs = stmt.executeQuery(selectQuery)) { - while (rs.next()) { - assertEquals(rs.getObject(1).getClass().toString(), "class java.lang.Long"); - assertEquals(rs.getObject(2).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(3).getClass().toString(), "class java.lang.Long"); - assertEquals(rs.getObject(4).getClass().toString(), "class java.lang.Long"); - } - } - } - } } diff --git a/src/test/java/net/snowflake/client/jdbc/ResultSetLatestIT.java b/src/test/java/net/snowflake/client/jdbc/ResultSetLatestIT.java index 5a416ab8a..cd97a5817 100644 --- a/src/test/java/net/snowflake/client/jdbc/ResultSetLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ResultSetLatestIT.java @@ -73,12 +73,12 @@ public ResultSetLatestIT() { super(queryResultFormat); } - public String createTableSql = + private String createTableSql = "Create or replace table get_object_for_numeric_types (c1 INT, c2 BIGINT, c3 SMALLINT, c4 TINYINT) "; - public String insertStmt = + private String insertStmt = "Insert into get_object_for_numeric_types (c1, c2, c3, c4) values (1000000000, 2000000000000000000000000, 3, 4)"; - public String selectQuery = "Select * from get_object_for_numeric_types"; - public String setJdbcTreatDecimalAsIntFalse = + private String selectQuery = "Select * from get_object_for_numeric_types"; + private String setJdbcTreatDecimalAsIntFalse = "alter session set JDBC_TREAT_DECIMAL_AS_INT = false"; /** @@ -980,24 +980,91 @@ public void testLargeStringRetrieval() throws SQLException { } } + // Test setting new connection property jdbc_arrow_treat_decimal_as_int=false. Connection property introduced after version 3.15.0. + @Test + public void testGetObjectForArrowResultFormatJDBCArrowDecimalAsIntFalse() throws SQLException { + Properties properties = new Properties(); + properties.put("jdbc_arrow_treat_decimal_as_int", false); + try (Connection con = getConnection(properties); + Statement stmt = con.createStatement()) { + stmt.execute("alter session set jdbc_query_result_format = 'ARROW'"); + stmt.execute(createTableSql); + stmt.execute(insertStmt); + + // Test with jdbc_arrow_treat_decimal_as_int=false and JDBC_TREAT_DECIMAL_AS_INT=true + try (ResultSet rs = stmt.executeQuery(selectQuery)) { + while(rs.next()) { + assertEquals("class java.lang.Long", rs.getObject(1).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(2).getClass().toString()); + assertEquals("class java.lang.Long", rs.getObject(3).getClass().toString()); + assertEquals("class java.lang.Long", rs.getObject(4).getClass().toString()); + } + } + + // Test with jdbc_arrow_treat_decimal_as_int=false and JDBC_TREAT_DECIMAL_AS_INT=false + stmt.execute(setJdbcTreatDecimalAsIntFalse); + try (ResultSet rs = stmt.executeQuery(selectQuery)) { + while (rs.next()) { + assertEquals("class java.math.BigDecimal", rs.getObject(1).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(2).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(3).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(4).getClass().toString()); + } + } + } + } + + // Test default setting of new connection property jdbc_arrow_treat_decimal_as_int=true. Connection property introduced after version 3.15.0. + @Test + public void testGetObjectForArrowResultFormatJDBCArrowDecimalAsIntTrue() throws SQLException { + try (Connection con = BaseJDBCTest.getConnection(); + Statement stmt = con.createStatement()) { + stmt.execute("alter session set jdbc_query_result_format = 'ARROW'"); + stmt.execute(createTableSql); + stmt.execute(insertStmt); + + // Test with jdbc_arrow_treat_decimal_as_int=true and JDBC_TREAT_DECIMAL_AS_INT=true + try (ResultSet rs = stmt.executeQuery(selectQuery)) { + while(rs.next()) { + assertEquals("class java.lang.Long", rs.getObject(1).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(2).getClass().toString()); + assertEquals("class java.lang.Long", rs.getObject(3).getClass().toString()); + assertEquals("class java.lang.Long", rs.getObject(4).getClass().toString()); + } + } + + // Test with jdbc_arrow_treat_decimal_as_int=true and JDBC_TREAT_DECIMAL_AS_INT=false + stmt.execute(setJdbcTreatDecimalAsIntFalse); + try (ResultSet rs = stmt.executeQuery(selectQuery)) { + while (rs.next()) { + assertEquals("class java.lang.Long", rs.getObject(1).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(2).getClass().toString()); + assertEquals("class java.lang.Long", rs.getObject(3).getClass().toString()); + assertEquals("class java.lang.Long", rs.getObject(4).getClass().toString()); + } + } + } + } + // Test setting new connection property jdbc_arrow_treat_decimal_as_int=false. Connection property // introduced after version 3.15.0. @Test public void testGetObjectForJSONResultFormatJDBCArrowDecimalAsIntFalse() throws SQLException { Properties properties = new Properties(); properties.put("jdbc_arrow_treat_decimal_as_int", false); - try (Connection con = init(properties); + try (Connection con = getConnection(properties); Statement stmt = con.createStatement()) { + stmt.execute("alter session set jdbc_query_result_format = 'JSON'"); stmt.execute(createTableSql); stmt.execute(insertStmt); // Test with jdbc_arrow_treat_decimal_as_int=false and JDBC_TREAT_DECIMAL_AS_INT=true try (ResultSet rs = stmt.executeQuery(selectQuery)) { while (rs.next()) { - assertEquals(rs.getObject(1).getClass().toString(), "class java.lang.Long"); - assertEquals(rs.getObject(2).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(3).getClass().toString(), "class java.lang.Long"); - assertEquals(rs.getObject(4).getClass().toString(), "class java.lang.Long"); + assertEquals("class java.lang.Long", rs.getObject(1).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(2).getClass().toString()); + assertEquals("class java.lang.Long", rs.getObject(3).getClass().toString()); + assertEquals("class java.lang.Long", rs.getObject(4).getClass().toString()); } } @@ -1005,10 +1072,10 @@ public void testGetObjectForJSONResultFormatJDBCArrowDecimalAsIntFalse() throws stmt.execute(setJdbcTreatDecimalAsIntFalse); try (ResultSet rs = stmt.executeQuery(selectQuery)) { while (rs.next()) { - assertEquals(rs.getObject(1).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(2).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(3).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(4).getClass().toString(), "class java.math.BigDecimal"); + assertEquals("class java.math.BigDecimal", rs.getObject(1).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(2).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(3).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(4).getClass().toString()); } } } @@ -1018,18 +1085,19 @@ public void testGetObjectForJSONResultFormatJDBCArrowDecimalAsIntFalse() throws // Connection property introduced after version 3.15.0. @Test public void testGetObjectForJSONResultFormatJDBCArrowDecimalAsIntTrue() throws SQLException { - try (Connection con = init(); + try (Connection con = BaseJDBCTest.getConnection(); Statement stmt = con.createStatement()) { + stmt.execute("alter session set jdbc_query_result_format = 'JSON'"); stmt.execute(createTableSql); stmt.execute(insertStmt); // Test with jdbc_arrow_treat_decimal_as_int=true and JDBC_TREAT_DECIMAL_AS_INT=true try (ResultSet rs = stmt.executeQuery(selectQuery)) { while (rs.next()) { - assertEquals(rs.getObject(1).getClass().toString(), "class java.lang.Long"); - assertEquals(rs.getObject(2).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(3).getClass().toString(), "class java.lang.Long"); - assertEquals(rs.getObject(4).getClass().toString(), "class java.lang.Long"); + assertEquals("class java.lang.Long", rs.getObject(1).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(2).getClass().toString()); + assertEquals("class java.lang.Long", rs.getObject(3).getClass().toString()); + assertEquals("class java.lang.Long", rs.getObject(4).getClass().toString()); } } @@ -1037,10 +1105,10 @@ public void testGetObjectForJSONResultFormatJDBCArrowDecimalAsIntTrue() throws S stmt.execute(setJdbcTreatDecimalAsIntFalse); try (ResultSet rs = stmt.executeQuery(selectQuery)) { while (rs.next()) { - assertEquals(rs.getObject(1).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(2).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(3).getClass().toString(), "class java.math.BigDecimal"); - assertEquals(rs.getObject(4).getClass().toString(), "class java.math.BigDecimal"); + assertEquals("class java.math.BigDecimal", rs.getObject(1).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(2).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(3).getClass().toString()); + assertEquals("class java.math.BigDecimal", rs.getObject(4).getClass().toString()); } } }