2626import net .snowflake .client .util .SFPair ;
2727import org .junit .jupiter .api .Tag ;
2828import org .junit .jupiter .api .Test ;
29+ import org .junit .jupiter .params .ParameterizedTest ;
30+ import org .junit .jupiter .params .provider .ValueSource ;
2931
3032/**
3133 * Binding Data integration tests for the latest JDBC driver. This doesn't work for the oldest
@@ -374,7 +376,7 @@ public void testTimestampLtzBindingNoLongerBreaksOtherDatetimeBindings() throws
374376 }
375377
376378 @ Test
377- public void testGregorianJulianConversions () throws SQLException {
379+ public void testGregorianJulianDateConversions () throws SQLException {
378380 try (Connection connection = getConnection ();
379381 Statement statement = connection .createStatement ()) {
380382 statement .execute ("create or replace table stageinsertdates(ind int, d1 date)" );
@@ -401,6 +403,56 @@ public void testGregorianJulianConversions() throws SQLException {
401403 }
402404 }
403405
406+ @ ParameterizedTest
407+ @ ValueSource (strings = {"TIMESTAMP_LTZ" , "TIMESTAMP_NTZ" })
408+ public void testGregorianJulianTimestampConversions (String timestampType ) throws SQLException {
409+ TimeZone .setDefault (TimeZone .getTimeZone ("UTC" ));
410+ List <Timestamp > gregorianJulianTimestamps =
411+ Arrays .asList (
412+ Timestamp .valueOf ("0001-01-01 00:00:00" ),
413+ Timestamp .valueOf ("0100-03-01 00:00:00" ),
414+ Timestamp .valueOf ("0400-02-29 00:00:00" ),
415+ Timestamp .valueOf ("0400-03-01 00:00:00" ),
416+ Timestamp .valueOf ("1582-10-15 00:00:00" ),
417+ Timestamp .valueOf ("1900-02-28 00:00:00" ),
418+ Timestamp .valueOf ("1900-03-01 00:00:00" ),
419+ Timestamp .valueOf ("1969-12-31 00:00:00" ),
420+ Timestamp .valueOf ("1970-01-01 00:00:00" ),
421+ Timestamp .valueOf ("2000-02-28 00:00:00" ),
422+ Timestamp .valueOf ("2000-02-29 00:00:00" ),
423+ Timestamp .valueOf ("2000-03-01 00:00:00" ),
424+ Timestamp .valueOf ("2023-10-26 00:00:00" ),
425+ Timestamp .valueOf ("2024-02-29 00:00:00" ));
426+ try (Connection connection = getConnection ();
427+ Statement statement = connection .createStatement ()) {
428+ statement .execute (
429+ "create or replace table stageinsertdates(ind int, d1 " + timestampType + ")" );
430+ statement .execute ("alter session set CLIENT_TIMESTAMP_TYPE_MAPPING=" + timestampType );
431+
432+ try (PreparedStatement prepStatement =
433+ connection .prepareStatement ("insert into stageinsertdates values (?,?)" )) {
434+ for (int i = 0 ; i < gregorianJulianTimestamps .size (); i ++) {
435+ prepStatement .setInt (1 , i );
436+ prepStatement .setTimestamp (2 , gregorianJulianTimestamps .get (i ));
437+ prepStatement .addBatch ();
438+ }
439+
440+ prepStatement .executeBatch ();
441+ prepStatement .getConnection ().commit ();
442+ }
443+
444+ try (ResultSet rs1 = statement .executeQuery ("select * from stageinsertdates order by ind" )) {
445+ for (int i = 0 ; i < gregorianJulianTimestamps .size (); i ++) {
446+ assertTrue (rs1 .next ());
447+ assertEquals (i , rs1 .getInt (1 ));
448+ assertEquals (gregorianJulianTimestamps .get (i ), rs1 .getTimestamp (2 ));
449+ }
450+ }
451+ } finally {
452+ TimeZone .setDefault (origTz );
453+ }
454+ }
455+
404456 /**
405457 * This test cannot run on the GitHub testing because of the "ALTER SESSION SET
406458 * CLIENT_STAGE_ARRAY_BINDING_THRESHOLD" This command should be executed with the system admin.
@@ -409,7 +461,7 @@ public void testGregorianJulianConversions() throws SQLException {
409461 */
410462 @ Test
411463 @ DontRunOnGithubActions
412- public void testGregorianJulianConversionsWithStageBindings () throws SQLException {
464+ public void testGregorianJulianDateConversionsWithStageBindings () throws SQLException {
413465 try (Connection connection = getConnection ();
414466 Statement statement = connection .createStatement ()) {
415467 statement .execute ("create or replace table stageinsertdates(ind int, d1 date)" );
@@ -437,6 +489,65 @@ public void testGregorianJulianConversionsWithStageBindings() throws SQLExceptio
437489 }
438490 }
439491
492+ /**
493+ * This test cannot run on the GitHub testing because of the "ALTER SESSION SET
494+ * CLIENT_STAGE_ARRAY_BINDING_THRESHOLD" This command should be executed with the system admin.
495+ *
496+ * @throws SQLException
497+ */
498+ @ ParameterizedTest
499+ @ ValueSource (strings = {"TIMESTAMP_LTZ" , "TIMESTAMP_NTZ" })
500+ @ DontRunOnGithubActions
501+ public void testGregorianJulianTimestampConversionsWithStageBindings (String timestampType )
502+ throws SQLException {
503+ TimeZone .setDefault (TimeZone .getTimeZone ("UTC" ));
504+ List <Timestamp > gregorianJulianTimestamps =
505+ Arrays .asList (
506+ Timestamp .valueOf ("0001-01-01 00:00:00" ),
507+ Timestamp .valueOf ("0100-03-01 00:00:00" ),
508+ Timestamp .valueOf ("0400-02-29 00:00:00" ),
509+ Timestamp .valueOf ("0400-03-01 00:00:00" ),
510+ Timestamp .valueOf ("1582-10-15 00:00:00" ),
511+ Timestamp .valueOf ("1900-02-28 00:00:00" ),
512+ Timestamp .valueOf ("1900-03-01 00:00:00" ),
513+ Timestamp .valueOf ("1969-12-31 00:00:00" ),
514+ Timestamp .valueOf ("1970-01-01 00:00:00" ),
515+ Timestamp .valueOf ("2000-02-28 00:00:00" ),
516+ Timestamp .valueOf ("2000-02-29 00:00:00" ),
517+ Timestamp .valueOf ("2000-03-01 00:00:00" ),
518+ Timestamp .valueOf ("2023-10-26 00:00:00" ),
519+ Timestamp .valueOf ("2024-02-29 00:00:00" ));
520+ try (Connection connection = getConnection ();
521+ Statement statement = connection .createStatement ()) {
522+ statement .execute (
523+ "create or replace table stageinsertdates(ind int, d1 " + timestampType + ")" );
524+ statement .execute ("alter session set CLIENT_STAGE_ARRAY_BINDING_THRESHOLD = 1" );
525+ statement .execute ("alter session set CLIENT_TIMESTAMP_TYPE_MAPPING=" + timestampType );
526+
527+ try (PreparedStatement prepStatement =
528+ connection .prepareStatement ("insert into stageinsertdates values (?,?)" )) {
529+ for (int i = 0 ; i < gregorianJulianTimestamps .size (); i ++) {
530+ prepStatement .setInt (1 , i );
531+ prepStatement .setTimestamp (2 , gregorianJulianTimestamps .get (i ));
532+ prepStatement .addBatch ();
533+ }
534+
535+ prepStatement .executeBatch ();
536+ prepStatement .getConnection ().commit ();
537+ }
538+
539+ try (ResultSet rs1 = statement .executeQuery ("select * from stageinsertdates order by ind" )) {
540+ for (int i = 0 ; i < gregorianJulianTimestamps .size (); i ++) {
541+ assertTrue (rs1 .next ());
542+ assertEquals (i , rs1 .getInt (1 ));
543+ assertEquals (gregorianJulianTimestamps .get (i ), rs1 .getTimestamp (2 ));
544+ }
545+ }
546+ } finally {
547+ TimeZone .setDefault (origTz );
548+ }
549+ }
550+
440551 @ Test
441552 public void testInsertTimeColumnAsWallClockTimeRegardlessOfTimezone () throws SQLException {
442553 TimeZone .setDefault (TimeZone .getTimeZone ("Pacific/Honolulu" ));
0 commit comments