15
15
import java .sql .Statement ;
16
16
import java .sql .Time ;
17
17
import java .sql .Timestamp ;
18
+ import java .sql .Types ;
18
19
import java .time .LocalDate ;
19
20
import java .time .LocalDateTime ;
20
21
import java .time .LocalTime ;
23
24
import net .snowflake .client .ConditionalIgnoreRule ;
24
25
import net .snowflake .client .RunningOnGithubAction ;
25
26
import net .snowflake .client .ThrowingConsumer ;
27
+ import net .snowflake .client .ThrowingRunnable ;
26
28
import net .snowflake .client .category .TestCategoryStructuredType ;
27
29
import net .snowflake .client .core .structs .SnowflakeObjectTypeFactories ;
30
+ import net .snowflake .client .core .structs .StructureTypeHelper ;
28
31
import org .junit .Before ;
29
32
import org .junit .Test ;
30
33
import org .junit .experimental .categories .Category ;
@@ -404,6 +407,32 @@ public void testMapArrayOfArrays() throws SQLException {
404
407
});
405
408
}
406
409
410
+ @ Test
411
+ @ ConditionalIgnoreRule .ConditionalIgnore (condition = RunningOnGithubAction .class )
412
+ public void testColumnTypeWhenStructureTypeIsDisabled () throws Exception {
413
+ withStructureTypeTemporaryDisabled (
414
+ () -> {
415
+ withFirstRow (
416
+ "SELECT {'string':'a'}::OBJECT(string VARCHAR)" ,
417
+ resultSet -> {
418
+ assertEquals (Types .VARCHAR , resultSet .getMetaData ().getColumnType (1 ));
419
+ });
420
+ });
421
+ }
422
+
423
+ @ Test
424
+ @ ConditionalIgnoreRule .ConditionalIgnore (condition = RunningOnGithubAction .class )
425
+ public void testColumnTypeWhenStructureTypeIsEnabled () throws Exception {
426
+ withStructureTypeTemporaryEnabled (
427
+ () -> {
428
+ withFirstRow (
429
+ "SELECT {'string':'a'}::OBJECT(string VARCHAR)" ,
430
+ resultSet -> {
431
+ assertEquals (Types .STRUCT , resultSet .getMetaData ().getColumnType (1 ));
432
+ });
433
+ });
434
+ }
435
+
407
436
private void withFirstRow (String sqlText , ThrowingConsumer <ResultSet , SQLException > consumer )
408
437
throws SQLException {
409
438
try (Connection connection = init ();
@@ -413,5 +442,28 @@ private void withFirstRow(String sqlText, ThrowingConsumer<ResultSet, SQLExcepti
413
442
consumer .accept (rs );
414
443
}
415
444
}
416
- ;
445
+
446
+ private void withStructureTypeTemporaryEnabled (ThrowingRunnable action ) throws Exception {
447
+ boolean isStructureTypeEnabled = StructureTypeHelper .isStructureTypeEnabled ();
448
+ try {
449
+ StructureTypeHelper .enableStructuredType ();
450
+ action .run ();
451
+ } finally {
452
+ if (!isStructureTypeEnabled ) {
453
+ StructureTypeHelper .disableStructuredType ();
454
+ }
455
+ }
456
+ }
457
+
458
+ private void withStructureTypeTemporaryDisabled (ThrowingRunnable action ) throws Exception {
459
+ boolean isStructureTypeEnabled = StructureTypeHelper .isStructureTypeEnabled ();
460
+ try {
461
+ StructureTypeHelper .disableStructuredType ();
462
+ action .run ();
463
+ } finally {
464
+ if (isStructureTypeEnabled ) {
465
+ StructureTypeHelper .enableStructuredType ();
466
+ }
467
+ }
468
+ }
417
469
}
0 commit comments