Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1313625-Verify-value-bindings-exceeding-CLIENT_STAGE_ARRAY_BINDING_THRESHOLD #1904

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,74 @@ public void testTimestampBindingWithNTZType() throws SQLException {
}
}

/**
* Test that stage binding and regular binding insert and return the expected value for
* timestamp_ntz, timestamp_ltz, and timestamp_tz when exceeding binding threshold.
*
* @throws SQLException if there is an error during query execution.
*/
@Test
public void testTimestampBindingWithNTZTypeExceedingBindingThreshold() throws SQLException {
TimeZone.setDefault(tokyoTz);
try (Connection connection = getConnection();
Statement statement = connection.createStatement()) {
try {
statement.execute(
"create or replace table stageinsert(ind int, ltz0 timestamp_ltz, tz0 timestamp_tz, ntz0 timestamp_ntz)");
statement.execute(
"create or replace table regularinsert(ind int, ltz0 timestamp_ltz, tz0 timestamp_tz, ntz0 timestamp_ntz)");
statement.execute("alter session set CLIENT_TIMESTAMP_TYPE_MAPPING=TIMESTAMP_NTZ");
statement.execute("alter session set TIMEZONE='Asia/Tokyo'");
Timestamp currT = new Timestamp(System.currentTimeMillis());

// insert using regular binging
executePrepStmtForNumRows(connection, "regularinsert", currT, 3);

// insert using stage binding
statement.execute("ALTER SESSION SET CLIENT_STAGE_ARRAY_BINDING_THRESHOLD = 1");
executePrepStmtForNumRows(connection, "stageinsert", currT, 3);

// Compare the results
try (ResultSet rs1 = statement.executeQuery("select * from stageinsert");
ResultSet rs2 = statement.executeQuery("select * from regularinsert")) {
for (int i = 0; i < 3; i++) {
assertTrue(rs1.next());
assertTrue(rs2.next());

assertEquals(rs1.getInt(1), rs2.getInt(1));

// Check tz type and ltz type columns have the same value.
assertEquals(rs1.getTimestamp(2), rs1.getTimestamp(3));

assertEquals(rs1.getTimestamp(2), rs2.getTimestamp(2));
assertEquals(rs1.getTimestamp(3), rs2.getTimestamp(3));
assertEquals(rs1.getTimestamp(4), rs2.getTimestamp(4));
}
}
} finally {
statement.execute("drop table if exists stageinsert");
statement.execute("drop table if exists regularinsert");
TimeZone.setDefault(origTz);
}
}
}

private void executePrepStmtForNumRows(
Connection connection, String tableName, Timestamp timestamp, int numRows)
throws SQLException {
try (PreparedStatement prepStatement =
connection.prepareStatement("insert into " + tableName + " values (?,?,?,?)")) {
for (int i = 0; i < numRows; i++) {
prepStatement.setInt(1, 1);
prepStatement.setTimestamp(2, timestamp);
prepStatement.setTimestamp(3, timestamp);
prepStatement.setTimestamp(4, timestamp);
prepStatement.addBatch();
}
prepStatement.executeBatch();
}
}

/**
* Test that stage binding and regular binding insert and return the same value for timestamp_ltz
*
Expand Down
Loading