|
19 | 19 | import com.datastax.oss.driver.api.core.data.UdtValue;
|
20 | 20 | import org.junit.jupiter.api.BeforeAll;
|
21 | 21 | import org.junit.jupiter.api.Test;
|
22 |
| -import org.slf4j.Logger; |
23 |
| -import org.slf4j.LoggerFactory; |
24 | 22 |
|
25 | 23 | import java.io.ByteArrayInputStream;
|
26 | 24 | import java.math.BigDecimal;
|
|
51 | 49 | import java.util.UUID;
|
52 | 50 |
|
53 | 51 | import static org.hamcrest.MatcherAssert.assertThat;
|
| 52 | +import static org.hamcrest.Matchers.hasItem; |
54 | 53 | import static org.hamcrest.Matchers.instanceOf;
|
55 | 54 | import static org.hamcrest.Matchers.is;
|
56 | 55 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
@@ -1032,4 +1031,78 @@ void testIngIssue33() throws Exception {
|
1032 | 1031 | stmt2.close();
|
1033 | 1032 | stmt3.close();
|
1034 | 1033 | }
|
| 1034 | + |
| 1035 | + @Test |
| 1036 | + @SuppressWarnings("unchecked") |
| 1037 | + void testIngIssue75() throws Exception { |
| 1038 | + final Statement stmt = sqlConnection.createStatement(); |
| 1039 | + |
| 1040 | + // Create the table with complex types. |
| 1041 | + final String createTableQuery = "CREATE TABLE t75 (id int PRIMARY KEY, " |
| 1042 | + + "complex_type1 list<frozen<map<text, text>>>, " |
| 1043 | + + "complex_type2 list<frozen<map<text, list<frozen<map<text, text>>>>>>, " |
| 1044 | + + "complex_type3 set<frozen<map<text, set<bigint>>>>);"; |
| 1045 | + stmt.execute(createTableQuery); |
| 1046 | + stmt.close(); |
| 1047 | + |
| 1048 | + // Insert data into the table. |
| 1049 | + final String insertQuery = |
| 1050 | + "INSERT INTO t75(id, complex_type1, complex_type2, complex_type3) values(?, ?, ?, ?);"; |
| 1051 | + final PreparedStatement stmt2 = sqlConnection.prepareStatement(insertQuery); |
| 1052 | + stmt2.setObject(1, 1); |
| 1053 | + |
| 1054 | + final Map<String, String> map = new HashMap<>(); |
| 1055 | + map.put("a", "10"); |
| 1056 | + map.put("b", "20"); |
| 1057 | + final List<Map<String, String>> list = new ArrayList<>(); |
| 1058 | + list.add(map); |
| 1059 | + stmt2.setObject(2, list); |
| 1060 | + |
| 1061 | + final Map<String, List<Map<String, String>>> map2 = new HashMap<>(); |
| 1062 | + map2.put("c", list); |
| 1063 | + final List<Map<String, List<Map<String, String>>>> list2 = new ArrayList<>(); |
| 1064 | + list2.add(map2); |
| 1065 | + stmt2.setObject(3, list2); |
| 1066 | + |
| 1067 | + final Map<String, Set<Long>> map3 = new HashMap<>(); |
| 1068 | + final Set<Long> innerSet = new HashSet<>(); |
| 1069 | + innerSet.add(10L); |
| 1070 | + innerSet.add(15L); |
| 1071 | + map3.put("d", innerSet); |
| 1072 | + final Set<Map<String, Set<Long>>> outerSet = new HashSet<>(); |
| 1073 | + outerSet.add(map3); |
| 1074 | + stmt2.setObject(4, outerSet); |
| 1075 | + |
| 1076 | + stmt2.execute(); |
| 1077 | + stmt2.close(); |
| 1078 | + |
| 1079 | + final Statement stmt3 = sqlConnection.createStatement(); |
| 1080 | + final CassandraResultSet result = (CassandraResultSet) stmt3.executeQuery("SELECT * FROM t75 WHERE id = 1;"); |
| 1081 | + |
| 1082 | + assertTrue(result.next()); |
| 1083 | + assertEquals(1, result.getInt("id")); |
| 1084 | + |
| 1085 | + final List<Map<String, String>> complexType1ValueAsList = |
| 1086 | + (List<Map<String, String>>) result.getList("complex_type1"); |
| 1087 | + final List<Map<String, String>> complexType1ValueAsObject = |
| 1088 | + (List<Map<String, String>>) result.getObject("complex_type1"); |
| 1089 | + assertThat(complexType1ValueAsList, hasItem(map)); |
| 1090 | + assertThat(complexType1ValueAsObject, hasItem(map)); |
| 1091 | + |
| 1092 | + final List<Map<String, List<Map<String, String>>>> complexType2ValueAsList = |
| 1093 | + (List<Map<String, List<Map<String, String>>>>) result.getList("complex_type2"); |
| 1094 | + final List<Map<String, List<Map<String, String>>>> complexType2ValueAsObject = |
| 1095 | + (List<Map<String, List<Map<String, String>>>>) result.getObject("complex_type2"); |
| 1096 | + assertThat(complexType2ValueAsList, hasItem(map2)); |
| 1097 | + assertThat(complexType2ValueAsObject, hasItem(map2)); |
| 1098 | + |
| 1099 | + final Set<Map<String, Set<Long>>> complexType3ValueAsSet = |
| 1100 | + (Set<Map<String, Set<Long>>>) result.getSet("complex_type3"); |
| 1101 | + final Set<Map<String, Set<Long>>> complexType3ValueAsObject = |
| 1102 | + (Set<Map<String, Set<Long>>>) result.getObject("complex_type3"); |
| 1103 | + assertThat(complexType3ValueAsSet, hasItem(map3)); |
| 1104 | + assertThat(complexType3ValueAsObject, hasItem(map3)); |
| 1105 | + |
| 1106 | + stmt3.close(); |
| 1107 | + } |
1035 | 1108 | }
|
0 commit comments