33import com .clickhouse .client .api .sql .SQLUtils ;
44import com .clickhouse .data .ClickHouseColumn ;
55import com .clickhouse .data .ClickHouseDataType ;
6+ import com .clickhouse .jdbc .ClientInfoProperties ;
67import com .clickhouse .jdbc .ConnectionImpl ;
78import com .clickhouse .jdbc .Driver ;
9+ import com .clickhouse .jdbc .DriverProperties ;
810import com .clickhouse .jdbc .JdbcV2Wrapper ;
911import com .clickhouse .jdbc .ResultSetImpl ;
10- import com .clickhouse .jdbc .ClientInfoProperties ;
11- import com .clickhouse .jdbc .DriverProperties ;
1212import com .clickhouse .jdbc .internal .ExceptionUtils ;
1313import com .clickhouse .jdbc .internal .JdbcUtils ;
1414import com .clickhouse .jdbc .internal .MetadataResultSet ;
@@ -912,7 +912,8 @@ public ResultSet getColumnPrivileges(String catalog, String schema, String table
912912 "NULL::Nullable(String) AS GRANTOR, " +
913913 "NULL::Nullable(String) AS GRANTEE, " +
914914 "NULL::Nullable(String) AS PRIVILEGE, " +
915- "NULL::Nullable(String) AS IS_GRANTABLE" );
915+ "NULL::Nullable(String) AS IS_GRANTABLE" +
916+ " LIMIT 0" );
916917 } catch (Exception e ) {
917918 throw ExceptionUtils .toSqlState (e );
918919 }
@@ -929,7 +930,8 @@ public ResultSet getTablePrivileges(String catalog, String schemaPattern, String
929930 "NULL::Nullable(String) AS GRANTOR, " +
930931 "NULL::Nullable(String) AS GRANTEE, " +
931932 "NULL::Nullable(String) AS PRIVILEGE, " +
932- "NULL::Nullable(String) AS IS_GRANTABLE" );
933+ "NULL::Nullable(String) AS IS_GRANTABLE" +
934+ " LIMIT 0" );
933935 } catch (Exception e ) {
934936 throw ExceptionUtils .toSqlState (e );
935937 }
@@ -947,7 +949,8 @@ public ResultSet getBestRowIdentifier(String catalog, String schema, String tabl
947949 "NULL::Nullable(Int32) AS COLUMN_SIZE, " +
948950 "NULL::Nullable(Int32) AS BUFFER_LENGTH, " +
949951 "NULL::Nullable(Int16) AS DECIMAL_DIGITS, " +
950- "NULL::Nullable(Int16) AS PSEUDO_COLUMN" );
952+ "NULL::Nullable(Int16) AS PSEUDO_COLUMN" +
953+ " LIMIT 0" );
951954 } catch (Exception e ) {
952955 throw ExceptionUtils .toSqlState (e );
953956 }
@@ -965,7 +968,8 @@ public ResultSet getVersionColumns(String catalog, String schema, String table)
965968 "NULL::Nullable(Int32) AS COLUMN_SIZE, " +
966969 "NULL::Nullable(Int32) AS BUFFER_LENGTH, " +
967970 "NULL::Nullable(Int16) AS DECIMAL_DIGITS, " +
968- "NULL::Nullable(Int16) AS PSEUDO_COLUMN" );
971+ "NULL::Nullable(Int16) AS PSEUDO_COLUMN" +
972+ " LIMIT 0" );
969973 } catch (Exception e ) {
970974 throw ExceptionUtils .toSqlState (e );
971975 }
@@ -995,8 +999,7 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr
995999
9961000 @ Override
9971001 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" );
1002+ // ClickHouse has no notion of foreign key. This method should return empty resultset
10001003 try {
10011004 String sql = "SELECT NULL::Nullable(String) AS PKTABLE_CAT, " +
10021005 "NULL::Nullable(String) AS PKTABLE_SCHEM, " +
@@ -1011,7 +1014,8 @@ public ResultSet getImportedKeys(String catalog, String schema, String table) th
10111014 "NULL::Nullable(Int16) AS DELETE_RULE, " +
10121015 "NULL::Nullable(String) AS FK_NAME, " +
10131016 "NULL::Nullable(String) AS PK_NAME, " +
1014- "NULL::Nullable(Int16) AS DEFERRABILITY" ;
1017+ "NULL::Nullable(Int16) AS DEFERRABILITY" +
1018+ " LIMIT 0" ;
10151019 return connection .createStatement ().executeQuery (sql );
10161020 } catch (Exception e ) {
10171021 throw ExceptionUtils .toSqlState (e );
@@ -1020,7 +1024,7 @@ public ResultSet getImportedKeys(String catalog, String schema, String table) th
10201024
10211025 @ Override
10221026 public ResultSet getExportedKeys (String catalog , String schema , String table ) throws SQLException {
1023- //Return an empty result set with the required columns
1027+ // ClickHouse has no notion of foreign key. This method should return empty resultset
10241028 log .warn ("getExportedKeys is not supported and may return invalid results" );
10251029 try {
10261030 return connection .createStatement ().executeQuery ("SELECT NULL::Nullable(String) AS PKTABLE_CAT, " +
@@ -1036,7 +1040,8 @@ public ResultSet getExportedKeys(String catalog, String schema, String table) th
10361040 "NULL::Nullable(Int16) AS DELETE_RULE, " +
10371041 "NULL::Nullable(String) AS FK_NAME, " +
10381042 "NULL::Nullable(String) AS PK_NAME, " +
1039- "NULL::Nullable(Int16) AS DEFERRABILITY" );
1043+ "NULL::Nullable(Int16) AS DEFERRABILITY" +
1044+ " LIMIT 0" );
10401045 } catch (Exception e ) {
10411046 throw ExceptionUtils .toSqlState (e );
10421047 }
@@ -1060,7 +1065,8 @@ public ResultSet getCrossReference(String parentCatalog, String parentSchema, St
10601065 "NULL::Nullable(Int16) AS DELETE_RULE, " +
10611066 "NULL::Nullable(String) AS FK_NAME, " +
10621067 "NULL::Nullable(String) AS PK_NAME, " +
1063- "NULL::Nullable(Int16) AS DEFERRABILITY" ;
1068+ "NULL::Nullable(Int16) AS DEFERRABILITY" +
1069+ " LIMIT 0" ;
10641070 return connection .createStatement ().executeQuery ("SELECT " + columns );
10651071 } catch (Exception e ) {
10661072 throw ExceptionUtils .toSqlState (e );
@@ -1150,7 +1156,8 @@ public ResultSet getIndexInfo(String catalog, String schema, String table, boole
11501156 "null::Nullable(String) AS ASC_OR_DESC, " +
11511157 "null::Nullable(Int64) AS CARDINALITY, " +
11521158 "null::Nullable(Int64) AS PAGES, " +
1153- "null::Nullable(String) AS FILTER_CONDITION " ;
1159+ "null::Nullable(String) AS FILTER_CONDITION " +
1160+ " LIMIT 0" ;
11541161 return connection .createStatement ().executeQuery (sql );
11551162 } catch (Exception e ) {
11561163 throw ExceptionUtils .toSqlState (e );
@@ -1229,7 +1236,8 @@ public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePa
12291236 "NULL::Nullable(String) AS CLASS_NAME, " +
12301237 "NULL::Nullable(Int32) AS DATA_TYPE, " +
12311238 "NULL::Nullable(String) AS REMARKS, " +
1232- "NULL::Nullable(Int16) AS BASE_TYPE" );
1239+ "NULL::Nullable(Int16) AS BASE_TYPE" +
1240+ " LIMIT 0" );
12331241 } catch (Exception e ) {
12341242 throw ExceptionUtils .toSqlState (e );
12351243 }
@@ -1274,7 +1282,8 @@ public ResultSet getSuperTypes(String catalog, String schemaPattern, String type
12741282 + "NULL::Nullable(String) AS TYPE_NAME, "
12751283 + "NULL::Nullable(String) AS SUPERTYPE_CAT, "
12761284 + "NULL::Nullable(String) AS SUPERTYPE_SCHEM, "
1277- + "NULL::Nullable(String) AS SUPERTYPE_NAME" );
1285+ + "NULL::Nullable(String) AS SUPERTYPE_NAME" +
1286+ " LIMIT 0" );
12781287 } catch (Exception e ) {
12791288 throw ExceptionUtils .toSqlState (e );
12801289 }
@@ -1290,7 +1299,8 @@ public ResultSet getSuperTables(String catalog, String schemaPattern, String tab
12901299 + "NULL::Nullable(String) AS TABLE_CAT, "
12911300 + "NULL::Nullable(String) AS TABLE_SCHEM, "
12921301 + "NULL::Nullable(String) AS TABLE_NAME, "
1293- + "NULL::Nullable(String) AS SUPERTABLE_NAME" );
1302+ + "NULL::Nullable(String) AS SUPERTABLE_NAME" +
1303+ " LIMIT 0" );
12941304 } catch (Exception e ) {
12951305 throw ExceptionUtils .toSqlState (e );
12961306 }
@@ -1323,7 +1333,8 @@ public ResultSet getAttributes(String catalog, String schemaPattern, String type
13231333 + "NULL::Nullable(String) AS SCOPE_CATALOG, "
13241334 + "NULL::Nullable(String) AS SCOPE_SCHEMA, "
13251335 + "NULL::Nullable(String) AS SCOPE_TABLE, "
1326- + "NULL::Nullable(Int16) AS SOURCE_DATA_TYPE" );
1336+ + "NULL::Nullable(Int16) AS SOURCE_DATA_TYPE" +
1337+ " LIMIT 0" );
13271338 } catch (Exception e ) {
13281339 throw ExceptionUtils .toSqlState (e );
13291340 }
0 commit comments