-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathDatabaseMetaDataTestParams.java
More file actions
313 lines (294 loc) · 12 KB
/
DatabaseMetaDataTestParams.java
File metadata and controls
313 lines (294 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package com.jayant.testparams;
import static com.jayant.testparams.ParamUtils.putInMapForKey;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.Types;
import java.util.*;
public class DatabaseMetaDataTestParams implements TestParams {
@Override
public Map<Map.Entry<String, Integer>, Set<Object[]>> getFunctionToArgsMap() {
Map<Map.Entry<String, Integer>, Set<Object[]>> functionToArgsMap = new HashMap<>();
putInMapForKey(
functionToArgsMap,
Map.entry("getTables", 4),
new String[] {"main", "tpcds_sf100_delta", "%", null});
putInMapForKey(
functionToArgsMap,
Map.entry("getTablePrivileges", 3),
new String[] {"main", "tpcds_sf100_delta", "%"});
putInMapForKey(functionToArgsMap, Map.entry("getSchemas", 2), new String[] {"main", "tpcds_%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getColumns", 4),
new String[] {"main", "tpcds_sf100_delta", "catalog_sales", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getPseudoColumns", 4),
new String[] {"main", "tpcds_sf100_delta", "catalog_sales", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getColumnPrivileges", 4),
new String[] {"main", "tpcds_sf100_delta", "catalog_sales", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getVersionColumns", 3),
new String[] {"main", "tpcds_sf100_delta", "catalog_sales"});
putInMapForKey(
functionToArgsMap,
Map.entry("getFunctions", 3),
new String[] {"main", "tpcds_sf100_delta", "aggregate"});
putInMapForKey(
functionToArgsMap,
Map.entry("getFunctionColumns", 4),
new String[] {"main", "tpcds_sf100_delta", "aggregate", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getProcedures", 3),
new String[] {"main", "tpcds_sf100_delta", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getProcedureColumns", 4),
new String[] {"main", "tpcds_sf100_delta", "%", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getPrimaryKeys", 3),
new String[] {"main", "oss_jdbc_tests", "test_result_set_types"});
putInMapForKey(
functionToArgsMap,
Map.entry("getImportedKeys", 3),
new String[] {"main", "tpcds_sf100_delta", "catalog_sales"});
putInMapForKey(
functionToArgsMap,
Map.entry("getExportedKeys", 3),
new String[] {"main", "tpcds_sf100_delta", "catalog_sales"});
// TODO: Add a proper cross reference test
putInMapForKey(
functionToArgsMap,
Map.entry("getCrossReference", 6),
new String[] {
"main", "tpcds_sf100_delta", "catalog_sales", "main", "tpcds_sf100_delta", "catalog_sales"
});
putInMapForKey(
functionToArgsMap,
Map.entry("getIndexInfo", 5),
new Object[] {"main", "tpcds_sf100_delta", "catalog_sales", true, false});
putInMapForKey(
functionToArgsMap,
Map.entry("getUDTs", 4),
new String[] {"main", "tpcds_sf100_delta", "%", null});
putInMapForKey(
functionToArgsMap,
Map.entry("getSuperTypes", 3),
new String[] {"main", "tpcds_sf100_delta", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getSuperTables", 3),
new String[] {"main", "tpcds_sf100_delta", "catalog_sales"});
putInMapForKey(
functionToArgsMap,
Map.entry("getAttributes", 4),
new String[] {"main", "tpcds_sf100_delta", "%", "%"});
// Cross-catalog tests: null catalog (match all catalogs)
putInMapForKey(
functionToArgsMap,
Map.entry("getTables", 4),
new String[] {null, "tpcds_sf100_delta", "%", null});
putInMapForKey(
functionToArgsMap,
Map.entry("getTablePrivileges", 3),
new String[] {null, "tpcds_sf100_delta", "%"});
putInMapForKey(functionToArgsMap, Map.entry("getSchemas", 2), new String[] {null, "tpcds_%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getColumns", 4),
new String[] {null, "tpcds_sf100_delta", "catalog_sales", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getPseudoColumns", 4),
new String[] {null, "tpcds_sf100_delta", "catalog_sales", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getColumnPrivileges", 4),
new String[] {null, "tpcds_sf100_delta", "catalog_sales", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getVersionColumns", 3),
new String[] {null, "tpcds_sf100_delta", "catalog_sales"});
putInMapForKey(
functionToArgsMap,
Map.entry("getFunctions", 3),
new String[] {null, "tpcds_sf100_delta", "aggregate"});
putInMapForKey(
functionToArgsMap,
Map.entry("getFunctionColumns", 4),
new String[] {null, "tpcds_sf100_delta", "aggregate", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getProcedures", 3),
new String[] {null, "tpcds_sf100_delta", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getProcedureColumns", 4),
new String[] {null, "tpcds_sf100_delta", "%", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getPrimaryKeys", 3),
new String[] {null, "oss_jdbc_tests", "test_result_set_types"});
putInMapForKey(
functionToArgsMap,
Map.entry("getImportedKeys", 3),
new String[] {null, "tpcds_sf100_delta", "catalog_sales"});
putInMapForKey(
functionToArgsMap,
Map.entry("getExportedKeys", 3),
new String[] {null, "tpcds_sf100_delta", "catalog_sales"});
putInMapForKey(
functionToArgsMap,
Map.entry("getCrossReference", 6),
new String[] {
null, "tpcds_sf100_delta", "catalog_sales", null, "tpcds_sf100_delta", "catalog_sales"
});
putInMapForKey(
functionToArgsMap,
Map.entry("getIndexInfo", 5),
new Object[] {null, "tpcds_sf100_delta", "catalog_sales", true, false});
putInMapForKey(
functionToArgsMap,
Map.entry("getUDTs", 4),
new String[] {null, "tpcds_sf100_delta", "%", null});
putInMapForKey(
functionToArgsMap,
Map.entry("getSuperTypes", 3),
new String[] {null, "tpcds_sf100_delta", "%"});
putInMapForKey(
functionToArgsMap,
Map.entry("getSuperTables", 3),
new String[] {null, "tpcds_sf100_delta", "catalog_sales"});
putInMapForKey(
functionToArgsMap,
Map.entry("getAttributes", 4),
new String[] {null, "tpcds_sf100_delta", "%", "%"});
// Methods for ResultSet concurrency and visibility
for (Integer type : getResultSetTypes()) {
putInMapForKey(
functionToArgsMap, Map.entry("supportsResultSetType", 1), new Integer[] {type});
putInMapForKey(
functionToArgsMap,
Map.entry("supportsResultSetConcurrency", 2),
new Integer[] {type, ResultSet.CONCUR_READ_ONLY});
putInMapForKey(
functionToArgsMap,
Map.entry("supportsResultSetConcurrency", 2),
new Integer[] {type, ResultSet.CONCUR_UPDATABLE});
putInMapForKey(functionToArgsMap, Map.entry("ownUpdatesAreVisible", 1), new Integer[] {type});
putInMapForKey(functionToArgsMap, Map.entry("ownDeletesAreVisible", 1), new Integer[] {type});
putInMapForKey(functionToArgsMap, Map.entry("ownInsertsAreVisible", 1), new Integer[] {type});
putInMapForKey(
functionToArgsMap, Map.entry("othersUpdatesAreVisible", 1), new Integer[] {type});
putInMapForKey(
functionToArgsMap, Map.entry("othersDeletesAreVisible", 1), new Integer[] {type});
putInMapForKey(
functionToArgsMap, Map.entry("othersInsertsAreVisible", 1), new Integer[] {type});
putInMapForKey(functionToArgsMap, Map.entry("updatesAreDetected", 1), new Integer[] {type});
putInMapForKey(functionToArgsMap, Map.entry("deletesAreDetected", 1), new Integer[] {type});
putInMapForKey(functionToArgsMap, Map.entry("insertsAreDetected", 1), new Integer[] {type});
}
for (Integer i : getAllTransactionIsolationLevels()) {
putInMapForKey(
functionToArgsMap, Map.entry("supportsTransactionIsolationLevel", 1), new Integer[] {i});
}
for (Integer i : getAllBestRowIdentifierScopes()) {
putInMapForKey(
functionToArgsMap,
Map.entry("getBestRowIdentifier", 5),
new Object[] {"main", "tpcds_sf100_delta", "catalog_sales", i, true});
// Cross-catalog: null catalog
putInMapForKey(
functionToArgsMap,
Map.entry("getBestRowIdentifier", 5),
new Object[] {null, "tpcds_sf100_delta", "catalog_sales", i, true});
}
for (Integer i : getResultSetHoldability()) {
putInMapForKey(
functionToArgsMap, Map.entry("supportsResultSetHoldability", 1), new Integer[] {i});
}
for (Integer fromType : getAllSqlTypes()) {
for (Integer toType : getAllSqlTypes()) {
if (fromType == Types.ROWID || toType == Types.ROWID) {
continue; // ROWID is not supported by Databricks server
}
if (fromType == Types.ARRAY || fromType == Types.STRUCT || fromType == Types.OTHER) {
continue; // Complex types not supported by legacy driver
}
if (fromType == Types.BOOLEAN && toType == Types.BOOLEAN) {
// This is a bug in the legacy driver
continue;
}
putInMapForKey(
functionToArgsMap, Map.entry("supportsConvert", 2), new Integer[] {fromType, toType});
}
}
return functionToArgsMap;
}
@Override
public Set<Map.Entry<String, Integer>> getAcceptedKnownDiffs() {
Set<Map.Entry<String, Integer>> acceptedKnownDiffs = new HashSet<>();
// getSchemas with no args returns empty result set for SEA
acceptedKnownDiffs.add(Map.entry("getSchemas", 0));
// don't compare classes
acceptedKnownDiffs.add(Map.entry("getConnection", 0));
// don't compare driver version
acceptedKnownDiffs.add(Map.entry("getDriverVersion", 0));
// URL passes is different
acceptedKnownDiffs.add(Map.entry("getURL", 0));
// Methods that we do not need to test from the Super class
acceptedKnownDiffs.add(Map.entry("unwrap", 1));
acceptedKnownDiffs.add(Map.entry("isWrapperFor", 1));
return acceptedKnownDiffs;
}
private static List<Integer> getAllSqlTypes() {
List<Integer> sqlTypes = new ArrayList<>();
// Get all fields from the Types class
Field[] fields = Types.class.getFields();
for (Field field : fields) {
if (field.getType().equals(int.class)) { // Only consider fields of type int (SQL types)
try {
// Add each constant value to the list
sqlTypes.add((Integer) field.get(null));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return sqlTypes;
}
private static List<Integer> getAllTransactionIsolationLevels() {
return new ArrayList<>(
Arrays.asList(
Connection.TRANSACTION_NONE,
Connection.TRANSACTION_READ_UNCOMMITTED,
Connection.TRANSACTION_READ_COMMITTED,
Connection.TRANSACTION_REPEATABLE_READ,
Connection.TRANSACTION_SERIALIZABLE));
}
private static List<Integer> getAllBestRowIdentifierScopes() {
return new ArrayList<>(
Arrays.asList(
DatabaseMetaData.bestRowTemporary,
DatabaseMetaData.bestRowTransaction,
DatabaseMetaData.bestRowSession));
}
private static List<Integer> getResultSetTypes() {
return new ArrayList<>(
Arrays.asList(
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.TYPE_SCROLL_SENSITIVE));
}
private static List<Integer> getResultSetHoldability() {
return new ArrayList<>(
Arrays.asList(ResultSet.HOLD_CURSORS_OVER_COMMIT, ResultSet.CLOSE_CURSORS_AT_COMMIT));
}
}