/
JdbcDatabaseMetaData.java
1580 lines (1396 loc) · 49.8 KB
/
JdbcDatabaseMetaData.java
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.jdbc;
import com.google.auth.Credentials;
import com.google.auth.ServiceAccountSigner;
import com.google.auth.oauth2.UserCredentials;
import com.google.cloud.spanner.ResultSets;
import com.google.cloud.spanner.Struct;
import com.google.cloud.spanner.Type;
import com.google.cloud.spanner.Type.StructField;
import com.google.cloud.spanner.connection.Connection.InternalMetadataQuery;
import com.google.common.annotations.VisibleForTesting;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.RowIdLifetime;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
/** {@link DatabaseMetaData} implementation for Cloud Spanner */
class JdbcDatabaseMetaData extends AbstractJdbcWrapper implements DatabaseMetaData {
private static final int JDBC_MAJOR_VERSION = 4;
private static final int JDBC_MINOR_VERSION = 1;
private static final int DATABASE_MAJOR_VERSION = 1;
private static final int DATABASE_MINOR_VERSION = 0;
private static final String PRODUCT_NAME = "Google Cloud Spanner";
@VisibleForTesting
static String readSqlFromFile(String filename) {
InputStream in = JdbcDatabaseMetaData.class.getResourceAsStream(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder builder = new StringBuilder();
try (Scanner scanner = new Scanner(reader)) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
builder.append(line).append("\n");
}
scanner.close();
}
return builder.toString();
}
private JdbcConnection connection;
JdbcDatabaseMetaData(JdbcConnection connection) {
this.connection = connection;
}
@Override
public boolean isClosed() {
return false;
}
@Override
public boolean allProceduresAreCallable() throws SQLException {
return true;
}
@Override
public boolean allTablesAreSelectable() throws SQLException {
return true;
}
@Override
public String getURL() throws SQLException {
return connection.getConnectionUrl();
}
@Override
public String getUserName() throws SQLException {
Credentials credentials = connection.getConnectionOptions().getCredentials();
if (credentials != null) {
if (credentials instanceof ServiceAccountSigner) {
return ((ServiceAccountSigner) credentials).getAccount();
} else if (credentials instanceof UserCredentials) {
return ((UserCredentials) credentials).getClientId();
}
}
return "";
}
@Override
public boolean isReadOnly() throws SQLException {
return false;
}
@Override
public boolean nullsAreSortedHigh() throws SQLException {
return false;
}
@Override
public boolean nullsAreSortedLow() throws SQLException {
return true;
}
@Override
public boolean nullsAreSortedAtStart() throws SQLException {
return false;
}
@Override
public boolean nullsAreSortedAtEnd() throws SQLException {
return false;
}
@Override
public String getDatabaseProductName() throws SQLException {
return PRODUCT_NAME;
}
@Override
public String getDatabaseProductVersion() throws SQLException {
return getDatabaseMajorVersion() + "." + getDatabaseMinorVersion();
}
@Override
public String getDriverName() throws SQLException {
return JdbcDriver.class.getName();
}
@Override
public String getDriverVersion() throws SQLException {
return getDriverMajorVersion() + "." + getDriverMinorVersion();
}
@Override
public int getDriverMajorVersion() {
return JdbcDriver.MAJOR_VERSION;
}
@Override
public int getDriverMinorVersion() {
return JdbcDriver.MINOR_VERSION;
}
@Override
public boolean usesLocalFiles() throws SQLException {
return false;
}
@Override
public boolean usesLocalFilePerTable() throws SQLException {
return false;
}
@Override
public boolean supportsMixedCaseIdentifiers() throws SQLException {
return false;
}
@Override
public boolean storesUpperCaseIdentifiers() throws SQLException {
return false;
}
@Override
public boolean storesLowerCaseIdentifiers() throws SQLException {
return false;
}
@Override
public boolean storesMixedCaseIdentifiers() throws SQLException {
return true;
}
@Override
public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
return false;
}
@Override
public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
return false;
}
@Override
public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
return false;
}
@Override
public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
return true;
}
@Override
public String getIdentifierQuoteString() throws SQLException {
return "`";
}
@Override
public String getSQLKeywords() throws SQLException {
return "ASSERT_ROWS_MODIFIED,ENUM,GROUPS,HASH,IGNORE,LOOKUP,PROTO,RESPECT,STRUCT,WINDOW";
}
@Override
public String getNumericFunctions() throws SQLException {
return "ABS,SIGN,IS_INF,IS_NAN,IEEE_DIVIDE,SQRT,POW,POWER,EXP,LN,LOG,LOG10,GREATEST,LEAST,DIV,MOD,ROUND,TRUNC,CEIL,CEILING,FLOOR,COS,COSH,ACOS,ACOSH,SIN,SINH,ASIN,ASINH,TAN,TANH,ATAN,ATANH,ATAN2,FARM_FINGERPRINT,SHA1,SHA256,SHA512";
}
@Override
public String getStringFunctions() throws SQLException {
return "BYTE_LENGTH,CHAR_LENGTH,CHARACTER_LENGTH,CODE_POINTS_TO_BYTES,CODE_POINTS_TO_STRING,CONCAT,ENDS_WITH,FORMAT,FROM_BASE64,FROM_HEX,LENGTH,LPAD,LOWER,LTRIM,REGEXP_CONTAINS,REGEXP_EXTRACT,REGEXP_EXTRACT_ALL,REGEXP_REPLACE,REPLACE,REPEAT,REVERSE,RPAD,RTRIM,SAFE_CONVERT_BYTES_TO_STRING,SPLIT,STARTS_WITH,STRPOS,SUBSTR,TO_BASE64,TO_CODE_POINTS,TO_HEX,TRIM,UPPER,JSON_QUERY,JSON_VALUE";
}
@Override
public String getSystemFunctions() throws SQLException {
return "";
}
@Override
public String getTimeDateFunctions() throws SQLException {
return "CURRENT_DATE,EXTRACT,DATE,DATE_ADD,DATE_SUB,DATE_DIFF,DATE_TRUNC,DATE_FROM_UNIX_DATE,FORMAT_DATE,PARSE_DATE,UNIX_DATE,CURRENT_TIMESTAMP,STRING,TIMESTAMP,TIMESTAMP_ADD,TIMESTAMP_SUB,TIMESTAMP_DIFF,TIMESTAMP_TRUNC,FORMAT_TIMESTAMP,PARSE_TIMESTAMP,TIMESTAMP_SECONDS,TIMESTAMP_MILLIS,TIMESTAMP_MICROS,UNIX_SECONDS,UNIX_MILLIS,UNIX_MICROS";
}
@Override
public String getSearchStringEscape() throws SQLException {
return "\\";
}
@Override
public String getExtraNameCharacters() throws SQLException {
return "";
}
@Override
public boolean supportsAlterTableWithAddColumn() throws SQLException {
return true;
}
@Override
public boolean supportsAlterTableWithDropColumn() throws SQLException {
return true;
}
@Override
public boolean supportsColumnAliasing() throws SQLException {
return true;
}
@Override
public boolean nullPlusNonNullIsNull() throws SQLException {
return true;
}
@Override
public boolean supportsConvert() throws SQLException {
return false;
}
@Override
public boolean supportsConvert(int fromType, int toType) throws SQLException {
return false;
}
@Override
public boolean supportsTableCorrelationNames() throws SQLException {
return true;
}
@Override
public boolean supportsDifferentTableCorrelationNames() throws SQLException {
return false;
}
@Override
public boolean supportsExpressionsInOrderBy() throws SQLException {
return true;
}
@Override
public boolean supportsOrderByUnrelated() throws SQLException {
return true;
}
@Override
public boolean supportsGroupBy() throws SQLException {
return true;
}
@Override
public boolean supportsGroupByUnrelated() throws SQLException {
return true;
}
@Override
public boolean supportsGroupByBeyondSelect() throws SQLException {
return true;
}
@Override
public boolean supportsLikeEscapeClause() throws SQLException {
return true;
}
@Override
public boolean supportsMultipleResultSets() throws SQLException {
return true;
}
@Override
public boolean supportsMultipleTransactions() throws SQLException {
return true;
}
@Override
public boolean supportsNonNullableColumns() throws SQLException {
return true;
}
@Override
public boolean supportsMinimumSQLGrammar() throws SQLException {
return false;
}
@Override
public boolean supportsCoreSQLGrammar() throws SQLException {
return false;
}
@Override
public boolean supportsExtendedSQLGrammar() throws SQLException {
return false;
}
@Override
public boolean supportsANSI92EntryLevelSQL() throws SQLException {
return false;
}
@Override
public boolean supportsANSI92IntermediateSQL() throws SQLException {
return false;
}
@Override
public boolean supportsANSI92FullSQL() throws SQLException {
return false;
}
@Override
public boolean supportsIntegrityEnhancementFacility() throws SQLException {
return false;
}
@Override
public boolean supportsOuterJoins() throws SQLException {
return true;
}
@Override
public boolean supportsFullOuterJoins() throws SQLException {
return true;
}
@Override
public boolean supportsLimitedOuterJoins() throws SQLException {
return true;
}
@Override
public String getSchemaTerm() throws SQLException {
return "SCHEMA";
}
@Override
public String getProcedureTerm() throws SQLException {
return "PROCEDURE";
}
@Override
public String getCatalogTerm() throws SQLException {
// Spanner does not support catalogs, but the term is included for compatibility with the SQL
// standard
return "CATALOG";
}
@Override
public boolean isCatalogAtStart() throws SQLException {
return false;
}
@Override
public String getCatalogSeparator() throws SQLException {
return ".";
}
@Override
public boolean supportsSchemasInDataManipulation() throws SQLException {
return false;
}
@Override
public boolean supportsSchemasInProcedureCalls() throws SQLException {
return false;
}
@Override
public boolean supportsSchemasInTableDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsSchemasInIndexDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsCatalogsInDataManipulation() throws SQLException {
return false;
}
@Override
public boolean supportsCatalogsInProcedureCalls() throws SQLException {
return false;
}
@Override
public boolean supportsCatalogsInTableDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
return false;
}
@Override
public boolean supportsPositionedDelete() throws SQLException {
return false;
}
@Override
public boolean supportsPositionedUpdate() throws SQLException {
return false;
}
@Override
public boolean supportsSelectForUpdate() throws SQLException {
return false;
}
@Override
public boolean supportsStoredProcedures() throws SQLException {
return false;
}
@Override
public boolean supportsSubqueriesInComparisons() throws SQLException {
return true;
}
@Override
public boolean supportsSubqueriesInExists() throws SQLException {
return true;
}
@Override
public boolean supportsSubqueriesInIns() throws SQLException {
return true;
}
@Override
public boolean supportsSubqueriesInQuantifieds() throws SQLException {
return true;
}
@Override
public boolean supportsCorrelatedSubqueries() throws SQLException {
return true;
}
@Override
public boolean supportsUnion() throws SQLException {
// Note that Cloud Spanner requires the user to specify 'UNION DISTINCT' or 'UNION ALL' in a
// query. 'UNION DISTINCT' is equal to the SQL operation 'UNION'.
return true;
}
@Override
public boolean supportsUnionAll() throws SQLException {
return true;
}
@Override
public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
return false;
}
@Override
public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
return false;
}
@Override
public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
return true;
}
@Override
public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
return true;
}
@Override
public int getMaxBinaryLiteralLength() throws SQLException {
return 0;
}
@Override
public int getMaxCharLiteralLength() throws SQLException {
return 0;
}
@Override
public int getMaxColumnNameLength() throws SQLException {
return 128;
}
@Override
public int getMaxColumnsInGroupBy() throws SQLException {
return 1000;
}
@Override
public int getMaxColumnsInIndex() throws SQLException {
return 16;
}
@Override
public int getMaxColumnsInOrderBy() throws SQLException {
return 0;
}
@Override
public int getMaxColumnsInSelect() throws SQLException {
return 0;
}
@Override
public int getMaxColumnsInTable() throws SQLException {
return 1024;
}
@Override
public int getMaxConnections() throws SQLException {
// there is a max number of sessions, but that is not the same as the max number of connections
return 0;
}
@Override
public int getMaxCursorNameLength() throws SQLException {
return 0;
}
@Override
public int getMaxIndexLength() throws SQLException {
return 8000;
}
@Override
public int getMaxSchemaNameLength() throws SQLException {
return 0;
}
@Override
public int getMaxProcedureNameLength() throws SQLException {
return 0;
}
@Override
public int getMaxCatalogNameLength() throws SQLException {
return 0;
}
@Override
public int getMaxRowSize() throws SQLException {
return 1024 * 10000000;
}
@Override
public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
return true;
}
@Override
public int getMaxStatementLength() throws SQLException {
return 1000000;
}
@Override
public int getMaxStatements() throws SQLException {
return 0;
}
@Override
public int getMaxTableNameLength() throws SQLException {
return 128;
}
@Override
public int getMaxTablesInSelect() throws SQLException {
return 0;
}
@Override
public int getMaxUserNameLength() throws SQLException {
return 0;
}
@Override
public int getDefaultTransactionIsolation() throws SQLException {
return Connection.TRANSACTION_SERIALIZABLE;
}
@Override
public boolean supportsTransactions() throws SQLException {
return true;
}
@Override
public boolean supportsTransactionIsolationLevel(int level) throws SQLException {
return Connection.TRANSACTION_SERIALIZABLE == level;
}
@Override
public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException {
return false;
}
@Override
public boolean supportsDataManipulationTransactionsOnly() throws SQLException {
return true;
}
@Override
public boolean dataDefinitionCausesTransactionCommit() throws SQLException {
return false;
}
@Override
public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
return false;
}
@Override
public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern)
throws SQLException {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
StructField.of("PROCEDURE_CAT", Type.string()),
StructField.of("PROCEDURE_SCHEM", Type.string()),
StructField.of("PROCEDURE_NAME", Type.string()),
StructField.of("reserved1", Type.string()),
StructField.of("reserved2", Type.string()),
StructField.of("reserved3", Type.string()),
StructField.of("REMARKS", Type.string()),
StructField.of("PROCEDURE_TYPE", Type.int64()),
StructField.of("SPECIFIC_NAME", Type.string())),
Collections.<Struct>emptyList()));
}
@Override
public ResultSet getProcedureColumns(
String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern)
throws SQLException {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
StructField.of("PROCEDURE_CAT", Type.string()),
StructField.of("PROCEDURE_SCHEM", Type.string()),
StructField.of("PROCEDURE_NAME", Type.string()),
StructField.of("COLUMN_NAME", Type.string()),
StructField.of("COLUMN_TYPE", Type.int64()),
StructField.of("DATA_TYPE", Type.int64()),
StructField.of("TYPE_NAME", Type.string()),
StructField.of("PRECISION", Type.string()),
StructField.of("LENGTH", Type.int64()),
StructField.of("SCALE", Type.int64()),
StructField.of("RADIX", Type.int64()),
StructField.of("NULLABLE", Type.int64()),
StructField.of("REMARKS", Type.string()),
StructField.of("COLUMN_DEF", Type.string()),
StructField.of("SQL_DATA_TYPE", Type.int64()),
StructField.of("SQL_DATETIME_SUB", Type.int64()),
StructField.of("CHAR_OCTET_LENGTH", Type.int64()),
StructField.of("ORDINAL_POSITION", Type.int64()),
StructField.of("IS_NULLABLE", Type.string()),
StructField.of("SPECIFIC_NAME", Type.string())),
Collections.<Struct>emptyList()));
}
private JdbcPreparedStatement prepareStatementReplaceNullWithAnyString(
String sql, String... params) throws SQLException {
JdbcPreparedStatement statement = connection.prepareStatement(sql);
int paramIndex = 1;
for (String param : params) {
if (param == null) {
statement.setString(paramIndex, "%");
} else {
statement.setString(paramIndex, param.toUpperCase());
}
paramIndex++;
}
return statement;
}
@Override
public ResultSet getTables(
String catalog, String schemaPattern, String tableNamePattern, String[] types)
throws SQLException {
String sql = readSqlFromFile("DatabaseMetaData_GetTables.sql");
String type1;
String type2;
if (types == null || types.length == 0) {
type1 = "TABLE";
type2 = "VIEW";
} else if (types.length == 1) {
type1 = types[0];
type2 = "NON_EXISTENT_TYPE";
} else {
type1 = types[0];
type2 = types[1];
}
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(
sql, catalog, schemaPattern, tableNamePattern, type1, type2);
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
}
@Override
public ResultSet getSchemas() throws SQLException {
return getSchemas(null, null);
}
@Override
public ResultSet getCatalogs() throws SQLException {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(StructField.of("TABLE_CAT", Type.string())),
Arrays.asList(Struct.newBuilder().set("TABLE_CAT").to("").build())));
}
@Override
public ResultSet getTableTypes() throws SQLException {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(StructField.of("TABLE_TYPE", Type.string())),
Arrays.asList(
Struct.newBuilder().set("TABLE_TYPE").to("TABLE").build(),
Struct.newBuilder().set("TABLE_TYPE").to("VIEW").build())));
}
@Override
public ResultSet getColumns(
String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)
throws SQLException {
String sql = readSqlFromFile("DatabaseMetaData_GetColumns.sql");
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(
sql, catalog, schemaPattern, tableNamePattern, columnNamePattern);
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
}
@Override
public ResultSet getColumnPrivileges(
String catalog, String schema, String table, String columnNamePattern) throws SQLException {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
StructField.of("TABLE_CAT", Type.string()),
StructField.of("TABLE_SCHEM", Type.string()),
StructField.of("TABLE_NAME", Type.string()),
StructField.of("COLUMN_NAME", Type.string()),
StructField.of("GRANTOR", Type.string()),
StructField.of("GRANTEE", Type.string()),
StructField.of("PRIVILEGE", Type.string()),
StructField.of("IS_GRANTABLE", Type.string())),
Collections.<Struct>emptyList()));
}
@Override
public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern)
throws SQLException {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
StructField.of("TABLE_CAT", Type.string()),
StructField.of("TABLE_SCHEM", Type.string()),
StructField.of("TABLE_NAME", Type.string()),
StructField.of("GRANTOR", Type.string()),
StructField.of("GRANTEE", Type.string()),
StructField.of("PRIVILEGE", Type.string()),
StructField.of("IS_GRANTABLE", Type.string())),
Collections.<Struct>emptyList()));
}
@Override
public ResultSet getBestRowIdentifier(
String catalog, String schema, String table, int scope, boolean nullable)
throws SQLException {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
StructField.of("SCOPE", Type.int64()),
StructField.of("COLUMN_NAME", Type.string()),
StructField.of("DATA_TYPE", Type.int64()),
StructField.of("TYPE_NAME", Type.string()),
StructField.of("COLUMN_SIZE", Type.int64()),
StructField.of("BUFFER_LENGTH", Type.int64()),
StructField.of("DECIMAL_DIGITS", Type.int64()),
StructField.of("PSEUDO_COLUMN", Type.int64())),
Collections.<Struct>emptyList()));
}
@Override
public ResultSet getVersionColumns(String catalog, String schema, String table)
throws SQLException {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
StructField.of("SCOPE", Type.int64()),
StructField.of("COLUMN_NAME", Type.string()),
StructField.of("DATA_TYPE", Type.int64()),
StructField.of("TYPE_NAME", Type.string()),
StructField.of("COLUMN_SIZE", Type.int64()),
StructField.of("BUFFER_LENGTH", Type.int64()),
StructField.of("DECIMAL_DIGITS", Type.int64()),
StructField.of("PSEUDO_COLUMN", Type.int64())),
Collections.<Struct>emptyList()));
}
@Override
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
JdbcPreconditions.checkArgument(table != null, "table may not be null");
String sql = readSqlFromFile("DatabaseMetaData_GetPrimaryKeys.sql");
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(sql, catalog, schema, table);
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
}
@Override
public ResultSet getImportedKeys(String catalog, String schema, String table)
throws SQLException {
JdbcPreconditions.checkArgument(table != null, "table may not be null");
String sql = readSqlFromFile("DatabaseMetaData_GetImportedKeys.sql");
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(sql, catalog, schema, table);
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
}
@Override
public ResultSet getExportedKeys(String catalog, String schema, String table)
throws SQLException {
JdbcPreconditions.checkArgument(table != null, "table may not be null");
String sql = readSqlFromFile("DatabaseMetaData_GetExportedKeys.sql");
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(sql, catalog, schema, table);
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
}
@Override
public ResultSet getCrossReference(
String parentCatalog,
String parentSchema,
String parentTable,
String foreignCatalog,
String foreignSchema,
String foreignTable)
throws SQLException {
String sql = readSqlFromFile("DatabaseMetaData_GetCrossReferences.sql");
JdbcPreparedStatement statement =
prepareStatementReplaceNullWithAnyString(
sql,
parentCatalog,
parentSchema,
parentTable,
foreignCatalog,
foreignSchema,
foreignTable);
return statement.executeQueryWithOptions(InternalMetadataQuery.INSTANCE);
}
@Override
public ResultSet getTypeInfo() throws SQLException {
return JdbcResultSet.of(
ResultSets.forRows(
Type.struct(
StructField.of("TYPE_NAME", Type.string()),
StructField.of("DATA_TYPE", Type.int64()),
StructField.of("PRECISION", Type.int64()),
StructField.of("LITERAL_PREFIX", Type.string()),
StructField.of("LITERAL_SUFFIX", Type.string()),
StructField.of("CREATE_PARAMS", Type.string()),
StructField.of("NULLABLE", Type.int64()),
StructField.of("CASE_SENSITIVE", Type.bool()),
StructField.of("SEARCHABLE", Type.int64()),
StructField.of("UNSIGNED_ATTRIBUTE", Type.bool()),
StructField.of("FIXED_PREC_SCALE", Type.bool()),
StructField.of("AUTO_INCREMENT", Type.bool()),
StructField.of("LOCAL_TYPE_NAME", Type.string()),
StructField.of("MINIMUM_SCALE", Type.int64()),
StructField.of("MAXIMUM_SCALE", Type.int64()),
StructField.of("SQL_DATA_TYPE", Type.int64()),
StructField.of("SQL_DATETIME_SUB", Type.int64()),
StructField.of("NUM_PREC_RADIX", Type.int64())),
Arrays.asList(
Struct.newBuilder()
.set("TYPE_NAME")
.to("STRING")
.set("DATA_TYPE")
.to(Types.NVARCHAR) // -9
.set("PRECISION")
.to(2621440L)
.set("LITERAL_PREFIX")
.to((String) null)
.set("LITERAL_SUFFIX")
.to((String) null)
.set("CREATE_PARAMS")
.to("(length)")
.set("NULLABLE")
.to(DatabaseMetaData.typeNullable)
.set("CASE_SENSITIVE")
.to(true)
.set("SEARCHABLE")
.to(DatabaseMetaData.typeSearchable)
.set("UNSIGNED_ATTRIBUTE")
.to(true)
.set("FIXED_PREC_SCALE")
.to(false)
.set("AUTO_INCREMENT")
.to(false)
.set("LOCAL_TYPE_NAME")
.to("STRING")
.set("MINIMUM_SCALE")
.to(0)
.set("MAXIMUM_SCALE")
.to(0)
.set("SQL_DATA_TYPE")
.to((Long) null)
.set("SQL_DATETIME_SUB")
.to((Long) null)
.set("NUM_PREC_RADIX")
.to((Long) null)
.build(),
Struct.newBuilder()
.set("TYPE_NAME")
.to("INT64")
.set("DATA_TYPE")
.to(Types.BIGINT) // -5
.set("PRECISION")
.to(19L)
.set("LITERAL_PREFIX")
.to((String) null)
.set("LITERAL_SUFFIX")
.to((String) null)
.set("CREATE_PARAMS")
.to((String) null)
.set("NULLABLE")
.to(DatabaseMetaData.typeNullable)
.set("CASE_SENSITIVE")
.to(false)
.set("SEARCHABLE")
.to(DatabaseMetaData.typePredBasic)
.set("UNSIGNED_ATTRIBUTE")
.to(false)
.set("FIXED_PREC_SCALE")