{
Writer(ClickHouseStatementImpl statement) {
super(statement);
+
+ dataCompression(ClickHouseCompression.none);
}
/**
- * Specifies format for further insert of data via send()
+ * Specifies format for further insert of data via send().
+ *
+ * @param format
+ * the format of the data to upload
+ * @return this writer instance
*/
public Writer format(ClickHouseFormat format) {
if (null == format) {
@@ -39,10 +49,11 @@ public Writer format(ClickHouseFormat format) {
}
/**
- * Set table name for data insertion
+ * Set table name for data insertion.
*
- * @param table table name
- * @return this
+ * @param table
+ * name of the table to upload the data to
+ * @return this writer instance
*/
public Writer table(String table) {
this.sql = null;
@@ -51,10 +62,11 @@ public Writer table(String table) {
}
/**
- * Set SQL for data insertion
+ * Set SQL for data insertion.
*
- * @param sql in a form "INSERT INTO table_name [(X,Y,Z)] VALUES "
- * @return this
+ * @param sql
+ * in a form "INSERT INTO table_name [(X,Y,Z)] VALUES "
+ * @return this writer instance
*/
public Writer sql(String sql) {
this.sql = sql;
@@ -63,19 +75,36 @@ public Writer sql(String sql) {
}
/**
- * Specifies data input stream
+ * Specifies data input stream.
+ *
+ * @param stream
+ * a stream providing the data to upload
+ * @return this writer instance
*/
public Writer data(InputStream stream) {
streamProvider = new HoldingInputProvider(stream);
return this;
}
+ /**
+ * Specifies data input stream, and the format to use.
+ *
+ * @param stream
+ * a stream providing the data to upload
+ * @param format
+ * the format of the data to upload
+ * @return this writer instance
+ */
public Writer data(InputStream stream, ClickHouseFormat format) {
return format(format).data(stream);
}
/**
- * Shortcut method for specifying a file as an input
+ * Shortcut method for specifying a file as an input.
+ *
+ * @param input
+ * the file to upload
+ * @return this writer instance
*/
public Writer data(File input) {
streamProvider = new FileInputProvider(input);
@@ -91,10 +120,9 @@ public Writer data(File input, ClickHouseFormat format, ClickHouseCompression co
}
public Writer dataCompression(ClickHouseCompression compression) {
- if (null == compression) {
- throw new NullPointerException("Compression can not be null");
- }
- this.compression = compression;
+ this.compression = Objects.requireNonNull(compression, "Compression can not be null");
+ this.addDbParam(ClickHouseQueryParam.COMPRESS, String.valueOf(compression != ClickHouseCompression.none));
+
return this;
}
@@ -103,7 +131,7 @@ public Writer data(File input, ClickHouseFormat format) {
}
/**
- * Method to call, when Writer is fully configured
+ * Method to call, when Writer is fully configured.
*/
public void send() throws SQLException {
HttpEntity entity;
@@ -124,31 +152,50 @@ private void send(HttpEntity entity) throws SQLException {
}
/**
- * Allows to send stream of data to ClickHouse
+ * Allows to send stream of data to ClickHouse.
*
- * @param sql in a form of "INSERT INTO table_name (X,Y,Z) VALUES "
- * @param data where to read data from
- * @param format format of data in InputStream
+ * @param sql
+ * in a form of "INSERT INTO table_name (X,Y,Z) VALUES "
+ * @param data
+ * where to read data from
+ * @param format
+ * format of data in InputStream
* @throws SQLException
+ * if the upload fails
*/
public void send(String sql, InputStream data, ClickHouseFormat format) throws SQLException {
sql(sql).data(data).format(format).send();
}
/**
- * Convenient method for importing the data into table
+ * Convenient method for importing the data into table.
*
- * @param table table name
- * @param data source data
- * @param format format of data in InputStream
+ * @param table
+ * table name
+ * @param data
+ * source data
+ * @param format
+ * format of data in InputStream
* @throws SQLException
+ * if the upload fails
*/
public void sendToTable(String table, InputStream data, ClickHouseFormat format) throws SQLException {
table(table).data(data).format(format).send();
}
/**
- * Sends the data in RowBinary or in Native formats
+ * Sends the data in {@link ClickHouseFormat#RowBinary RowBinary} or in
+ * {@link ClickHouseFormat#Native Native} format.
+ *
+ * @param sql
+ * the SQL statement to execute
+ * @param callback
+ * data source for the upload
+ * @param format
+ * the format to use, either {@link ClickHouseFormat#RowBinary
+ * RowBinary} or {@link ClickHouseFormat#Native Native}
+ * @throws SQLException
+ * if the upload fails
*/
public void send(String sql, ClickHouseStreamCallback callback, ClickHouseFormat format) throws SQLException {
if (!(RowBinary.equals(format) || Native.equals(format))) {
diff --git a/src/main/java/ru/yandex/clickhouse/domain/ClickHouseCompression.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/domain/ClickHouseCompression.java
similarity index 100%
rename from src/main/java/ru/yandex/clickhouse/domain/ClickHouseCompression.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/domain/ClickHouseCompression.java
diff --git a/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/domain/ClickHouseDataType.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/domain/ClickHouseDataType.java
new file mode 100644
index 000000000..182120b90
--- /dev/null
+++ b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/domain/ClickHouseDataType.java
@@ -0,0 +1,178 @@
+package ru.yandex.clickhouse.domain;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Array;
+import java.sql.Date;
+import java.sql.JDBCType;
+import java.sql.Timestamp;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Basic ClickHouse data types.
+ *
+ * This list is based on the list of data type families returned by
+ * {@code SELECT * FROM system.data_type_families}
+ *
+ * {@code LowCardinality} and {@code Nullable} are technically data types in
+ * ClickHouse, but for the sake of this driver, we treat these data types as
+ * modifiers for the underlying base data types.
+ */
+public enum ClickHouseDataType {
+ // aliases:
+ // https://clickhouse.tech/docs/en/sql-reference/data-types/multiword-types/
+ // https://github.com/ClickHouse/ClickHouse/blob/master/src/DataTypes/DataTypeCustomIPv4AndIPv6.cpp
+ // https://github.com/ClickHouse/ClickHouse/blob/master/src/DataTypes/registerDataTypeDateTime.cpp
+ // https://github.com/ClickHouse/ClickHouse/blob/master/src/DataTypes/DataTypesDecimal.cpp
+ // https://github.com/ClickHouse/ClickHouse/blob/master/src/DataTypes/DataTypeFixedString.cpp
+ // https://github.com/ClickHouse/ClickHouse/blob/master/src/DataTypes/DataTypesNumber.cpp
+ // https://github.com/ClickHouse/ClickHouse/blob/master/src/DataTypes/DataTypeString.cpp
+ IntervalYear (JDBCType.INTEGER, Integer.class, true, 19, 0),
+ IntervalQuarter (JDBCType.INTEGER, Integer.class, true, 19, 0),
+ IntervalMonth (JDBCType.INTEGER, Integer.class, true, 19, 0),
+ IntervalWeek (JDBCType.INTEGER, Integer.class, true, 19, 0),
+ IntervalDay (JDBCType.INTEGER, Integer.class, true, 19, 0),
+ IntervalHour (JDBCType.INTEGER, Integer.class, true, 19, 0),
+ IntervalMinute (JDBCType.INTEGER, Integer.class, true, 19, 0),
+ IntervalSecond (JDBCType.INTEGER, Integer.class, true, 19, 0),
+ UInt256 (JDBCType.NUMERIC, BigInteger.class, true, 39, 0),
+ UInt128 (JDBCType.NUMERIC, BigInteger.class, true, 20, 0),
+ UInt64 (JDBCType.BIGINT, BigInteger.class, false, 19, 0,
+ "BIGINT UNSIGNED"),
+ UInt32 (JDBCType.BIGINT, Long.class, false, 10, 0,
+ "INT UNSIGNED", "INTEGER UNSIGNED", "MEDIUMINT UNSIGNED"),
+ UInt16 (JDBCType.SMALLINT, Integer.class, false, 5, 0,
+ "SMALLINT UNSIGNED"),
+ UInt8 (JDBCType.TINYINT, Integer.class, false, 3, 0,
+ "TINYINT UNSIGNED", "INT1 UNSIGNED"),
+ Int256 (JDBCType.NUMERIC, BigInteger.class, true, 40, 0),
+ Int128 (JDBCType.NUMERIC, BigInteger.class, true, 20, 0),
+ Int64 (JDBCType.BIGINT, Long.class, true, 20, 0,
+ "BIGINT", "BIGINT SIGNED"),
+ Int32 (JDBCType.INTEGER, Integer.class, true, 11, 0,
+ "INT", "INTEGER", "MEDIUMINT", "INT SIGNED", "INTEGER SIGNED", "MEDIUMINT SIGNED"),
+ Int16 (JDBCType.SMALLINT, Integer.class, true, 6, 0,
+ "SMALLINT", "SMALLINT SIGNED"),
+ Int8 (JDBCType.TINYINT, Integer.class, true, 4, 0,
+ "TINYINT", "BOOL", "BOOLEAN", "INT1", "BYTE", "TINYINT SIGNED", "INT1 SIGNED"),
+ Date (JDBCType.DATE, Date.class, false, 10, 0),
+ DateTime (JDBCType.TIMESTAMP, Timestamp.class, false, 19, 0,
+ "TIMESTAMP"),
+ DateTime32 (JDBCType.TIMESTAMP, Timestamp.class, false, 19, 0),
+ DateTime64 (JDBCType.TIMESTAMP, Timestamp.class, false, 38, 3), // scale up to 18
+ Enum8 (JDBCType.VARCHAR, String.class, false, 0, 0,
+ "ENUM"),
+ Enum16 (JDBCType.VARCHAR, String.class, false, 0, 0),
+ Float32 (JDBCType.REAL, Float.class, true, 8, 8,
+ "SINGLE", "REAL"),
+ Float64 (JDBCType.DOUBLE, Double.class, true, 17, 17,
+ "DOUBLE", "DOUBLE PRECISION"),
+ Decimal32 (JDBCType.DECIMAL, BigDecimal.class, true, 9, 9),
+ Decimal64 (JDBCType.DECIMAL, BigDecimal.class, true, 18, 18),
+ Decimal128 (JDBCType.DECIMAL, BigDecimal.class, true, 38, 38),
+ Decimal256 (JDBCType.DECIMAL, BigDecimal.class, true, 76, 20),
+ Decimal (JDBCType.DECIMAL, BigDecimal.class, true, 0, 0,
+ "DEC", "NUMERIC", "FIXED"),
+ UUID (JDBCType.OTHER, UUID.class, false, 36, 0),
+ IPv4 (JDBCType.VARCHAR, String.class, false, 10, 0),
+ IPv6 (JDBCType.VARCHAR, String.class, false, 0, 0),
+ String (JDBCType.VARCHAR, String.class, false, 0, 0,
+ "CHAR", "NCHAR", "CHARACTER", "VARCHAR", "NVARCHAR", "VARCHAR2",
+ "TEXT", "TINYTEXT", "MEDIUMTEXT", "LONGTEXT",
+ "BLOB", "CLOB", "TINYBLOB", "MEDIUMBLOB", "LONGBLOB", "BYTEA",
+ "CHARACTER LARGE OBJECT", "CHARACTER VARYING", "CHAR LARGE OBJECT", "CHAR VARYING",
+ "NATIONAL CHAR", "NATIONAL CHARACTER", "NATIONAL CHARACTER LARGE OBJECT",
+ "NATIONAL CHARACTER VARYING", "NATIONAL CHAR VARYING",
+ "NCHAR VARYING", "NCHAR LARGE OBJECT", "BINARY LARGE OBJECT", "BINARY VARYING"),
+ FixedString (JDBCType.CHAR, String.class, false, -1, 0,
+ "BINARY"),
+ Nothing (JDBCType.NULL, Object.class, false, 0, 0),
+ Nested (JDBCType.STRUCT, String.class, false, 0, 0),
+ // TODO use list/collection for Tuple
+ Tuple (JDBCType.OTHER, String.class, false, 0, 0),
+ Array (JDBCType.ARRAY, Array.class, false, 0, 0),
+ Map (JDBCType.OTHER, Map.class, false, 0, 0),
+ AggregateFunction (JDBCType.OTHER, String.class, false, 0, 0),
+ Unknown (JDBCType.OTHER, String.class, false, 0, 0);
+
+ private static final Map name2type;
+
+ static {
+ Map map = new HashMap<>();
+ String errorMsg = "[%s] is used by type [%s]";
+ ClickHouseDataType used = null;
+ for (ClickHouseDataType t : ClickHouseDataType.values()) {
+ used = map.put(t.name(), t);
+ if (used != null) {
+ throw new IllegalStateException(java.lang.String.format(errorMsg, t.name(), used.name()));
+ }
+ String nameInUpperCase = t.name().toUpperCase();
+ if (!nameInUpperCase.equals(t.name())) {
+ used = map.put(nameInUpperCase, t);
+ if (used != null) {
+ throw new IllegalStateException(java.lang.String.format(errorMsg, nameInUpperCase, used.name()));
+ }
+ }
+ for (String alias: t.aliases) {
+ used = map.put(alias.toUpperCase(), t);
+ if (used != null) {
+ throw new IllegalStateException(java.lang.String.format(errorMsg, alias, used.name()));
+ }
+ }
+ }
+ name2type = Collections.unmodifiableMap(map);
+ }
+
+ private final JDBCType jdbcType;
+ private final Class> javaClass;
+ private final boolean signed;
+ private final int defaultPrecision;
+ private final int defaultScale;
+ private final String[] aliases;
+
+ ClickHouseDataType(JDBCType jdbcType, Class> javaClass,
+ boolean signed, int defaultPrecision, int defaultScale,
+ String... aliases) {
+ this.jdbcType = jdbcType;
+ this.javaClass = javaClass;
+ this.signed = signed;
+ this.defaultPrecision = defaultPrecision;
+ this.defaultScale = defaultScale;
+ this.aliases = aliases;
+ }
+
+ public int getSqlType() {
+ return jdbcType.getVendorTypeNumber().intValue();
+ }
+
+ public JDBCType getJdbcType() {
+ return jdbcType;
+ }
+
+ public Class> getJavaClass() {
+ return javaClass;
+ }
+
+ public boolean isSigned() {
+ return signed;
+ }
+
+ public int getDefaultPrecision() {
+ return defaultPrecision;
+ }
+
+ public int getDefaultScale() {
+ return defaultScale;
+ }
+
+ public static ClickHouseDataType fromTypeString(String typeString) {
+ return name2type.getOrDefault(typeString.trim().toUpperCase(), ClickHouseDataType.Unknown);
+ }
+
+ public static ClickHouseDataType resolveDefaultArrayDataType(String typeName) {
+ return name2type.getOrDefault(typeName, ClickHouseDataType.String);
+ }
+}
diff --git a/src/main/java/ru/yandex/clickhouse/domain/ClickHouseFormat.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/domain/ClickHouseFormat.java
similarity index 93%
rename from src/main/java/ru/yandex/clickhouse/domain/ClickHouseFormat.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/domain/ClickHouseFormat.java
index ef8614cb2..a230d1a89 100644
--- a/src/main/java/ru/yandex/clickhouse/domain/ClickHouseFormat.java
+++ b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/domain/ClickHouseFormat.java
@@ -24,7 +24,11 @@ public enum ClickHouseFormat {
Vertical,
JSON,
JSONCompact,
+ JSONCompactString,
JSONEachRow,
+ JSONStringEachRow,
+ JSONCompactEachRow,
+ JSONCompactStringEachRow,
TSKV,
TSV,
Pretty,
diff --git a/src/main/java/ru/yandex/clickhouse/except/ClickHouseErrorCode.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/except/ClickHouseErrorCode.java
similarity index 100%
rename from src/main/java/ru/yandex/clickhouse/except/ClickHouseErrorCode.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/except/ClickHouseErrorCode.java
diff --git a/src/main/java/ru/yandex/clickhouse/except/ClickHouseException.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/except/ClickHouseException.java
similarity index 74%
rename from src/main/java/ru/yandex/clickhouse/except/ClickHouseException.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/except/ClickHouseException.java
index 37d020855..570da79cb 100644
--- a/src/main/java/ru/yandex/clickhouse/except/ClickHouseException.java
+++ b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/except/ClickHouseException.java
@@ -13,4 +13,10 @@ public ClickHouseException(int code, String message, Throwable cause, String hos
super("ClickHouse exception, message: " + message + ", host: " + host + ", port: " + port + "; "
+ (cause == null ? "" : cause.getMessage()), null, code, cause);
}
+
+ public ClickHouseException(int code, String message, Throwable cause) {
+ super("ClickHouse exception, message: " + message + "; "
+ + (cause == null ? "" : cause.getMessage()), null, code, cause);
+ }
+
}
diff --git a/src/main/java/ru/yandex/clickhouse/except/ClickHouseExceptionSpecifier.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/except/ClickHouseExceptionSpecifier.java
similarity index 96%
rename from src/main/java/ru/yandex/clickhouse/except/ClickHouseExceptionSpecifier.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/except/ClickHouseExceptionSpecifier.java
index 53f3b87cc..c4bbe0848 100644
--- a/src/main/java/ru/yandex/clickhouse/except/ClickHouseExceptionSpecifier.java
+++ b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/except/ClickHouseExceptionSpecifier.java
@@ -1,10 +1,11 @@
package ru.yandex.clickhouse.except;
-import com.google.common.base.Strings;
import org.apache.http.conn.ConnectTimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import ru.yandex.clickhouse.util.Utils;
+
import java.net.ConnectException;
import java.net.SocketTimeoutException;
@@ -37,7 +38,7 @@ public static ClickHouseException specify(String clickHouseMessage) {
* "Code: 10, e.displayText() = DB::Exception: ...".
*/
private static ClickHouseException specify(String clickHouseMessage, Throwable cause, String host, int port) {
- if (Strings.isNullOrEmpty(clickHouseMessage) && cause != null) {
+ if (Utils.isNullOrEmptyString(clickHouseMessage) && cause != null) {
return getException(cause, host, port);
}
diff --git a/src/main/java/ru/yandex/clickhouse/except/ClickHouseUnknownException.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/except/ClickHouseUnknownException.java
similarity index 79%
rename from src/main/java/ru/yandex/clickhouse/except/ClickHouseUnknownException.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/except/ClickHouseUnknownException.java
index d2c295a19..e1bd79708 100644
--- a/src/main/java/ru/yandex/clickhouse/except/ClickHouseUnknownException.java
+++ b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/except/ClickHouseUnknownException.java
@@ -11,6 +11,10 @@ public ClickHouseUnknownException(String message, Throwable cause, String host,
super(ClickHouseErrorCode.UNKNOWN_EXCEPTION.code, message, cause, host, port);
}
+ public ClickHouseUnknownException(String message, Throwable cause) {
+ super(ClickHouseErrorCode.UNKNOWN_EXCEPTION.code, message, cause);
+ }
+
public ClickHouseUnknownException(Integer code, Throwable cause, String host, int port) {
super(code, cause, host, port);
}
diff --git a/src/main/java/ru/yandex/clickhouse/jdbc/parser/ClickHouseSqlStatement.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/jdbc/parser/ClickHouseSqlStatement.java
similarity index 100%
rename from src/main/java/ru/yandex/clickhouse/jdbc/parser/ClickHouseSqlStatement.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/jdbc/parser/ClickHouseSqlStatement.java
diff --git a/src/main/java/ru/yandex/clickhouse/jdbc/parser/ClickHouseSqlUtils.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/jdbc/parser/ClickHouseSqlUtils.java
similarity index 100%
rename from src/main/java/ru/yandex/clickhouse/jdbc/parser/ClickHouseSqlUtils.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/jdbc/parser/ClickHouseSqlUtils.java
diff --git a/src/main/java/ru/yandex/clickhouse/jdbc/parser/LanguageType.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/jdbc/parser/LanguageType.java
similarity index 100%
rename from src/main/java/ru/yandex/clickhouse/jdbc/parser/LanguageType.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/jdbc/parser/LanguageType.java
diff --git a/src/main/java/ru/yandex/clickhouse/jdbc/parser/OperationType.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/jdbc/parser/OperationType.java
similarity index 100%
rename from src/main/java/ru/yandex/clickhouse/jdbc/parser/OperationType.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/jdbc/parser/OperationType.java
diff --git a/src/main/java/ru/yandex/clickhouse/jdbc/parser/ParseHandler.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/jdbc/parser/ParseHandler.java
similarity index 100%
rename from src/main/java/ru/yandex/clickhouse/jdbc/parser/ParseHandler.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/jdbc/parser/ParseHandler.java
diff --git a/src/main/java/ru/yandex/clickhouse/jdbc/parser/StatementType.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/jdbc/parser/StatementType.java
similarity index 100%
rename from src/main/java/ru/yandex/clickhouse/jdbc/parser/StatementType.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/jdbc/parser/StatementType.java
diff --git a/src/main/java/ru/yandex/clickhouse/response/AbstractResultSet.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/AbstractResultSet.java
similarity index 96%
rename from src/main/java/ru/yandex/clickhouse/response/AbstractResultSet.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/AbstractResultSet.java
index 14642c959..9c44e6f6a 100644
--- a/src/main/java/ru/yandex/clickhouse/response/AbstractResultSet.java
+++ b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/AbstractResultSet.java
@@ -4,12 +4,27 @@
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
-import java.sql.*;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Map;
public abstract class AbstractResultSet implements ResultSet {
+
@Override
public boolean next() throws SQLException {
throw new UnsupportedOperationException();
@@ -952,12 +967,20 @@ public boolean isWrapperFor(Class> iface) throws SQLException {
throw new UnsupportedOperationException();
}
- public long[] getLongArray(String column) throws SQLException {
- Array array = getArray(column);
- return (long[])array.getArray(); // optimistic
- }
-
-
-
+ /**
+ * Parse the value in current row at column with label {@code column} as an array
+ * of long
+ *
+ * @param column
+ * the label, name, alias of the column
+ * @return an array of longs
+ * @throws SQLException
+ * if the value cannot be interpreted as {@code long[]}
+ * @deprecated prefer to use regular JDBC API, e.g. via
+ * {@link #getArray(int)} or simply
+ * {@link #getObject(int, Class)}
+ */
+ @Deprecated
+ public abstract long[] getLongArray(String column) throws SQLException;
}
diff --git a/src/main/java/ru/yandex/clickhouse/response/ArrayByteFragment.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/ArrayByteFragment.java
similarity index 62%
rename from src/main/java/ru/yandex/clickhouse/response/ArrayByteFragment.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/ArrayByteFragment.java
index bf7390b00..602ec42f5 100644
--- a/src/main/java/ru/yandex/clickhouse/response/ArrayByteFragment.java
+++ b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/ArrayByteFragment.java
@@ -1,12 +1,12 @@
package ru.yandex.clickhouse.response;
-class ArrayByteFragment extends ByteFragment {
+public final class ArrayByteFragment extends ByteFragment {
private ArrayByteFragment(byte[] buf, int start, int len) {
super(buf, start, len);
}
- static ArrayByteFragment wrap(ByteFragment fragment) {
+ public static ArrayByteFragment wrap(ByteFragment fragment) {
return new ArrayByteFragment(fragment.buf, fragment.start, fragment.len);
}
@@ -16,8 +16,5 @@ public boolean isNull() {
return len == 4 && buf[start] == 'N' && buf[start + 1] == 'U' && buf[start + 2] == 'L' && buf[start + 3] == 'L';
}
- public boolean isNaN() {
- // nan
- return len == 3 && buf[start] == 'n' && buf[start + 1] == 'a' && buf[start + 2] == 'n';
- }
+
}
diff --git a/src/main/java/ru/yandex/clickhouse/response/ArrayToStringDeserializer.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/ArrayToStringDeserializer.java
similarity index 56%
rename from src/main/java/ru/yandex/clickhouse/response/ArrayToStringDeserializer.java
rename to clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/ArrayToStringDeserializer.java
index 9ab7eadbb..a0dbed6f1 100644
--- a/src/main/java/ru/yandex/clickhouse/response/ArrayToStringDeserializer.java
+++ b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/response/ArrayToStringDeserializer.java
@@ -5,48 +5,41 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.type.TypeFactory;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
import ru.yandex.clickhouse.Jackson;
+import ru.yandex.clickhouse.util.LRUCache;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.ExecutionException;
-
+import java.util.Map;
+import java.util.function.Function;
class ArrayToStringDeserializer extends JsonDeserializer> {
-
- private static final LoadingCache> deserializers
- = CacheBuilder.newBuilder()
- .weakKeys()
- .concurrencyLevel(16)
- .maximumSize(10000)
- .build(new CacheLoader>() {
- @Override
- public JsonDeserializer