From c909574102ce0d4a412aba0b3b0e500c7c9acf01 Mon Sep 17 00:00:00 2001 From: Zhichun Wu Date: Sat, 16 Apr 2022 14:57:52 +0800 Subject: [PATCH] Clean up code and enhance enum types --- .../clickhouse/client/ClickHouseColumn.java | 54 ++++++- .../client/ClickHouseCompression.java | 16 +- .../clickhouse/client/ClickHouseFormat.java | 142 ++++++++++++++---- .../clickhouse/client/ClickHouseProtocol.java | 19 ++- .../clickhouse/jdbc/ClickHouseDataSource.java | 11 -- .../jdbc/ClickHouseDatabaseMetaData.java | 2 - .../internal/ClickHouseConnectionImpl.java | 7 +- 7 files changed, 192 insertions(+), 59 deletions(-) diff --git a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseColumn.java b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseColumn.java index d63d0d3af..340116063 100644 --- a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseColumn.java +++ b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseColumn.java @@ -29,8 +29,10 @@ public final class ClickHouseColumn implements Serializable { private static final String KEYWORD_MAP = ClickHouseDataType.Map.name(); private static final String KEYWORD_NESTED = ClickHouseDataType.Nested.name(); - private String originalTypeName; + private int columnCount; + private int columnIndex; private String columnName; + private String originalTypeName; private ClickHouseAggregateFunction aggFuncType; private ClickHouseDataType dataType; @@ -449,6 +451,8 @@ private ClickHouseColumn(ClickHouseDataType dataType, String columnName, String this.aggFuncType = null; this.dataType = ClickHouseChecker.nonNull(dataType, "dataType"); + this.columnCount = 1; + this.columnIndex = 0; this.columnName = columnName == null ? "" : columnName; this.originalTypeName = originalTypeName == null ? dataType.name() : originalTypeName; this.nullable = nullable; @@ -474,8 +478,18 @@ private ClickHouseColumn(ClickHouseDataType dataType, String columnName, String this.estimatedByteLength = 0; } + /** + * Sets zero-based column index and column count. + * + * @param index zero-based column index, negative number is treated as zero + * @param count column count, should be always greater than one + */ + protected void setColumnIndex(int index, int count) { + this.columnCount = count < 2 ? 1 : count; + this.columnIndex = index < 1 ? 0 : (index < count ? index : count - 1); + } + public boolean isAggregateFunction() { - // || dataType == ClickHouseDataType.SimpleAggregateFunction; return dataType == ClickHouseDataType.AggregateFunction; } @@ -533,14 +547,30 @@ public int getEstimatedLength() { return estimatedByteLength; } - public String getOriginalTypeName() { - return originalTypeName; + public int getColumnCount() { + return columnCount; + } + + public int getColumnIndex() { + return columnIndex; } public String getColumnName() { return columnName; } + public String getOriginalTypeName() { + return originalTypeName; + } + + public boolean isFirstColumn() { + return columnCount == 0; + } + + public boolean isLastColumn() { + return columnCount - columnIndex == 1; + } + public boolean isNullable() { return nullable; } @@ -616,12 +646,14 @@ public int hashCode() { result = prime * result + ((arrayBaseColumn == null) ? 0 : arrayBaseColumn.hashCode()); result = prime * result + ((aggFuncType == null) ? 0 : aggFuncType.hashCode()); result = prime * result + arrayLevel; + result = prime * result + columnCount; + result = prime * result + columnIndex; result = prime * result + ((columnName == null) ? 0 : columnName.hashCode()); + result = prime * result + ((originalTypeName == null) ? 0 : originalTypeName.hashCode()); result = prime * result + ((dataType == null) ? 0 : dataType.hashCode()); result = prime * result + (lowCardinality ? 1231 : 1237); result = prime * result + ((nested == null) ? 0 : nested.hashCode()); result = prime * result + (nullable ? 1231 : 1237); - result = prime * result + ((originalTypeName == null) ? 0 : originalTypeName.hashCode()); result = prime * result + ((parameters == null) ? 0 : parameters.hashCode()); result = prime * result + precision; result = prime * result + scale; @@ -643,7 +675,8 @@ public boolean equals(Object obj) { ClickHouseColumn other = (ClickHouseColumn) obj; return Objects.equals(arrayBaseColumn, other.arrayBaseColumn) && aggFuncType == other.aggFuncType - && arrayLevel == other.arrayLevel && Objects.equals(columnName, other.columnName) + && arrayLevel == other.arrayLevel && columnCount == other.columnCount + && columnIndex == other.columnIndex && Objects.equals(columnName, other.columnName) && dataType == other.dataType && lowCardinality == other.lowCardinality && Objects.equals(nested, other.nested) && nullable == other.nullable && Objects.equals(originalTypeName, other.originalTypeName) @@ -654,7 +687,12 @@ public boolean equals(Object obj) { @Override public String toString() { - return new StringBuilder().append(columnName == null || columnName.isEmpty() ? "column" : columnName) - .append(' ').append(originalTypeName).toString(); + StringBuilder builder = new StringBuilder(); + if (columnName == null || columnName.isEmpty()) { + builder.append("column").append(columnIndex); + } else { + builder.append(columnName); + } + return builder.append(' ').append(originalTypeName).toString(); } } diff --git a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseCompression.java b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseCompression.java index bd53192af..096f9c043 100644 --- a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseCompression.java +++ b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseCompression.java @@ -4,9 +4,15 @@ * Supported compression algoritms. */ public enum ClickHouseCompression { - NONE("", "", ""), BROTLI("application/x-brotli", "br", "br"), DEFLATE("application/deflate", "deflate", "zz"), - GZIP("application/gzip", "gzip", "gz"), LZ4("application/x-lz4", "lz4", "lz4"), - ZIP("application/zip", "zip", "zip"), ZSTD("application/zstd", "zstd", "zst"); + NONE("", "", ""), + BROTLI("application/x-brotli", "br", "br"), + BZ2("application/x-bzip2", "bz2", "bz2"), + DEFLATE("application/deflate", "deflate", "zz"), + GZIP("application/gzip", "gzip", "gz"), + LZMA("application/x-lzma", "lzma", "xz"), + LZ4("application/x-lz4", "lz4", "lz4"), + ZIP("application/zip", "zip", "zip"), + ZSTD("application/zstd", "zstd", "zst"); private String mimeType; private String encoding; @@ -82,8 +88,8 @@ public static ClickHouseCompression fromEncoding(String encoding) { public static ClickHouseCompression fromFileName(String file) { ClickHouseCompression compression = NONE; - int index = file == null ? -1 : file.lastIndexOf('.'); - if (index > 0) { + int index = 0; + if (file != null && (index = file.lastIndexOf('.')) > 0) { String ext = file.substring(index + 1).toLowerCase(); for (ClickHouseCompression c : values()) { if (c.fileExt.equals(ext)) { diff --git a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseFormat.java b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseFormat.java index c8c20eb2e..4a8eca651 100644 --- a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseFormat.java +++ b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseFormat.java @@ -5,91 +5,168 @@ * https://clickhouse.com/docs/en/interfaces/formats/. */ public enum ClickHouseFormat { + // start with the most common ones + RowBinary(true, true, true, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#rowbinary + RowBinaryWithNamesAndTypes(true, true, true, true, true, RowBinary), // https://clickhouse.com/docs/en/interfaces/formats/#rowbinarywithnamesandtypes + TabSeparated(true, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#tabseparated + TabSeparatedRaw(true, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#tabseparatedraw + TabSeparatedWithNames(true, true, false, true, true, TabSeparated), // https://clickhouse.com/docs/en/interfaces/formats/#tabseparatedwithnames + TabSeparatedWithNamesAndTypes(true, true, false, true, true, TabSeparated), // https://clickhouse.com/docs/en/interfaces/formats/#tabseparatedwithnamesandtypes + // and the rest Arrow(true, true, true, true, false), // https://clickhouse.com/docs/en/interfaces/formats/#arrow ArrowStream(true, true, true, true, false), // https://clickhouse.com/docs/en/interfaces/formats/#arrowstream Avro(true, true, true, true, false), // https://clickhouse.com/docs/en/interfaces/formats/#avro AvroConfluent(true, false, true, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#avroconfluent CSV(true, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#csv - CSVWithNames(true, true, false, true, true), // https://clickhouse.com/docs/en/interfaces/formats/#csvwithnames + CSVWithNames(true, true, false, true, true, CSV), // https://clickhouse.com/docs/en/interfaces/formats/#csvwithnames CapnProto(true, false, true, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#capnproto CustomSeparated(true, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#customseparated - CustomSeparatedIgnoreSpaces(true, true, false, false, true), JSON(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#json - JSONAsString(true, false, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#jsonasstring - JSONCompact(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#jsoncompact + CustomSeparatedIgnoreSpaces(true, true, false, false, true), JSONCompactEachRow(true, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#jsoncompacteachrow JSONCompactEachRowWithNamesAndTypes(true, true, false, true, true), // https://clickhouse.com/docs/en/interfaces/formats/#jsoncompacteachrowwithnamesandtypes - JSONCompactStrings(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#jsoncompactstrings + JSON(false, true, false, false, false, JSONCompactEachRow), // https://clickhouse.com/docs/en/interfaces/formats/#json + JSONAsString(true, false, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#jsonasstring + JSONCompact(false, true, false, false, false, JSONCompactEachRow), // https://clickhouse.com/docs/en/interfaces/formats/#jsoncompact JSONCompactStringsEachRow(true, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#jsoncompactstringeachrow - JSONCompactStringsEachRowWithNamesAndTypes(true, true, false, true, true), // https://clickhouse.com/docs/en/interfaces/formats/#jsoncompactstringeachrowwithnamesandtypes + JSONCompactStringsEachRowWithNamesAndTypes(true, true, false, true, true, JSONCompactStringsEachRow), // https://clickhouse.com/docs/en/interfaces/formats/#jsoncompactstringeachrowwithnamesandtypes + JSONCompactStrings(false, true, false, false, false, JSONCompactStringsEachRow), // https://clickhouse.com/docs/en/interfaces/formats/#jsoncompactstrings JSONEachRow(true, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#jsoneachrow - JSONEachRowWithProgress(false, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#jsoneachrowwithprogress - JSONStringEachRow(false, false, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#jsoneachrow - JSONStrings(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#jsonstring + JSONEachRowWithProgress(false, true, false, false, true, JSONEachRow), // https://clickhouse.com/docs/en/interfaces/formats/#jsoneachrowwithprogress JSONStringsEachRow(true, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#jsonstringseachrow - JSONStringsEachRowWithProgress(false, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#jsonstringseachrowwithprogress + JSONStringsEachRowWithProgress(false, true, false, false, true, JSONStringsEachRow), // https://clickhouse.com/docs/en/interfaces/formats/#jsonstringseachrowwithprogress + JSONStringEachRow(false, false, false, false, true, JSONStringsEachRow), // https://clickhouse.com/docs/en/interfaces/formats/#jsoneachrow + JSONStrings(false, true, false, false, false, JSONStringsEachRow), // https://clickhouse.com/docs/en/interfaces/formats/#jsonstring LineAsString(true, false, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#lineasstring Markdown(false, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#lineasstring MsgPack(true, true, true, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#msgpack - MySQLWire(false, true, true, false, false), Native(true, true, true, true, false), // https://clickhouse.com/docs/en/interfaces/formats/#native + MySQLWire(false, true, true, false, false), + Native(true, true, true, true, false), // https://clickhouse.com/docs/en/interfaces/formats/#native Null(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#null - ODBCDriver2(false, true, true, false, false), ORC(true, false, true, true, false), // https://clickhouse.com/docs/en/interfaces/formats/#orc + ODBCDriver2(false, true, true, false, false), + ORC(true, false, true, true, false), // https://clickhouse.com/docs/en/interfaces/formats/#orc Parquet(true, true, true, true, false), // https://clickhouse.com/docs/en/interfaces/formats/#parquet - PostgreSQLWire(false, true, true, false, false), Pretty(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#pretty + PostgreSQLWire(false, true, true, false, false), + Pretty(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#pretty PrettyCompact(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#prettycompact PrettyCompactMonoBlock(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#prettycompactmonoblock - PrettyCompactNoEscapes(false, true, false, false, false), PrettyNoEscapes(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#prettynoescapes + PrettyCompactNoEscapes(false, true, false, false, false), + PrettyNoEscapes(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#prettynoescapes PrettySpace(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#prettyspace - PrettySpaceNoEscapes(false, true, false, false, false), Protobuf(true, true, true, true, false), // https://clickhouse.com/docs/en/interfaces/formats/#protobuf + PrettySpaceNoEscapes(false, true, false, false, false), + Protobuf(true, true, true, true, false), // https://clickhouse.com/docs/en/interfaces/formats/#protobuf ProtobufSingle(true, true, true, true, false), // https://clickhouse.com/docs/en/interfaces/formats/#protobufsingle RawBLOB(true, true, true, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#rawblob Regexp(true, false, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#regexp - RowBinary(true, true, true, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#rowbinary - RowBinaryWithNamesAndTypes(true, true, true, true, true), // https://clickhouse.com/docs/en/interfaces/formats/#rowbinarywithnamesandtypes TSKV(true, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#tskv TSV(true, true, false, false, true), // alias of TabSeparated TSVRaw(true, true, false, false, true), // alias of TabSeparatedRaw - TSVWithNames(true, true, false, true, true), // alias of TabSeparatedWithNames - TSVWithNamesAndTypes(true, true, false, true, true), // alias of TabSeparatedWithNamesAndTypes - TabSeparated(true, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#tabseparated - TabSeparatedRaw(true, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#tabseparatedraw - TabSeparatedWithNames(true, true, false, true, true), // https://clickhouse.com/docs/en/interfaces/formats/#tabseparatedwithnames - TabSeparatedWithNamesAndTypes(true, true, false, true, true), // https://clickhouse.com/docs/en/interfaces/formats/#tabseparatedwithnamesandtypes + TSVWithNames(true, true, false, true, true, TSV), // alias of TabSeparatedWithNames + TSVWithNamesAndTypes(true, true, false, true, true, TSV), // alias of TabSeparatedWithNamesAndTypes Template(true, true, false, true, true), // https://clickhouse.com/docs/en/interfaces/formats/#template TemplateIgnoreSpaces(true, false, false, true, true), // https://clickhouse.com/docs/en/interfaces/formats/#templateignorespaces Values(true, true, false, false, true), // https://clickhouse.com/docs/en/interfaces/formats/#values Vertical(false, true, false, false, false), // https://clickhouse.com/docs/en/interfaces/formats/#vertical XML(false, true, false, false, false); // https://clickhouse.com/docs/en/interfaces/formats/#xml - private boolean input; - private boolean output; - private boolean binary; - private boolean header; - private boolean rowBased; + private final boolean input; + private final boolean output; + private final boolean binary; + private final boolean header; + private final boolean rowBased; + private final ClickHouseFormat defaultInput; + + /** + * Simplified constructor. Same as + * {@code new ClickHouseFormat(input, output, binary, header, rowBased, null)}. + * + * @param input whether the format can be used for input + * @param output whether the format can be used for output + * @param binary whether the format is binary-based + * @param header whether the format contains header like names and/or + * types + * @param rowBased whether the format is row-based + */ ClickHouseFormat(boolean input, boolean output, boolean binary, boolean header, boolean rowBased) { + this(input, output, binary, header, rowBased, null); + } + + /** + * Default constructor. + * + * @param input whether the format can be used for input + * @param output whether the format can be used for output + * @param binary whether the format is binary-based + * @param header whether the format contains header like names + * and/or types + * @param rowBased whether the format is row-based + * @param defaultInputFormat default format can be used for input, null means + * one of the current format, RowBinary or + * TabSeparated + */ + ClickHouseFormat(boolean input, boolean output, boolean binary, boolean header, boolean rowBased, + ClickHouseFormat defaultInputFormat) { this.input = input; this.output = output; this.binary = binary; this.header = output && header; this.rowBased = rowBased; + + if (defaultInputFormat != null) { + defaultInput = defaultInputFormat; + } else if (input) { + defaultInput = this; + } else { + String typeName = binary ? "RowBinary" : "TabSeparated"; + try { + defaultInput = (ClickHouseFormat) getClass().getField(typeName).get(null); + } catch (Exception e) { + throw new IllegalArgumentException("Failed to initialize format", e); + } + } } + /** + * Checks if the format can be used for input. + * + * @return true if the format can be used for input; false otherwise + */ public boolean supportsInput() { return input; } + /** + * Checks if the format can be used for output. + * + * @return true if the format can be used for output; false otherwise + */ public boolean supportsOutput() { return output; } + /** + * Checks if the format is binary-based or not. + * + * @return true if the format is binary-based; false otherwise + */ public boolean isBinary() { return binary; } + /** + * Checks if the format is text-based or not. + * + * @return true if the format is text-based; false otherwise + */ public boolean isText() { return !binary; } + /** + * Checks if the format contains header like names and/or types. + * + * @return true if the format contains header; false otherwise + */ public boolean hasHeader() { return header; } @@ -104,4 +181,13 @@ public boolean hasHeader() { public boolean isRowBased() { return rowBased; } + + /** + * Gets default input format, which usually does not has header. + * + * @return non-null input format + */ + public ClickHouseFormat defaultInputFormat() { + return defaultInput; + } } diff --git a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseProtocol.java b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseProtocol.java index 70b69d187..e448729cd 100644 --- a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseProtocol.java +++ b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseProtocol.java @@ -15,11 +15,11 @@ public enum ClickHouseProtocol { /** * HTTP/HTTPS interface. */ - HTTP(8123, "http", "https"), + HTTP(8123, 8443, "http", "https"), /** * Native interface. */ - TCP(9000, "native", "tcp"), + TCP(9000, 9440, "native", "tcp"), /** * MySQL interface. */ @@ -59,10 +59,16 @@ public static ClickHouseProtocol fromUriScheme(String scheme) { } private final int defaultPort; + private final int defaultSecurePort; private final List schemes; ClickHouseProtocol(int defaultPort, String... schemes) { + this(defaultPort, defaultPort, schemes); + } + + ClickHouseProtocol(int defaultPort, int defaultSecurePort, String... schemes) { this.defaultPort = defaultPort; + this.defaultSecurePort = defaultSecurePort; int len = schemes != null ? schemes.length : 0; if (len > 0) { @@ -87,6 +93,15 @@ public int getDefaultPort() { return this.defaultPort; } + /** + * Get default secure port used by the protocol. + * + * @return default secure port used by the protocol + */ + public int getDefaultSecurePort() { + return this.defaultSecurePort; + } + /** * Gets supported URI schemes. * diff --git a/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDataSource.java b/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDataSource.java index 956311a33..be231c40e 100644 --- a/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDataSource.java +++ b/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDataSource.java @@ -2,15 +2,12 @@ import javax.sql.DataSource; -import com.clickhouse.client.ClickHouseNode; import com.clickhouse.client.config.ClickHouseDefaults; import com.clickhouse.jdbc.internal.ClickHouseConnectionImpl; import com.clickhouse.jdbc.internal.ClickHouseJdbcUrlParser; import com.clickhouse.jdbc.internal.ClickHouseJdbcUrlParser.ConnectionInfo; import java.io.PrintWriter; -import java.net.URI; -import java.net.URISyntaxException; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.util.Properties; @@ -73,14 +70,6 @@ public String getDatabase() { .orElse((String) ClickHouseDefaults.DATABASE.getEffectiveDefaultValue()); } - // public String getUrl() { - // return url; - // } - - // public Properties getProperties() { - // return connInfo.getProperties(); - // } - @Override public PrintWriter getLogWriter() throws SQLException { return printWriter; diff --git a/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaData.java b/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaData.java index 87e052edb..0413228b9 100644 --- a/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaData.java +++ b/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaData.java @@ -6,8 +6,6 @@ import java.sql.RowIdLifetime; import java.sql.SQLException; import java.sql.Types; -import java.time.LocalDate; -import java.time.LocalDateTime; import java.time.temporal.Temporal; import java.util.ArrayList; import java.util.Collections; diff --git a/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java b/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java index d0e057c44..ebef724bc 100644 --- a/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java +++ b/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java @@ -155,10 +155,10 @@ protected void ensureSupport(String feature, boolean silent) throws SQLException if (jdbcConf.isJdbcCompliant()) { if (silent) { - log.debug("[JDBC Compliant Mode] %s. Change %s to false to throw SQLException instead.", msg, + log.debug("[JDBC Compliant Mode] %s. You may change %s to false to throw SQLException instead.", msg, JdbcConfig.PROP_JDBC_COMPLIANT); } else { - log.warn("[JDBC Compliant Mode] %s. Change %s to false to throw SQLException instead.", msg, + log.warn("[JDBC Compliant Mode] %s. You may change %s to false to throw SQLException instead.", msg, JdbcConfig.PROP_JDBC_COMPLIANT); } } else if (!silent) { @@ -188,7 +188,8 @@ protected List getTableColumns(String dbName, String tableName } builder.append('`').append(ClickHouseUtils.escape(tableName, '`')).append('`').append(" WHERE 0"); List list; - try (ClickHouseResponse resp = clientRequest.copy().query(builder.toString()).execute().get()) { + try (ClickHouseResponse resp = clientRequest.copy().format(ClickHouseFormat.RowBinaryWithNamesAndTypes) + .query(builder.toString()).execute().get()) { list = resp.getColumns(); } catch (InterruptedException e) { Thread.currentThread().interrupt();