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 ;
@@ -903,7 +903,6 @@ private static String columnDataTypeToSqlType(String value) {
903903 @ Override
904904 public ResultSet getColumnPrivileges (String catalog , String schema , String table , String columnNamePattern ) throws SQLException {
905905 //Return an empty result set with the required columns
906- log .warn ("getColumnPrivileges is not supported and may return invalid results" );
907906 try {
908907 return connection .createStatement ().executeQuery ("SELECT NULL::Nullable(String) AS TABLE_CAT, " +
909908 "NULL::Nullable(String) AS TABLE_SCHEM, " +
@@ -912,7 +911,8 @@ public ResultSet getColumnPrivileges(String catalog, String schema, String table
912911 "NULL::Nullable(String) AS GRANTOR, " +
913912 "NULL::Nullable(String) AS GRANTEE, " +
914913 "NULL::Nullable(String) AS PRIVILEGE, " +
915- "NULL::Nullable(String) AS IS_GRANTABLE" );
914+ "NULL::Nullable(String) AS IS_GRANTABLE" +
915+ " LIMIT 0" );
916916 } catch (Exception e ) {
917917 throw ExceptionUtils .toSqlState (e );
918918 }
@@ -921,15 +921,15 @@ public ResultSet getColumnPrivileges(String catalog, String schema, String table
921921 @ Override
922922 public ResultSet getTablePrivileges (String catalog , String schemaPattern , String tableNamePattern ) throws SQLException {
923923 //Return an empty result set with the required columns
924- log .warn ("getTablePrivileges is not supported and may return invalid results" );
925924 try {
926925 return connection .createStatement ().executeQuery ("SELECT NULL::Nullable(String) AS TABLE_CAT, " +
927926 "NULL::Nullable(String) AS TABLE_SCHEM, " +
928927 "NULL::Nullable(String) AS TABLE_NAME, " +
929928 "NULL::Nullable(String) AS GRANTOR, " +
930929 "NULL::Nullable(String) AS GRANTEE, " +
931930 "NULL::Nullable(String) AS PRIVILEGE, " +
932- "NULL::Nullable(String) AS IS_GRANTABLE" );
931+ "NULL::Nullable(String) AS IS_GRANTABLE" +
932+ " LIMIT 0" );
933933 } catch (Exception e ) {
934934 throw ExceptionUtils .toSqlState (e );
935935 }
@@ -938,7 +938,6 @@ public ResultSet getTablePrivileges(String catalog, String schemaPattern, String
938938 @ Override
939939 public ResultSet getBestRowIdentifier (String catalog , String schema , String table , int scope , boolean nullable ) throws SQLException {
940940 //Return an empty result set with the required columns
941- log .warn ("getBestRowIdentifier is not supported and may return invalid results" );
942941 try {
943942 return connection .createStatement ().executeQuery ("SELECT NULL::Nullable(Int16) AS SCOPE, " +
944943 "NULL::Nullable(String) AS COLUMN_NAME, " +
@@ -947,7 +946,8 @@ public ResultSet getBestRowIdentifier(String catalog, String schema, String tabl
947946 "NULL::Nullable(Int32) AS COLUMN_SIZE, " +
948947 "NULL::Nullable(Int32) AS BUFFER_LENGTH, " +
949948 "NULL::Nullable(Int16) AS DECIMAL_DIGITS, " +
950- "NULL::Nullable(Int16) AS PSEUDO_COLUMN" );
949+ "NULL::Nullable(Int16) AS PSEUDO_COLUMN" +
950+ " LIMIT 0" );
951951 } catch (Exception e ) {
952952 throw ExceptionUtils .toSqlState (e );
953953 }
@@ -956,7 +956,6 @@ public ResultSet getBestRowIdentifier(String catalog, String schema, String tabl
956956 @ Override
957957 public ResultSet getVersionColumns (String catalog , String schema , String table ) throws SQLException {
958958 //Return an empty result set with the required columns
959- log .warn ("getVersionColumns is not supported and may return invalid results" );
960959 try {
961960 return connection .createStatement ().executeQuery ("SELECT NULL::Nullable(Int16) AS SCOPE, " +
962961 "NULL::Nullable(String) AS COLUMN_NAME, " +
@@ -965,7 +964,8 @@ public ResultSet getVersionColumns(String catalog, String schema, String table)
965964 "NULL::Nullable(Int32) AS COLUMN_SIZE, " +
966965 "NULL::Nullable(Int32) AS BUFFER_LENGTH, " +
967966 "NULL::Nullable(Int16) AS DECIMAL_DIGITS, " +
968- "NULL::Nullable(Int16) AS PSEUDO_COLUMN" );
967+ "NULL::Nullable(Int16) AS PSEUDO_COLUMN" +
968+ " LIMIT 0" );
969969 } catch (Exception e ) {
970970 throw ExceptionUtils .toSqlState (e );
971971 }
@@ -995,8 +995,7 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr
995995
996996 @ Override
997997 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
1000999 try {
10011000 String sql = "SELECT NULL::Nullable(String) AS PKTABLE_CAT, " +
10021001 "NULL::Nullable(String) AS PKTABLE_SCHEM, " +
@@ -1011,7 +1010,8 @@ public ResultSet getImportedKeys(String catalog, String schema, String table) th
10111010 "NULL::Nullable(Int16) AS DELETE_RULE, " +
10121011 "NULL::Nullable(String) AS FK_NAME, " +
10131012 "NULL::Nullable(String) AS PK_NAME, " +
1014- "NULL::Nullable(Int16) AS DEFERRABILITY" ;
1013+ "NULL::Nullable(Int16) AS DEFERRABILITY" +
1014+ " LIMIT 0" ;
10151015 return connection .createStatement ().executeQuery (sql );
10161016 } catch (Exception e ) {
10171017 throw ExceptionUtils .toSqlState (e );
@@ -1020,8 +1020,7 @@ public ResultSet getImportedKeys(String catalog, String schema, String table) th
10201020
10211021 @ Override
10221022 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
10251024 try {
10261025 return connection .createStatement ().executeQuery ("SELECT NULL::Nullable(String) AS PKTABLE_CAT, " +
10271026 "NULL::Nullable(String) AS PKTABLE_SCHEM, " +
@@ -1036,7 +1035,8 @@ public ResultSet getExportedKeys(String catalog, String schema, String table) th
10361035 "NULL::Nullable(Int16) AS DELETE_RULE, " +
10371036 "NULL::Nullable(String) AS FK_NAME, " +
10381037 "NULL::Nullable(String) AS PK_NAME, " +
1039- "NULL::Nullable(Int16) AS DEFERRABILITY" );
1038+ "NULL::Nullable(Int16) AS DEFERRABILITY" +
1039+ " LIMIT 0" );
10401040 } catch (Exception e ) {
10411041 throw ExceptionUtils .toSqlState (e );
10421042 }
@@ -1045,7 +1045,6 @@ public ResultSet getExportedKeys(String catalog, String schema, String table) th
10451045 @ Override
10461046 public ResultSet getCrossReference (String parentCatalog , String parentSchema , String parentTable , String foreignCatalog , String foreignSchema , String foreignTable ) throws SQLException {
10471047 //Return an empty result set with the required columns
1048- log .warn ("getCrossReference is not supported and may return invalid results" );
10491048 try {
10501049 String columns = "NULL ::Nullable(String) AS PKTABLE_CAT, " +
10511050 "NULL::Nullable(String) AS PKTABLE_SCHEM, " +
@@ -1060,7 +1059,8 @@ public ResultSet getCrossReference(String parentCatalog, String parentSchema, St
10601059 "NULL::Nullable(Int16) AS DELETE_RULE, " +
10611060 "NULL::Nullable(String) AS FK_NAME, " +
10621061 "NULL::Nullable(String) AS PK_NAME, " +
1063- "NULL::Nullable(Int16) AS DEFERRABILITY" ;
1062+ "NULL::Nullable(Int16) AS DEFERRABILITY" +
1063+ " LIMIT 0" ;
10641064 return connection .createStatement ().executeQuery ("SELECT " + columns );
10651065 } catch (Exception e ) {
10661066 throw ExceptionUtils .toSqlState (e );
@@ -1150,7 +1150,8 @@ public ResultSet getIndexInfo(String catalog, String schema, String table, boole
11501150 "null::Nullable(String) AS ASC_OR_DESC, " +
11511151 "null::Nullable(Int64) AS CARDINALITY, " +
11521152 "null::Nullable(Int64) AS PAGES, " +
1153- "null::Nullable(String) AS FILTER_CONDITION " ;
1153+ "null::Nullable(String) AS FILTER_CONDITION " +
1154+ " LIMIT 0" ;
11541155 return connection .createStatement ().executeQuery (sql );
11551156 } catch (Exception e ) {
11561157 throw ExceptionUtils .toSqlState (e );
@@ -1220,7 +1221,6 @@ public boolean supportsBatchUpdates() throws SQLException {
12201221 @ Override
12211222 public ResultSet getUDTs (String catalog , String schemaPattern , String typeNamePattern , int [] types ) throws SQLException {
12221223 //Return an empty result set with the required columns
1223- log .warn ("getUDTs is not supported and may return invalid results" );
12241224 try {
12251225 return connection .createStatement ().executeQuery ("SELECT " +
12261226 "NULL::Nullable(String) AS TYPE_CAT, " +
@@ -1229,7 +1229,8 @@ public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePa
12291229 "NULL::Nullable(String) AS CLASS_NAME, " +
12301230 "NULL::Nullable(Int32) AS DATA_TYPE, " +
12311231 "NULL::Nullable(String) AS REMARKS, " +
1232- "NULL::Nullable(Int16) AS BASE_TYPE" );
1232+ "NULL::Nullable(Int16) AS BASE_TYPE" +
1233+ " LIMIT 0" );
12331234 } catch (Exception e ) {
12341235 throw ExceptionUtils .toSqlState (e );
12351236 }
@@ -1266,15 +1267,15 @@ public boolean supportsGetGeneratedKeys() throws SQLException {
12661267 @ Override
12671268 public ResultSet getSuperTypes (String catalog , String schemaPattern , String typeNamePattern ) throws SQLException {
12681269 //Return an empty result set with the required columns
1269- log .warn ("getSuperTypes is not supported and may return invalid results" );
12701270 try {
12711271 return connection .createStatement ().executeQuery (
12721272 "SELECT NULL::Nullable(String) AS TYPE_CAT, "
12731273 + "NULL::Nullable(String) AS TYPE_SCHEM, "
12741274 + "NULL::Nullable(String) AS TYPE_NAME, "
12751275 + "NULL::Nullable(String) AS SUPERTYPE_CAT, "
12761276 + "NULL::Nullable(String) AS SUPERTYPE_SCHEM, "
1277- + "NULL::Nullable(String) AS SUPERTYPE_NAME" );
1277+ + "NULL::Nullable(String) AS SUPERTYPE_NAME" +
1278+ " LIMIT 0" );
12781279 } catch (Exception e ) {
12791280 throw ExceptionUtils .toSqlState (e );
12801281 }
@@ -1283,14 +1284,14 @@ public ResultSet getSuperTypes(String catalog, String schemaPattern, String type
12831284 @ Override
12841285 public ResultSet getSuperTables (String catalog , String schemaPattern , String tableNamePattern ) throws SQLException {
12851286 //Return an empty result set with the required columns
1286- log .warn ("getSuperTables is not supported and may return invalid results" );
12871287 try {
12881288 return connection .createStatement ().executeQuery (
12891289 "SELECT "
12901290 + "NULL::Nullable(String) AS TABLE_CAT, "
12911291 + "NULL::Nullable(String) AS TABLE_SCHEM, "
12921292 + "NULL::Nullable(String) AS TABLE_NAME, "
1293- + "NULL::Nullable(String) AS SUPERTABLE_NAME" );
1293+ + "NULL::Nullable(String) AS SUPERTABLE_NAME" +
1294+ " LIMIT 0" );
12941295 } catch (Exception e ) {
12951296 throw ExceptionUtils .toSqlState (e );
12961297 }
@@ -1299,7 +1300,6 @@ public ResultSet getSuperTables(String catalog, String schemaPattern, String tab
12991300 @ Override
13001301 public ResultSet getAttributes (String catalog , String schemaPattern , String typeNamePattern , String attributeNamePattern ) throws SQLException {
13011302 //Return an empty result set with the required columns
1302- log .warn ("getAttributes is not supported and may return invalid results" );
13031303 try {
13041304 return connection .createStatement ().executeQuery (
13051305 "SELECT "
@@ -1323,7 +1323,8 @@ public ResultSet getAttributes(String catalog, String schemaPattern, String type
13231323 + "NULL::Nullable(String) AS SCOPE_CATALOG, "
13241324 + "NULL::Nullable(String) AS SCOPE_SCHEMA, "
13251325 + "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" );
13271328 } catch (Exception e ) {
13281329 throw ExceptionUtils .toSqlState (e );
13291330 }
0 commit comments