Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.clickhouse.jdbc.internal.JdbcConfiguration;
import com.clickhouse.jdbc.internal.ExceptionUtils;
import com.clickhouse.jdbc.internal.JdbcUtils;
import com.clickhouse.jdbc.metadata.DatabaseMetaDataImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -54,7 +55,7 @@ public class ConnectionImpl implements Connection, JdbcV2Wrapper {
private String appName;
private QuerySettings defaultQuerySettings;

private final com.clickhouse.jdbc.metadata.DatabaseMetaData metadata;
private final DatabaseMetaDataImpl metadata;
protected final Calendar defaultCalendar;

public ConnectionImpl(String url, Properties info) throws SQLException {
Expand Down Expand Up @@ -96,7 +97,7 @@ public ConnectionImpl(String url, Properties info) throws SQLException {
.serverSetting(ServerSettings.ASYNC_INSERT, "0")
.serverSetting(ServerSettings.WAIT_END_OF_QUERY, "0");

this.metadata = new com.clickhouse.jdbc.metadata.DatabaseMetaData(this, false, url);
this.metadata = new DatabaseMetaDataImpl(this, false, url);
this.defaultCalendar = Calendar.getInstance();
} catch (SQLException e) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import java.sql.SQLType;
import java.util.Arrays;

public class DatabaseMetaData implements java.sql.DatabaseMetaData, JdbcV2Wrapper {
private static final Logger log = LoggerFactory.getLogger(DatabaseMetaData.class);
public class DatabaseMetaDataImpl implements java.sql.DatabaseMetaData, JdbcV2Wrapper {
private static final Logger log = LoggerFactory.getLogger(DatabaseMetaDataImpl.class);
public static final String[] TABLE_TYPES = new String[] { "DICTIONARY", "LOG TABLE", "MEMORY TABLE",
"REMOTE TABLE", "TABLE", "VIEW", "SYSTEM TABLE", "TEMPORARY TABLE" };

Expand All @@ -42,7 +42,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData, JdbcV2Wrappe
* @param connection - connection for which metadata is created
* @param useCatalogs - if true then getCatalogs() will return non-empty list (not implemented yet)
*/
public DatabaseMetaData(ConnectionImpl connection, boolean useCatalogs, String url) throws SQLFeatureNotSupportedException {
public DatabaseMetaDataImpl(ConnectionImpl connection, boolean useCatalogs, String url) throws SQLFeatureNotSupportedException {
if (useCatalogs) {
throw new SQLFeatureNotSupportedException("Catalogs are not supported yet", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
}
Expand Down Expand Up @@ -864,7 +864,7 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa
" ORDER BY TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION";
try {
return new MetadataResultSet((ResultSetImpl) connection.createStatement().executeQuery(sql))
.transform(DATA_TYPE_COL.getColumnName(), DATA_TYPE_COL, DatabaseMetaData::columnDataTypeToSqlType);
.transform(DATA_TYPE_COL.getColumnName(), DATA_TYPE_COL, DatabaseMetaDataImpl::columnDataTypeToSqlType);
} catch (Exception e) {
throw ExceptionUtils.toSqlState(e);
}
Expand Down Expand Up @@ -1002,8 +1002,8 @@ public ResultSet getCrossReference(String parentCatalog, String parentSchema, St
public ResultSet getTypeInfo() throws SQLException {
try {
return new MetadataResultSet((ResultSetImpl) connection.createStatement().executeQuery(DATA_TYPE_INFO_SQL))
.transform(DATA_TYPE_COL.getColumnName(), DATA_TYPE_COL, DatabaseMetaData::dataTypeToSqlTypeInt)
.transform(NULLABLE_COL.getColumnName(), NULLABLE_COL, DatabaseMetaData::dataTypeNullability);
.transform(DATA_TYPE_COL.getColumnName(), DATA_TYPE_COL, DatabaseMetaDataImpl::dataTypeToSqlTypeInt)
.transform(NULLABLE_COL.getColumnName(), NULLABLE_COL, DatabaseMetaDataImpl::dataTypeNullability);
} catch (Exception e) {
throw ExceptionUtils.toSqlState(e);
}
Expand Down Expand Up @@ -1065,7 +1065,14 @@ private static String getDataTypeInfoSql() {

@Override
public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException {
return null;
try {
String sql = "SELECT null AS TABLE_CAT, null AS TABLE_SCHEM, null AS TABLE_NAME, null AS NON_UNIQUE," +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect that we use https://clickhouse.com/docs/sql-reference/statements/show#show-index to get information about indexes.

" null AS INDEX_QUALIFIER, null AS INDEX_NAME, null AS TYPE, null AS ORDINAL_POSITION, null AS COLUMN_NAME, null AS ASC_OR_DESC," +
" null AS CARDINALITY, null AS PAGES, null AS FILTER_CONDITION LIMIT 0";
return connection.createStatement().executeQuery(sql);
} catch (Exception e) {
throw ExceptionUtils.toSqlState(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void testGetTableTypes() throws Exception {
try (Connection conn = getJdbcConnection()) {
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getTableTypes();
List<String> sortedTypes = Arrays.asList(com.clickhouse.jdbc.metadata.DatabaseMetaData.TABLE_TYPES);
List<String> sortedTypes = Arrays.asList(DatabaseMetaDataImpl.TABLE_TYPES);
Collections.sort(sortedTypes);
for (String type: sortedTypes) {
assertTrue(rs.next());
Expand Down Expand Up @@ -316,4 +316,14 @@ public void testGetDriverVersion() throws Exception {
assertNotEquals(version, "unknown");
}
}


@Test(groups = { "integration" })
public void testGetIndexInfo() throws Exception {
try (Connection conn = getJdbcConnection()) {
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getIndexInfo(null, null, "numbers", false, false);
assertFalse(rs.next());
}
}
}
Loading