3
3
import com .clickhouse .client .api .sql .SQLUtils ;
4
4
import com .clickhouse .data .ClickHouseColumn ;
5
5
import com .clickhouse .data .ClickHouseDataType ;
6
+ import com .clickhouse .jdbc .ClientInfoProperties ;
6
7
import com .clickhouse .jdbc .ConnectionImpl ;
7
8
import com .clickhouse .jdbc .Driver ;
9
+ import com .clickhouse .jdbc .DriverProperties ;
8
10
import com .clickhouse .jdbc .JdbcV2Wrapper ;
9
11
import com .clickhouse .jdbc .ResultSetImpl ;
10
- import com .clickhouse .jdbc .ClientInfoProperties ;
11
- import com .clickhouse .jdbc .DriverProperties ;
12
12
import com .clickhouse .jdbc .internal .ExceptionUtils ;
13
13
import com .clickhouse .jdbc .internal .JdbcUtils ;
14
14
import com .clickhouse .jdbc .internal .MetadataResultSet ;
@@ -903,7 +903,6 @@ private static String columnDataTypeToSqlType(String value) {
903
903
@ Override
904
904
public ResultSet getColumnPrivileges (String catalog , String schema , String table , String columnNamePattern ) throws SQLException {
905
905
//Return an empty result set with the required columns
906
- log .warn ("getColumnPrivileges is not supported and may return invalid results" );
907
906
try {
908
907
return connection .createStatement ().executeQuery ("SELECT NULL::Nullable(String) AS TABLE_CAT, " +
909
908
"NULL::Nullable(String) AS TABLE_SCHEM, " +
@@ -912,7 +911,8 @@ public ResultSet getColumnPrivileges(String catalog, String schema, String table
912
911
"NULL::Nullable(String) AS GRANTOR, " +
913
912
"NULL::Nullable(String) AS GRANTEE, " +
914
913
"NULL::Nullable(String) AS PRIVILEGE, " +
915
- "NULL::Nullable(String) AS IS_GRANTABLE" );
914
+ "NULL::Nullable(String) AS IS_GRANTABLE" +
915
+ " LIMIT 0" );
916
916
} catch (Exception e ) {
917
917
throw ExceptionUtils .toSqlState (e );
918
918
}
@@ -921,15 +921,15 @@ public ResultSet getColumnPrivileges(String catalog, String schema, String table
921
921
@ Override
922
922
public ResultSet getTablePrivileges (String catalog , String schemaPattern , String tableNamePattern ) throws SQLException {
923
923
//Return an empty result set with the required columns
924
- log .warn ("getTablePrivileges is not supported and may return invalid results" );
925
924
try {
926
925
return connection .createStatement ().executeQuery ("SELECT NULL::Nullable(String) AS TABLE_CAT, " +
927
926
"NULL::Nullable(String) AS TABLE_SCHEM, " +
928
927
"NULL::Nullable(String) AS TABLE_NAME, " +
929
928
"NULL::Nullable(String) AS GRANTOR, " +
930
929
"NULL::Nullable(String) AS GRANTEE, " +
931
930
"NULL::Nullable(String) AS PRIVILEGE, " +
932
- "NULL::Nullable(String) AS IS_GRANTABLE" );
931
+ "NULL::Nullable(String) AS IS_GRANTABLE" +
932
+ " LIMIT 0" );
933
933
} catch (Exception e ) {
934
934
throw ExceptionUtils .toSqlState (e );
935
935
}
@@ -938,7 +938,6 @@ public ResultSet getTablePrivileges(String catalog, String schemaPattern, String
938
938
@ Override
939
939
public ResultSet getBestRowIdentifier (String catalog , String schema , String table , int scope , boolean nullable ) throws SQLException {
940
940
//Return an empty result set with the required columns
941
- log .warn ("getBestRowIdentifier is not supported and may return invalid results" );
942
941
try {
943
942
return connection .createStatement ().executeQuery ("SELECT NULL::Nullable(Int16) AS SCOPE, " +
944
943
"NULL::Nullable(String) AS COLUMN_NAME, " +
@@ -947,7 +946,8 @@ public ResultSet getBestRowIdentifier(String catalog, String schema, String tabl
947
946
"NULL::Nullable(Int32) AS COLUMN_SIZE, " +
948
947
"NULL::Nullable(Int32) AS BUFFER_LENGTH, " +
949
948
"NULL::Nullable(Int16) AS DECIMAL_DIGITS, " +
950
- "NULL::Nullable(Int16) AS PSEUDO_COLUMN" );
949
+ "NULL::Nullable(Int16) AS PSEUDO_COLUMN" +
950
+ " LIMIT 0" );
951
951
} catch (Exception e ) {
952
952
throw ExceptionUtils .toSqlState (e );
953
953
}
@@ -956,7 +956,6 @@ public ResultSet getBestRowIdentifier(String catalog, String schema, String tabl
956
956
@ Override
957
957
public ResultSet getVersionColumns (String catalog , String schema , String table ) throws SQLException {
958
958
//Return an empty result set with the required columns
959
- log .warn ("getVersionColumns is not supported and may return invalid results" );
960
959
try {
961
960
return connection .createStatement ().executeQuery ("SELECT NULL::Nullable(Int16) AS SCOPE, " +
962
961
"NULL::Nullable(String) AS COLUMN_NAME, " +
@@ -965,7 +964,8 @@ public ResultSet getVersionColumns(String catalog, String schema, String table)
965
964
"NULL::Nullable(Int32) AS COLUMN_SIZE, " +
966
965
"NULL::Nullable(Int32) AS BUFFER_LENGTH, " +
967
966
"NULL::Nullable(Int16) AS DECIMAL_DIGITS, " +
968
- "NULL::Nullable(Int16) AS PSEUDO_COLUMN" );
967
+ "NULL::Nullable(Int16) AS PSEUDO_COLUMN" +
968
+ " LIMIT 0" );
969
969
} catch (Exception e ) {
970
970
throw ExceptionUtils .toSqlState (e );
971
971
}
@@ -995,8 +995,7 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr
995
995
996
996
@ Override
997
997
public ResultSet getImportedKeys (String catalog , String schema , String table ) throws SQLException {
998
- //Return an empty result set with the required columns
999
- log .warn ("getImportedKeys is not supported and may return invalid results" );
998
+ // ClickHouse has no notion of foreign key. This method should return empty resultset
1000
999
try {
1001
1000
String sql = "SELECT NULL::Nullable(String) AS PKTABLE_CAT, " +
1002
1001
"NULL::Nullable(String) AS PKTABLE_SCHEM, " +
@@ -1011,7 +1010,8 @@ public ResultSet getImportedKeys(String catalog, String schema, String table) th
1011
1010
"NULL::Nullable(Int16) AS DELETE_RULE, " +
1012
1011
"NULL::Nullable(String) AS FK_NAME, " +
1013
1012
"NULL::Nullable(String) AS PK_NAME, " +
1014
- "NULL::Nullable(Int16) AS DEFERRABILITY" ;
1013
+ "NULL::Nullable(Int16) AS DEFERRABILITY" +
1014
+ " LIMIT 0" ;
1015
1015
return connection .createStatement ().executeQuery (sql );
1016
1016
} catch (Exception e ) {
1017
1017
throw ExceptionUtils .toSqlState (e );
@@ -1020,8 +1020,7 @@ public ResultSet getImportedKeys(String catalog, String schema, String table) th
1020
1020
1021
1021
@ Override
1022
1022
public ResultSet getExportedKeys (String catalog , String schema , String table ) throws SQLException {
1023
- //Return an empty result set with the required columns
1024
- log .warn ("getExportedKeys is not supported and may return invalid results" );
1023
+ // ClickHouse has no notion of foreign key. This method should return empty resultset
1025
1024
try {
1026
1025
return connection .createStatement ().executeQuery ("SELECT NULL::Nullable(String) AS PKTABLE_CAT, " +
1027
1026
"NULL::Nullable(String) AS PKTABLE_SCHEM, " +
@@ -1036,7 +1035,8 @@ public ResultSet getExportedKeys(String catalog, String schema, String table) th
1036
1035
"NULL::Nullable(Int16) AS DELETE_RULE, " +
1037
1036
"NULL::Nullable(String) AS FK_NAME, " +
1038
1037
"NULL::Nullable(String) AS PK_NAME, " +
1039
- "NULL::Nullable(Int16) AS DEFERRABILITY" );
1038
+ "NULL::Nullable(Int16) AS DEFERRABILITY" +
1039
+ " LIMIT 0" );
1040
1040
} catch (Exception e ) {
1041
1041
throw ExceptionUtils .toSqlState (e );
1042
1042
}
@@ -1045,7 +1045,6 @@ public ResultSet getExportedKeys(String catalog, String schema, String table) th
1045
1045
@ Override
1046
1046
public ResultSet getCrossReference (String parentCatalog , String parentSchema , String parentTable , String foreignCatalog , String foreignSchema , String foreignTable ) throws SQLException {
1047
1047
//Return an empty result set with the required columns
1048
- log .warn ("getCrossReference is not supported and may return invalid results" );
1049
1048
try {
1050
1049
String columns = "NULL ::Nullable(String) AS PKTABLE_CAT, " +
1051
1050
"NULL::Nullable(String) AS PKTABLE_SCHEM, " +
@@ -1060,7 +1059,8 @@ public ResultSet getCrossReference(String parentCatalog, String parentSchema, St
1060
1059
"NULL::Nullable(Int16) AS DELETE_RULE, " +
1061
1060
"NULL::Nullable(String) AS FK_NAME, " +
1062
1061
"NULL::Nullable(String) AS PK_NAME, " +
1063
- "NULL::Nullable(Int16) AS DEFERRABILITY" ;
1062
+ "NULL::Nullable(Int16) AS DEFERRABILITY" +
1063
+ " LIMIT 0" ;
1064
1064
return connection .createStatement ().executeQuery ("SELECT " + columns );
1065
1065
} catch (Exception e ) {
1066
1066
throw ExceptionUtils .toSqlState (e );
@@ -1150,7 +1150,8 @@ public ResultSet getIndexInfo(String catalog, String schema, String table, boole
1150
1150
"null::Nullable(String) AS ASC_OR_DESC, " +
1151
1151
"null::Nullable(Int64) AS CARDINALITY, " +
1152
1152
"null::Nullable(Int64) AS PAGES, " +
1153
- "null::Nullable(String) AS FILTER_CONDITION " ;
1153
+ "null::Nullable(String) AS FILTER_CONDITION " +
1154
+ " LIMIT 0" ;
1154
1155
return connection .createStatement ().executeQuery (sql );
1155
1156
} catch (Exception e ) {
1156
1157
throw ExceptionUtils .toSqlState (e );
@@ -1220,7 +1221,6 @@ public boolean supportsBatchUpdates() throws SQLException {
1220
1221
@ Override
1221
1222
public ResultSet getUDTs (String catalog , String schemaPattern , String typeNamePattern , int [] types ) throws SQLException {
1222
1223
//Return an empty result set with the required columns
1223
- log .warn ("getUDTs is not supported and may return invalid results" );
1224
1224
try {
1225
1225
return connection .createStatement ().executeQuery ("SELECT " +
1226
1226
"NULL::Nullable(String) AS TYPE_CAT, " +
@@ -1229,7 +1229,8 @@ public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePa
1229
1229
"NULL::Nullable(String) AS CLASS_NAME, " +
1230
1230
"NULL::Nullable(Int32) AS DATA_TYPE, " +
1231
1231
"NULL::Nullable(String) AS REMARKS, " +
1232
- "NULL::Nullable(Int16) AS BASE_TYPE" );
1232
+ "NULL::Nullable(Int16) AS BASE_TYPE" +
1233
+ " LIMIT 0" );
1233
1234
} catch (Exception e ) {
1234
1235
throw ExceptionUtils .toSqlState (e );
1235
1236
}
@@ -1266,15 +1267,15 @@ public boolean supportsGetGeneratedKeys() throws SQLException {
1266
1267
@ Override
1267
1268
public ResultSet getSuperTypes (String catalog , String schemaPattern , String typeNamePattern ) throws SQLException {
1268
1269
//Return an empty result set with the required columns
1269
- log .warn ("getSuperTypes is not supported and may return invalid results" );
1270
1270
try {
1271
1271
return connection .createStatement ().executeQuery (
1272
1272
"SELECT NULL::Nullable(String) AS TYPE_CAT, "
1273
1273
+ "NULL::Nullable(String) AS TYPE_SCHEM, "
1274
1274
+ "NULL::Nullable(String) AS TYPE_NAME, "
1275
1275
+ "NULL::Nullable(String) AS SUPERTYPE_CAT, "
1276
1276
+ "NULL::Nullable(String) AS SUPERTYPE_SCHEM, "
1277
- + "NULL::Nullable(String) AS SUPERTYPE_NAME" );
1277
+ + "NULL::Nullable(String) AS SUPERTYPE_NAME" +
1278
+ " LIMIT 0" );
1278
1279
} catch (Exception e ) {
1279
1280
throw ExceptionUtils .toSqlState (e );
1280
1281
}
@@ -1283,14 +1284,14 @@ public ResultSet getSuperTypes(String catalog, String schemaPattern, String type
1283
1284
@ Override
1284
1285
public ResultSet getSuperTables (String catalog , String schemaPattern , String tableNamePattern ) throws SQLException {
1285
1286
//Return an empty result set with the required columns
1286
- log .warn ("getSuperTables is not supported and may return invalid results" );
1287
1287
try {
1288
1288
return connection .createStatement ().executeQuery (
1289
1289
"SELECT "
1290
1290
+ "NULL::Nullable(String) AS TABLE_CAT, "
1291
1291
+ "NULL::Nullable(String) AS TABLE_SCHEM, "
1292
1292
+ "NULL::Nullable(String) AS TABLE_NAME, "
1293
- + "NULL::Nullable(String) AS SUPERTABLE_NAME" );
1293
+ + "NULL::Nullable(String) AS SUPERTABLE_NAME" +
1294
+ " LIMIT 0" );
1294
1295
} catch (Exception e ) {
1295
1296
throw ExceptionUtils .toSqlState (e );
1296
1297
}
@@ -1299,7 +1300,6 @@ public ResultSet getSuperTables(String catalog, String schemaPattern, String tab
1299
1300
@ Override
1300
1301
public ResultSet getAttributes (String catalog , String schemaPattern , String typeNamePattern , String attributeNamePattern ) throws SQLException {
1301
1302
//Return an empty result set with the required columns
1302
- log .warn ("getAttributes is not supported and may return invalid results" );
1303
1303
try {
1304
1304
return connection .createStatement ().executeQuery (
1305
1305
"SELECT "
@@ -1323,7 +1323,8 @@ public ResultSet getAttributes(String catalog, String schemaPattern, String type
1323
1323
+ "NULL::Nullable(String) AS SCOPE_CATALOG, "
1324
1324
+ "NULL::Nullable(String) AS SCOPE_SCHEMA, "
1325
1325
+ "NULL::Nullable(String) AS SCOPE_TABLE, "
1326
- + "NULL::Nullable(Int16) AS SOURCE_DATA_TYPE" );
1326
+ + "NULL::Nullable(Int16) AS SOURCE_DATA_TYPE" +
1327
+ " LIMIT 0" );
1327
1328
} catch (Exception e ) {
1328
1329
throw ExceptionUtils .toSqlState (e );
1329
1330
}
0 commit comments