Skip to content

Commit

Permalink
Trying fix for failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jf committed Mar 13, 2024
1 parent eed3ab6 commit 0e4e3df
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
}
}
}
}
}
112 changes: 90 additions & 22 deletions src/test/java/net/snowflake/client/jdbc/ResultSetLatestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down Expand Up @@ -980,35 +980,102 @@ 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());
}
}

// 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");
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());
}
}
}
Expand All @@ -1018,29 +1085,30 @@ 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());
}
}

// 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.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());
}
}
}
Expand Down

0 comments on commit 0e4e3df

Please sign in to comment.