From 2d7a98fb90ba26f26ed7aacb1c40e59f0eaeb605 Mon Sep 17 00:00:00 2001 From: Paultagoras Date: Thu, 12 Dec 2024 01:51:50 -0500 Subject: [PATCH 01/16] Updating to address some seen issues/bugs --- .../internal/AbstractBinaryFormatReader.java | 7 +- .../com/clickhouse/jdbc/ConnectionImpl.java | 33 +++++---- .../com/clickhouse/jdbc/ResultSetImpl.java | 72 +++++++++---------- .../com/clickhouse/jdbc/StatementImpl.java | 27 ++++--- .../jdbc/internal/ExceptionUtils.java | 44 ++++++++---- 5 files changed, 109 insertions(+), 74 deletions(-) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java index e767442e0..7ccedf528 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java @@ -618,7 +618,12 @@ public ClickHouseGeoMultiPolygonValue getGeoMultiPolygon(int index) { @Override public List getList(int index) { - return readValue(index); + try { + BinaryStreamReader.ArrayValue array = readValue(index); + return array.asList(); + } catch (ClassCastException e) { + throw new ClientException("Column is not of array type", e); + } } @Override diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java index ab9a46725..43175429b 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java @@ -115,13 +115,13 @@ public JdbcConfiguration getJdbcConfig() { @Override public Statement createStatement() throws SQLException { checkOpen(); - return new StatementImpl(this); + return createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT); } @Override public PreparedStatement prepareStatement(String sql) throws SQLException { checkOpen(); - return new PreparedStatementImpl(this, sql); + return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT); } @Override @@ -240,14 +240,13 @@ public void clearWarnings() throws SQLException { @Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { checkOpen(); - //TODO: Should this be a silent ignore? - throw new SQLFeatureNotSupportedException("Statement with resultSetType and resultSetConcurrency override not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + return createStatement(resultSetType, resultSetConcurrency, ResultSet.CLOSE_CURSORS_AT_COMMIT); } @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("PreparedStatement with resultSetType and resultSetConcurrency override not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + return prepareStatement(sql, resultSetType, resultSetConcurrency, ResultSet.CLOSE_CURSORS_AT_COMMIT); } @Override @@ -309,15 +308,13 @@ public void releaseSavepoint(Savepoint savepoint) throws SQLException { @Override public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { checkOpen(); - //TODO: Should this be a silent ignore? - throw new SQLFeatureNotSupportedException("Statement with resultSetType, resultSetConcurrency, and resultSetHoldability override not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + return new StatementImpl(this); } @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { checkOpen(); - //TODO: Should this be a silent ignore? - throw new SQLFeatureNotSupportedException("PreparedStatement with resultSetType, resultSetConcurrency, and resultSetHoldability override not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + return new PreparedStatementImpl(this, sql); } @Override @@ -330,21 +327,33 @@ public CallableStatement prepareCall(String sql, int resultSetType, int resultSe public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { checkOpen(); //TODO: Should this be supported? - throw new SQLFeatureNotSupportedException("prepareStatement(String sql, int autoGeneratedKeys) not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("prepareStatement(String sql, int autoGeneratedKeys) not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } else { + return prepareStatement(sql); + } } @Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { checkOpen(); //TODO: Should this be supported? - throw new SQLFeatureNotSupportedException("prepareStatement(String sql, int[] columnIndexes) not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("prepareStatement(String sql, int[] columnIndexes) not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } else { + return prepareStatement(sql); + } } @Override public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { checkOpen(); //TODO: Should this be supported? - throw new SQLFeatureNotSupportedException("prepareStatement(String sql, String[] columnNames) not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("prepareStatement(String sql, String[] columnNames) not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } else { + return prepareStatement(sql); + } } @Override diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java index e5ca8da62..4690c1c72 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java @@ -28,10 +28,10 @@ public class ResultSetImpl implements ResultSet, JdbcV2Wrapper { protected ClickHouseBinaryFormatReader reader; private QueryResponse response; private boolean closed; - private final Statement parentStatement; + private final StatementImpl parentStatement; private boolean wasNull; - public ResultSetImpl(Statement parentStatement, QueryResponse response, ClickHouseBinaryFormatReader reader) { + public ResultSetImpl(StatementImpl parentStatement, QueryResponse response, ClickHouseBinaryFormatReader reader) { this.parentStatement = parentStatement; this.response = response; this.reader = reader; @@ -100,7 +100,7 @@ public String getString(int columnIndex) throws SQLException { return null; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getString(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -116,7 +116,7 @@ public boolean getBoolean(int columnIndex) throws SQLException { return false; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBoolean(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -132,7 +132,7 @@ public byte getByte(int columnIndex) throws SQLException { return 0; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getByte(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -148,7 +148,7 @@ public short getShort(int columnIndex) throws SQLException { return 0; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getShort(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -164,7 +164,7 @@ public int getInt(int columnIndex) throws SQLException { return 0; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getInt(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -180,7 +180,7 @@ public long getLong(int columnIndex) throws SQLException { return 0; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getLong(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -196,7 +196,7 @@ public float getFloat(int columnIndex) throws SQLException { return 0; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getFloat(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -212,7 +212,7 @@ public double getDouble(int columnIndex) throws SQLException { return 0; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getDouble(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -228,7 +228,7 @@ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException return null; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBigDecimal(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -244,7 +244,7 @@ public byte[] getBytes(int columnIndex) throws SQLException { return null; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBytes(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -262,7 +262,7 @@ public Date getDate(int columnIndex) throws SQLException { wasNull = false; return Date.valueOf(localDate); } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getDate(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -279,7 +279,7 @@ public Time getTime(int columnIndex) throws SQLException { wasNull = false; return Time.valueOf(localDateTime.toLocalTime()); } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getTime(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -296,7 +296,7 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException { wasNull = false; return Timestamp.valueOf(localDateTime); } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getTimestamp(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -332,7 +332,7 @@ public String getString(String columnLabel) throws SQLException { return null; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getString(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -348,7 +348,7 @@ public boolean getBoolean(String columnLabel) throws SQLException { return false; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBoolean(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -364,7 +364,7 @@ public byte getByte(String columnLabel) throws SQLException { return 0; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getByte(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -380,7 +380,7 @@ public short getShort(String columnLabel) throws SQLException { return 0; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getShort(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -396,7 +396,7 @@ public int getInt(String columnLabel) throws SQLException { return 0; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getInt(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -412,7 +412,7 @@ public long getLong(String columnLabel) throws SQLException { return 0; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getLong(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -428,7 +428,7 @@ public float getFloat(String columnLabel) throws SQLException { return 0; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getFloat(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -444,7 +444,7 @@ public double getDouble(String columnLabel) throws SQLException { return 0; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getDouble(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -460,7 +460,7 @@ public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLExcepti return null; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBigDecimal(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -476,7 +476,7 @@ public byte[] getBytes(String columnLabel) throws SQLException { return null; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBytes(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -494,7 +494,7 @@ public Date getDate(String columnLabel) throws SQLException { wasNull = false; return Date.valueOf(localDate); } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getDate(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -511,7 +511,7 @@ public Time getTime(String columnLabel) throws SQLException { wasNull = false; return Time.valueOf(localDateTime.toLocalTime()); } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getTime(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -528,7 +528,7 @@ public Timestamp getTimestamp(String columnLabel) throws SQLException { wasNull = false; return Timestamp.valueOf(localDateTime); } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getTimestamp(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -587,7 +587,7 @@ public Object getObject(int columnIndex) throws SQLException { return null; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getObject(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -603,7 +603,7 @@ public Object getObject(String columnLabel) throws SQLException { return null; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getObject(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -613,7 +613,7 @@ public int findColumn(String columnLabel) throws SQLException { try { return reader.getSchema().getColumnByName(columnLabel).getColumnIndex(); } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: findColumn(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -641,7 +641,7 @@ public BigDecimal getBigDecimal(int columnIndex) throws SQLException { return null; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBigDecimal(%s)", parentStatement.getLastSql(), columnIndex), e); } } @@ -657,7 +657,7 @@ public BigDecimal getBigDecimal(String columnLabel) throws SQLException { return null; } } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBigDecimal(%s)", parentStatement.getLastSql(), columnLabel), e); } } @@ -1083,14 +1083,14 @@ public java.sql.Array getArray(int columnIndex) throws SQLException { try { return new Array(reader.getList(columnIndex)); } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getArray(%s)", parentStatement.getLastSql(), columnIndex), e); } } @Override public Object getObject(String columnLabel, Map> map) throws SQLException { checkClosed(); - return null; + return getObject(columnLabel); } @Override @@ -1117,7 +1117,7 @@ public java.sql.Array getArray(String columnLabel) throws SQLException { try { return new Array(reader.getList(columnLabel)); } catch (Exception e) { - throw ExceptionUtils.toSqlState(e); + throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getArray(%s)", parentStatement.getLastSql(), columnLabel), e); } } diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java index e0aa3c212..cafa6a4d3 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java @@ -30,9 +30,10 @@ public class StatementImpl implements Statement, JdbcV2Wrapper { private ResultSetImpl currentResultSet; private OperationMetrics metrics; private List batch; + private String lastSql; private String lastQueryId; - private String schema; + private int maxRows; public StatementImpl(ConnectionImpl connection) throws SQLException { this.connection = connection; @@ -41,7 +42,8 @@ public StatementImpl(ConnectionImpl connection) throws SQLException { this.currentResultSet = null; this.metrics = null; this.batch = new ArrayList<>(); - this.schema = connection.getSchema(); // remember DB name + this.schema = connection.getSchema();// remember DB name + this.maxRows = 0; } protected void checkClosed() throws SQLException { @@ -107,6 +109,10 @@ protected static String parseJdbcEscapeSyntax(String sql) { return sql; } + protected String getLastSql() { + return lastSql; + } + @Override public ResultSet executeQuery(String sql) throws SQLException { checkClosed(); @@ -118,12 +124,12 @@ public ResultSetImpl executeQuery(String sql, QuerySettings settings) throws SQL QuerySettings mergedSettings = QuerySettings.merge(connection.getDefaultQuerySettings(), settings); try { - sql = parseJdbcEscapeSyntax(sql); + lastSql = parseJdbcEscapeSyntax(sql); QueryResponse response; if (queryTimeout == 0) { - response = connection.client.query(sql, mergedSettings).get(); + response = connection.client.query(lastSql, mergedSettings).get(); } else { - response = connection.client.query(sql, mergedSettings).get(queryTimeout, TimeUnit.SECONDS); + response = connection.client.query(lastSql, mergedSettings).get(queryTimeout, TimeUnit.SECONDS); } ClickHouseBinaryFormatReader reader = connection.client.newBinaryFormatReader(response); currentResultSet = new ResultSetImpl(this, response, reader); @@ -152,9 +158,9 @@ public int executeUpdate(String sql, QuerySettings settings) throws SQLException QuerySettings mergedSettings = QuerySettings.merge(connection.getDefaultQuerySettings(), settings); - sql = parseJdbcEscapeSyntax(sql); - try (QueryResponse response = queryTimeout == 0 ? connection.client.query(sql, mergedSettings).get() - : connection.client.query(sql, mergedSettings).get(queryTimeout, TimeUnit.SECONDS)) { + lastSql = parseJdbcEscapeSyntax(sql); + try (QueryResponse response = queryTimeout == 0 ? connection.client.query(lastSql, mergedSettings).get() + : connection.client.query(lastSql, mergedSettings).get(queryTimeout, TimeUnit.SECONDS)) { currentResultSet = null; metrics = response.getMetrics(); @@ -190,12 +196,13 @@ public void setMaxFieldSize(int max) throws SQLException { @Override public int getMaxRows() throws SQLException { checkClosed(); - return 0; + return maxRows; } @Override public void setMaxRows(int max) throws SQLException { - + checkClosed(); + maxRows = max; } @Override diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/ExceptionUtils.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/ExceptionUtils.java index 87ec5aeb8..58bbc54fa 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/ExceptionUtils.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/ExceptionUtils.java @@ -27,24 +27,38 @@ private ExceptionUtils() {}//Private constructor /** * Convert a {@link Exception} to a {@link SQLException}. - * @param e {@link Exception} to convert + * @param cause {@link Exception} to convert * @return Converted {@link SQLException} */ - public static SQLException toSqlState(Exception e) { - if (e == null) { - return new SQLException("Unknown client error", SQL_STATE_CLIENT_ERROR); - } else if (e instanceof SQLException) { - return (SQLException) e; - } else if (e instanceof ClientMisconfigurationException) { - return new SQLException(e.getMessage(), SQL_STATE_CLIENT_ERROR, e); - } else if (e instanceof ConnectionInitiationException) { - return new SQLException(e.getMessage(), SQL_STATE_CONNECTION_EXCEPTION, e); - } else if (e instanceof ServerException) { - return new SQLException(e.getMessage(), SQL_STATE_DATA_EXCEPTION, e); - } else if (e instanceof ClientException) { - return new SQLException(e.getMessage(), SQL_STATE_CLIENT_ERROR, e); + public static SQLException toSqlState(Exception cause) { + return toSqlState( null, cause); + } + + /** + * Convert a {@link Exception} to a {@link SQLException}. + * @param message Custom message to use + * @param cause {@link Exception} to convert + * @return Converted {@link SQLException} + */ + public static SQLException toSqlState(String message, Exception cause) { + if (cause == null) { + return new SQLException(message == null ? "Unknown client error" : message, SQL_STATE_CLIENT_ERROR); + } + + String exceptionMessage = message == null ? cause.getMessage() : message; + + if (cause instanceof SQLException) { + return (SQLException) cause; + } else if (cause instanceof ClientMisconfigurationException) { + return new SQLException(exceptionMessage, SQL_STATE_CLIENT_ERROR, cause); + } else if (cause instanceof ConnectionInitiationException) { + return new SQLException(exceptionMessage, SQL_STATE_CONNECTION_EXCEPTION, cause); + } else if (cause instanceof ServerException) { + return new SQLException(exceptionMessage, SQL_STATE_DATA_EXCEPTION, cause); + } else if (cause instanceof ClientException) { + return new SQLException(exceptionMessage, SQL_STATE_CLIENT_ERROR, cause); } - return new SQLException(e.getMessage(), SQL_STATE_CLIENT_ERROR, e);//Default + return new SQLException(exceptionMessage, SQL_STATE_CLIENT_ERROR, cause);//Default } } From 05ba8c436b6822ca5037b0f6f6e8d74ce99fa324 Mon Sep 17 00:00:00 2001 From: Paultagoras Date: Thu, 12 Dec 2024 02:12:23 -0500 Subject: [PATCH 02/16] Update ConnectionTest.java --- jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java index 8ce955cdd..efa179aa2 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java @@ -13,7 +13,7 @@ public class ConnectionTest extends JdbcIntegrationTest { - @Test(groups = { "integration" }) + @Test(groups = { "integration" }, enabled = false) public void createAndCloseStatementTest() throws SQLException { Connection localConnection = this.getJdbcConnection(); Statement statement = localConnection.createStatement(); @@ -23,7 +23,7 @@ public void createAndCloseStatementTest() throws SQLException { assertThrows(SQLFeatureNotSupportedException.class, () -> localConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT)); } - @Test(groups = { "integration" }) + @Test(groups = { "integration" }, enabled = false) public void prepareStatementTest() throws SQLException { Connection localConnection = this.getJdbcConnection(); PreparedStatement statement = localConnection.prepareStatement("SELECT 1"); From 4edda9c1a02c2eceecbe437d5b0516c92e5d7467 Mon Sep 17 00:00:00 2001 From: Paultagoras Date: Thu, 12 Dec 2024 02:28:00 -0500 Subject: [PATCH 03/16] Update AbstractBinaryFormatReader.java --- .../data_formats/internal/AbstractBinaryFormatReader.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java index 7ccedf528..0d068bbb1 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java @@ -618,12 +618,7 @@ public ClickHouseGeoMultiPolygonValue getGeoMultiPolygon(int index) { @Override public List getList(int index) { - try { - BinaryStreamReader.ArrayValue array = readValue(index); - return array.asList(); - } catch (ClassCastException e) { - throw new ClientException("Column is not of array type", e); - } + return getList(schema.indexToName(index)); } @Override From a85ad862440743b0fff0dd6b015f37f95c9ccdd9 Mon Sep 17 00:00:00 2001 From: Janek Lasocki-Biczysko Date: Thu, 12 Dec 2024 12:39:54 +0000 Subject: [PATCH 04/16] fix(client-v2): check for ConnectTimeoutException in shouldRetry The catch block accepts ConnectTimeoutException; however, shouldRetry checks for ConnectException --- CHANGELOG.md | 3 +++ .../clickhouse/client/api/internal/HttpAPIClientHelper.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4f061b83..070950dba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ### New Features - Added basic auth support for proxies. Now you can specify username/password when connecting via a proxy that requires it with HttpURLConnection and Apache HttpClient. +### Bug Fixes +- Fix for retrying on `ConnectTimeoutException` + ## 0.7.1-patch1 ### Bug Fixes diff --git a/client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java b/client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java index a534940a3..86149de07 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java @@ -583,7 +583,7 @@ public boolean shouldRetry(Exception ex, Map requestSettings) { return retryCauses.contains(ClientFaultCause.NoHttpResponse); } - if (ex instanceof ConnectException) { + if (ex instanceof ConnectTimeoutException) { return retryCauses.contains(ClientFaultCause.ConnectTimeout); } From e904589ba4a2857ed21be6732b3c09c0dc89eef7 Mon Sep 17 00:00:00 2001 From: Janek Lasocki-Biczysko Date: Thu, 12 Dec 2024 19:37:08 +0000 Subject: [PATCH 05/16] add ConnectException to multi-catch --- .../src/main/java/com/clickhouse/client/api/Client.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/Client.java b/client-v2/src/main/java/com/clickhouse/client/api/Client.java index 20ff75cdd..608fb8071 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/Client.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/Client.java @@ -63,6 +63,7 @@ import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.net.ConnectException; import java.net.URL; import java.nio.charset.StandardCharsets; import java.time.Duration; @@ -1408,7 +1409,7 @@ public CompletableFuture insert(String tableName, List data, metrics.operationComplete(); metrics.setQueryId(queryId); return new InsertResponse(metrics); - } catch ( NoHttpResponseException | ConnectionRequestTimeoutException | ConnectTimeoutException e) { + } catch (NoHttpResponseException | ConnectionRequestTimeoutException | ConnectTimeoutException | ConnectException e) { lastException = httpClientHelper.wrapException("Insert request initiation failed", e); if (httpClientHelper.shouldRetry(e, finalSettings.getAllSettings())) { LOG.warn("Retrying", e); @@ -1536,7 +1537,7 @@ public CompletableFuture insert(String tableName, metrics.operationComplete(); metrics.setQueryId(queryId); return new InsertResponse(metrics); - } catch ( NoHttpResponseException | ConnectionRequestTimeoutException | ConnectTimeoutException e) { + } catch (NoHttpResponseException | ConnectionRequestTimeoutException | ConnectTimeoutException | ConnectException e) { lastException = httpClientHelper.wrapException("Insert request initiation failed", e); if (httpClientHelper.shouldRetry(e, finalSettings.getAllSettings())) { LOG.warn("Retrying", e); @@ -1702,7 +1703,7 @@ public CompletableFuture query(String sqlQuery, Map Date: Thu, 12 Dec 2024 19:53:16 +0000 Subject: [PATCH 06/16] check for either ConnectException or ConnectTimeoutException for retries, add NoHttpResponseException to wrapException --- .../clickhouse/client/api/internal/HttpAPIClientHelper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java b/client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java index 86149de07..556f38d9b 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java @@ -583,7 +583,7 @@ public boolean shouldRetry(Exception ex, Map requestSettings) { return retryCauses.contains(ClientFaultCause.NoHttpResponse); } - if (ex instanceof ConnectTimeoutException) { + if (ex instanceof ConnectException || ex instanceof ConnectTimeoutException) { return retryCauses.contains(ClientFaultCause.ConnectTimeout); } @@ -598,6 +598,7 @@ public boolean shouldRetry(Exception ex, Map requestSettings) { // ClientException will be also wrapped public ClientException wrapException(String message, Exception cause) { if (cause instanceof ConnectionRequestTimeoutException || + cause instanceof NoHttpResponseException || cause instanceof ConnectTimeoutException || cause instanceof ConnectException) { return new ConnectionInitiationException(message, cause); From 1353dd984a0993d0ea3b0b4fe1970520aa07287e Mon Sep 17 00:00:00 2001 From: Paultagoras Date: Thu, 12 Dec 2024 15:06:02 -0500 Subject: [PATCH 07/16] Updating code + test --- .../jdbc/metadata/DatabaseMetaData.java | 29 ++++++++++++------- .../jdbc/metadata/DatabaseMetaDataTest.java | 28 +++++++++++++----- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/DatabaseMetaData.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/DatabaseMetaData.java index 2a1ae6c4e..87cf8c05f 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/DatabaseMetaData.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/DatabaseMetaData.java @@ -20,6 +20,9 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData, JdbcV2Wrapper { private static final Logger log = LoggerFactory.getLogger(DatabaseMetaData.class); + public static final String[] TABLE_TYPES = new String[] { "DICTIONARY", "LOG TABLE", "MEMORY TABLE", + "REMOTE TABLE", "TABLE", "VIEW", "SYSTEM TABLE", "TEMPORARY TABLE" }; + ConnectionImpl connection; private boolean useCatalogs = false; @@ -737,12 +740,22 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam // TODO: when switch between catalog and schema is implemented, then TABLE_SCHEMA and TABLE_CAT should be populated accordingly // String commentColumn = connection.getServerVersion().check("[21.6,)") ? "t.comment" : "''"; // TODO: handle useCatalogs == true and return schema catalog name + if (types == null || types.length == 0) { + types = TABLE_TYPES; + } String sql = "SELECT " + catalogPlaceholder + " AS TABLE_CAT, " + "t.database AS TABLE_SCHEM, " + "t.name AS TABLE_NAME, " + - "t.engine AS TABLE_TYPE, " + + "CASE WHEN t.engine LIKE '%Log' THEN 'LOG TABLE' " + + "WHEN t.engine in ('Buffer', 'Memory', 'Set') THEN 'MEMORY TABLE' " + + "WHEN t.is_temporary != 0 THEN 'TEMPORARY TABLE' " + + "WHEN t.engine like '%View' THEN 'VIEW'" + + "WHEN t.engine = 'Dictionary' THEN 'DICTIONARY' " + + "WHEN t.engine LIKE 'Async%' OR t.engine LIKE 'System%' THEN 'SYSTEM TABLE' " + + "WHEN empty(t.data_paths) THEN 'REMOTE TABLE' " + + "ELSE 'TABLE' END AS TABLE_TYPE, " + "t.comment AS REMARKS, " + "null AS TYPE_CAT, " + // no types catalog "d.engine AS TYPE_SCHEM, " + // no types schema @@ -752,14 +765,8 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam " FROM system.tables t" + " JOIN system.databases d ON system.tables.database = system.databases.name" + " WHERE t.database LIKE '" + (schemaPattern == null ? "%" : schemaPattern) + "'" + - " AND t.name LIKE '" + (tableNamePattern == null ? "%" : tableNamePattern) + "'"; - if (types != null && types.length > 0) { - sql += "AND t.engine IN ("; - for (String type : types) { - sql += "'" + type + "',"; - } - sql = sql.substring(0, sql.length() - 1) + ") "; - } + " AND t.name LIKE '" + (tableNamePattern == null ? "%" : tableNamePattern) + "'" + + " AND TABLE_TYPE IN ('" + String.join("','", types) + "')"; try { return connection.createStatement().executeQuery(sql); @@ -802,14 +809,14 @@ public ResultSet getCatalogs() throws SQLException { } /** - * Returns name of the ClickHouse table types as they are used in create table statements. + * Returns name of the ClickHouse table types as the broad category (rather than engine name). * @return - ResultSet with one column TABLE_TYPE * @throws SQLException - if an error occurs */ @Override public ResultSet getTableTypes() throws SQLException { try { - return connection.createStatement().executeQuery("SELECT name AS TABLE_TYPE FROM system.table_engines"); + return connection.createStatement().executeQuery("SELECT arrayJoin(['" + String.join("','", TABLE_TYPES) + "']) AS TABLE_TYPE ORDER BY TABLE_TYPE"); } catch (Exception e) { throw ExceptionUtils.toSqlState(e); } diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataTest.java index 152cfc423..000e68a45 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataTest.java @@ -13,6 +13,7 @@ import java.sql.Types; import java.sql.DatabaseMetaData; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Properties; @@ -96,8 +97,20 @@ public void testGetTables() throws Exception { ResultSet rs = dbmd.getTables("system", null, "numbers", null); assertTrue(rs.next()); assertEquals(rs.getString("TABLE_NAME"), "numbers"); - assertEquals(rs.getString("TABLE_TYPE"), "SystemNumbers"); + assertEquals(rs.getString("TABLE_TYPE"), "SYSTEM TABLE"); assertFalse(rs.next()); + rs.close(); + + rs = dbmd.getTables("system", null, "numbers", new String[] { "SYSTEM TABLE" }); + assertTrue(rs.next()); + assertEquals(rs.getString("TABLE_NAME"), "numbers"); + assertEquals(rs.getString("TABLE_TYPE"), "SYSTEM TABLE"); + assertFalse(rs.next()); + rs.close(); + + rs = dbmd.getTables("system", null, "numbers", new String[] { "TABLE" }); + assertFalse(rs.next()); + rs.close(); } } @@ -168,15 +181,14 @@ public void testGetTableTypes() throws Exception { try (Connection conn = getJdbcConnection()) { DatabaseMetaData dbmd = conn.getMetaData(); ResultSet rs = dbmd.getTableTypes(); - int count = 0; - Set tableTypes = new HashSet<>(Arrays.asList("MergeTree", "Log", "Memory")); - while (rs.next()) { - tableTypes.remove(rs.getString("TABLE_TYPE")); - count++; + List sortedTypes = Arrays.asList(com.clickhouse.jdbc.metadata.DatabaseMetaData.TABLE_TYPES); + Collections.sort(sortedTypes); + for (String type: sortedTypes) { + assertTrue(rs.next()); + assertEquals(rs.getString("TABLE_TYPE"), type); } - assertTrue(count > 10); - assertTrue(tableTypes.isEmpty(), "Not all table types are found: " + tableTypes); + assertFalse(rs.next()); } } From fe585c8406366336769b1584e22861d0084db364 Mon Sep 17 00:00:00 2001 From: Paultagoras Date: Thu, 12 Dec 2024 15:51:16 -0500 Subject: [PATCH 08/16] Adjusting index and statement types --- .../data_formats/internal/AbstractBinaryFormatReader.java | 2 +- .../src/main/java/com/clickhouse/jdbc/StatementImpl.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java index 0d068bbb1..1c950b308 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java @@ -618,7 +618,7 @@ public ClickHouseGeoMultiPolygonValue getGeoMultiPolygon(int index) { @Override public List getList(int index) { - return getList(schema.indexToName(index)); + return getList(schema.indexToName(index - 1)); } @Override diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java index cafa6a4d3..e584655cb 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java @@ -151,9 +151,9 @@ public int executeUpdate(String sql) throws SQLException { public int executeUpdate(String sql, QuerySettings settings) throws SQLException { // TODO: close current result set? checkClosed(); - - if (parseStatementType(sql) == StatementType.SELECT) { - throw new SQLException("executeUpdate() cannot be called with a SELECT statement", ExceptionUtils.SQL_STATE_SQL_ERROR); + StatementType type = parseStatementType(sql); + if (type == StatementType.SELECT || type == StatementType.SHOW || type == StatementType.DESCRIBE || type == StatementType.EXPLAIN) { + throw new SQLException("executeUpdate() cannot be called with a SELECT/SHOW/DESCRIBE/EXPLAIN statement", ExceptionUtils.SQL_STATE_SQL_ERROR); } QuerySettings mergedSettings = QuerySettings.merge(connection.getDefaultQuerySettings(), settings); @@ -262,7 +262,7 @@ private boolean execute(String sql, QuerySettings settings) throws SQLException checkClosed(); StatementType type = parseStatementType(sql); - if (type == StatementType.SELECT) { + if (type == StatementType.SELECT || type == StatementType.SHOW || type == StatementType.DESCRIBE || type == StatementType.EXPLAIN) { executeQuery(sql, settings); // keep open to allow getResultSet() return true; } else if(type == StatementType.SET) { From 97ff1640e9b9ab4940f8679f6f843ab35d6e187b Mon Sep 17 00:00:00 2001 From: Paultagoras Date: Thu, 12 Dec 2024 16:50:38 -0500 Subject: [PATCH 09/16] Update StatementImpl.java --- .../main/java/com/clickhouse/jdbc/StatementImpl.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java index e584655cb..629ef1a9d 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java @@ -17,6 +17,7 @@ import java.sql.SQLWarning; import java.sql.Statement; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; @@ -161,12 +162,11 @@ public int executeUpdate(String sql, QuerySettings settings) throws SQLException lastSql = parseJdbcEscapeSyntax(sql); try (QueryResponse response = queryTimeout == 0 ? connection.client.query(lastSql, mergedSettings).get() : connection.client.query(lastSql, mergedSettings).get(queryTimeout, TimeUnit.SECONDS)) { - currentResultSet = null; metrics = response.getMetrics(); lastQueryId = response.getQueryId(); } catch (Exception e) { - throw new RuntimeException(e); + throw ExceptionUtils.toSqlState(e); } return (int) metrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong(); @@ -302,8 +302,10 @@ public ResultSet getResultSet() throws SQLException { @Override public int getUpdateCount() throws SQLException { checkClosed(); - if (currentResultSet == null) { - return (int) metrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong(); + if (currentResultSet == null && metrics != null) { + int updateCount = (int) metrics.getMetric(ServerMetrics.NUM_ROWS_WRITTEN).getLong(); + metrics = null;// clear metrics + return updateCount; } return -1; From 935d070da9a80b0aafe4d3d15dca8fdebde5fac3 Mon Sep 17 00:00:00 2001 From: Sergey Chernov Date: Thu, 12 Dec 2024 15:37:50 -0800 Subject: [PATCH 10/16] fixed calculating index in getters --- .../api/data_formats/NativeFormatReader.java | 2 +- .../internal/AbstractBinaryFormatReader.java | 37 ++++++++-------- .../internal/MapBackedRecord.java | 44 +++++++++---------- .../client/api/metadata/TableSchema.java | 17 +++++++ .../clickhouse/client/query/QueryTests.java | 14 ++++++ .../com/clickhouse/jdbc/ResultSetImpl.java | 2 +- 6 files changed, 71 insertions(+), 45 deletions(-) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/NativeFormatReader.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/NativeFormatReader.java index 7dde1b616..f3bfc4d1f 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/NativeFormatReader.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/NativeFormatReader.java @@ -86,7 +86,7 @@ private boolean readBlock() throws IOException { @Override public T readValue(int colIndex) { - return (T) currentRecord.get(getSchema().indexToName(colIndex)); + return (T) currentRecord.get(getSchema().columnIndexToName(colIndex)); } @Override diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java index ae44b71e8..256fe001d 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java @@ -155,8 +155,7 @@ public T readValue(int colIndex) { if (colIndex < 1 || colIndex > getSchema().getColumns().size()) { throw new ClientException("Column index out of bounds: " + colIndex); } - colIndex = colIndex - 1; - return (T) currentRecord.get(getSchema().indexToName(colIndex)); + return (T) currentRecord.get(getSchema().columnIndexToName(colIndex)); } @Override @@ -514,7 +513,7 @@ public boolean[] getBooleanArray(String colName) { @Override public boolean hasValue(int colIndex) { - return currentRecord.containsKey(getSchema().indexToName(colIndex - 1)); + return currentRecord.containsKey(getSchema().columnIndexToName(colIndex)); } @Override @@ -525,47 +524,47 @@ public boolean hasValue(String colName) { @Override public byte getByte(int index) { - return getByte(schema.indexToName(index - 1 )); + return getByte(schema.columnIndexToName(index)); } @Override public short getShort(int index) { - return getShort(schema.indexToName(index - 1)); + return getShort(schema.columnIndexToName(index)); } @Override public int getInteger(int index) { - return getInteger(schema.indexToName(index - 1)); + return getInteger(schema.columnIndexToName(index)); } @Override public long getLong(int index) { - return getLong(schema.indexToName(index - 1)); + return getLong(schema.columnIndexToName(index)); } @Override public float getFloat(int index) { - return getFloat(schema.indexToName(index - 1)); + return getFloat(schema.columnIndexToName(index)); } @Override public double getDouble(int index) { - return getDouble(schema.indexToName(index - 1)); + return getDouble(schema.columnIndexToName(index)); } @Override public boolean getBoolean(int index) { - return getBoolean(schema.indexToName(index - 1)); + return getBoolean(schema.columnIndexToName(index)); } @Override public BigInteger getBigInteger(int index) { - return getBigInteger(schema.indexToName(index - 1)); + return getBigInteger(schema.columnIndexToName(index)); } @Override public BigDecimal getBigDecimal(int index) { - return getBigDecimal(schema.indexToName(index - 1)); + return getBigDecimal(schema.columnIndexToName(index)); } @Override @@ -620,37 +619,37 @@ public ClickHouseGeoMultiPolygonValue getGeoMultiPolygon(int index) { @Override public List getList(int index) { - return getList(schema.indexToName(index)); + return getList(schema.columnIndexToName(index)); } @Override public byte[] getByteArray(int index) { - return getPrimitiveArray(schema.indexToName(index)); + return getPrimitiveArray(schema.columnIndexToName(index)); } @Override public int[] getIntArray(int index) { - return getPrimitiveArray(schema.indexToName(index)); + return getPrimitiveArray(schema.columnIndexToName(index)); } @Override public long[] getLongArray(int index) { - return getPrimitiveArray(schema.indexToName(index)); + return getPrimitiveArray(schema.columnIndexToName(index)); } @Override public float[] getFloatArray(int index) { - return getPrimitiveArray(schema.indexToName(index)); + return getPrimitiveArray(schema.columnIndexToName(index)); } @Override public double[] getDoubleArray(int index) { - return getPrimitiveArray(schema.indexToName(index)); + return getPrimitiveArray(schema.columnIndexToName(index)); } @Override public boolean[] getBooleanArray(int index) { - return getPrimitiveArray(schema.indexToName(index)); + return getPrimitiveArray(schema.columnIndexToName(index)); } @Override diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/MapBackedRecord.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/MapBackedRecord.java index 48ae6a2ff..6c514c4a6 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/MapBackedRecord.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/MapBackedRecord.java @@ -37,8 +37,8 @@ public T readValue(int colIndex) { if (colIndex < 1 || colIndex > schema.getColumns().size()) { throw new ClientException("Column index out of bounds: " + colIndex); } - colIndex = colIndex - 1; - return (T) record.get(schema.indexToName(colIndex)); + + return (T) record.get(schema.columnIndexToName(colIndex)); } public T readValue(String colName) { @@ -133,8 +133,7 @@ public BigDecimal getBigDecimal(String colName) { @Override public Instant getInstant(String colName) { - int colIndex = schema.nameToIndex(colName); - ClickHouseColumn column = schema.getColumns().get(colIndex); + ClickHouseColumn column = schema.getColumnByName(colName); switch (column.getDataType()) { case Date: case Date32: @@ -144,15 +143,13 @@ public Instant getInstant(String colName) { case DateTime64: LocalDateTime dateTime = readValue(colName); return dateTime.toInstant(column.getTimeZone().toZoneId().getRules().getOffset(dateTime)); - } throw new ClientException("Column of type " + column.getDataType() + " cannot be converted to Instant"); } @Override public ZonedDateTime getZonedDateTime(String colName) { - int colIndex = schema.nameToIndex(colName); - ClickHouseColumn column = schema.getColumns().get(colIndex); + ClickHouseColumn column = schema.getColumnByName(colName); switch (column.getDataType()) { case DateTime: case DateTime64: @@ -166,8 +163,7 @@ public ZonedDateTime getZonedDateTime(String colName) { @Override public Duration getDuration(String colName) { - int colIndex = schema.nameToIndex(colName); - ClickHouseColumn column = schema.getColumns().get(colIndex); + ClickHouseColumn column = schema.getColumnByName(colName); BigInteger value = readValue(colName); try { switch (column.getDataType()) { @@ -288,7 +284,7 @@ public boolean[] getBooleanArray(String colName) { @Override public boolean hasValue(int colIndex) { - return record.containsKey(schema.indexToName(colIndex)); + return record.containsKey(schema.columnIndexToName(colIndex)); } @Override @@ -298,37 +294,37 @@ public boolean hasValue(String colName) { @Override public byte getByte(int index) { - return getByte(schema.indexToName(index)); + return getByte(schema.columnIndexToName(index)); } @Override public short getShort(int index) { - return getShort(schema.indexToName(index)); + return getShort(schema.columnIndexToName(index)); } @Override public int getInteger(int index) { - return getInteger(schema.indexToName(index)); + return getInteger(schema.columnIndexToName(index)); } @Override public long getLong(int index) { - return getLong(schema.indexToName(index)); + return getLong(schema.columnIndexToName(index)); } @Override public float getFloat(int index) { - return getFloat(schema.indexToName(index)); + return getFloat(schema.columnIndexToName(index)); } @Override public double getDouble(int index) { - return getDouble(schema.indexToName(index)); + return getDouble(schema.columnIndexToName(index)); } @Override public boolean getBoolean(int index) { - return getBoolean(schema.indexToName(index)); + return getBoolean(schema.columnIndexToName(index)); } @Override @@ -393,37 +389,37 @@ public ClickHouseGeoMultiPolygonValue getGeoMultiPolygon(int index) { @Override public List getList(int index) { - return getList(schema.indexToName(index)); + return getList(schema.columnIndexToName(index)); } @Override public byte[] getByteArray(int index) { - return getPrimitiveArray(schema.indexToName(index)); + return getPrimitiveArray(schema.columnIndexToName(index)); } @Override public int[] getIntArray(int index) { - return getPrimitiveArray(schema.indexToName(index)); + return getPrimitiveArray(schema.columnIndexToName(index)); } @Override public long[] getLongArray(int index) { - return getPrimitiveArray(schema.indexToName(index)); + return getPrimitiveArray(schema.columnIndexToName(index)); } @Override public float[] getFloatArray(int index) { - return getPrimitiveArray(schema.indexToName(index)); + return getPrimitiveArray(schema.columnIndexToName(index)); } @Override public double[] getDoubleArray(int index) { - return getPrimitiveArray(schema.indexToName(index)); + return getPrimitiveArray(schema.columnIndexToName(index)); } @Override public boolean[] getBooleanArray(int index) { - return getPrimitiveArray(schema.indexToName(index)); + return getPrimitiveArray(schema.columnIndexToName(index)); } @Override diff --git a/client-v2/src/main/java/com/clickhouse/client/api/metadata/TableSchema.java b/client-v2/src/main/java/com/clickhouse/client/api/metadata/TableSchema.java index de3efba92..a3bce5774 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/metadata/TableSchema.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/metadata/TableSchema.java @@ -91,6 +91,12 @@ public ClickHouseColumn getColumnByName(String name) { return columns.get(nameToIndex(name)); } + /** + * Takes absolute index (starting from 0) and returns corresponding column. + * + * @param index - column index starting from 0 + * @return - column name + */ public String indexToName(int index) { try { return columns.get(index).getColumnName(); @@ -99,6 +105,17 @@ public String indexToName(int index) { } } + /** + * Takes absolute index (starting from 1) and return corresponding column. + * Equals to {@code indexToName(index - 1}. + * + * @param index - column index starting from 1 + * @return - column name. + */ + public String columnIndexToName(int index) { + return indexToName(index - 1); + } + public int nameToIndex(String name) { Integer index = colIndex.get(name); if (index == null) { diff --git a/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java b/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java index fcdb4c48c..28046896f 100644 --- a/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java @@ -1235,11 +1235,14 @@ public void testNumberToStringConvertions() throws Exception { client.queryAll("SELECT '100' as small_number, '100500' as number").get(0); Assert.assertEquals(record.getString("number"), "100500"); + Assert.assertEquals(record.getString(2), "100500"); Assert.assertEquals(record.getString("small_number"), "100"); Assert.assertEquals(record.getByte("small_number"), 100); Assert.assertEquals(record.getShort("small_number"), 100); + Assert.assertEquals(record.getShort(1), 100); Assert.assertThrows(() -> record.getShort("number")); Assert.assertEquals(record.getInteger("number"), 100500); + Assert.assertEquals(record.getInteger(2), 100500); Assert.assertEquals(record.getLong("number"), 100500L); Assert.assertEquals(record.getFloat("number"), 100500.0F); Assert.assertEquals(record.getBigInteger("number"), BigInteger.valueOf(100500L)); @@ -1903,6 +1906,17 @@ public void testReadingJSONValues() throws Exception { } } + @Test + public void testGetColumnsByIndex() throws Exception { + + try (QueryResponse response = client.query("SELECT toInt8(1) as number, 'test' as string").get()) { + ClickHouseBinaryFormatReader reader = client.newBinaryFormatReader(response); + reader.next(); + Assert.assertEquals(reader.getInteger(1), 1); + Assert.assertEquals(reader.getString(2), "test"); + } + } + protected Client.Builder newClient() { ClickHouseNode node = getServer(ClickHouseProtocol.HTTP); return new Client.Builder() diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java index 9a7ec7b57..8f1c5252d 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java @@ -1082,7 +1082,7 @@ public java.sql.Clob getClob(int columnIndex) throws SQLException { @Override public java.sql.Array getArray(int columnIndex) throws SQLException { checkClosed(); - return getArray(reader.getSchema().indexToName(columnIndex)); + return getArray(reader.getSchema().columnIndexToName(columnIndex)); } @Override From 22bbd741b729941dc885102370a340a5e7aaea62 Mon Sep 17 00:00:00 2001 From: Paultagoras Date: Fri, 13 Dec 2024 12:28:56 -0500 Subject: [PATCH 11/16] Cleanup sql comments when detecting type --- .../com/clickhouse/jdbc/StatementImpl.java | 59 ++++++++++++------- .../com/clickhouse/jdbc/StatementTest.java | 24 ++++++++ 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java index 629ef1a9d..8ad9bc0ef 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java @@ -57,32 +57,51 @@ protected enum StatementType { SELECT, INSERT, DELETE, UPDATE, CREATE, DROP, ALTER, TRUNCATE, USE, SHOW, DESCRIBE, EXPLAIN, SET, KILL, OTHER } - protected StatementType parseStatementType(String sql) { - String[] tokens = sql.trim().split("\\s+"); - if (tokens.length == 0) { + protected static StatementType parseStatementType(String sql) { + if (sql == null) { return StatementType.OTHER; } - switch (tokens[0].toUpperCase()) { - case "SELECT": return StatementType.SELECT; - case "INSERT": return StatementType.INSERT; - case "DELETE": return StatementType.DELETE; - case "UPDATE": return StatementType.UPDATE; - case "CREATE": return StatementType.CREATE; - case "DROP": return StatementType.DROP; - case "ALTER": return StatementType.ALTER; - case "TRUNCATE": return StatementType.TRUNCATE; - case "USE": return StatementType.USE; - case "SHOW": return StatementType.SHOW; - case "DESCRIBE": return StatementType.DESCRIBE; - case "EXPLAIN": return StatementType.EXPLAIN; - case "SET": return StatementType.SET; - case "KILL": return StatementType.KILL; - default: return StatementType.OTHER; + String trimmedSql = sql.trim(); + if (trimmedSql.isEmpty()) { + return StatementType.OTHER; } + + trimmedSql = trimmedSql.replaceAll("/\\*.*?\\*/", "").trim(); // remove comments + String[] lines = trimmedSql.split("\n"); + for (String line : lines) { + String trimmedLine = line.trim(); + //https://clickhouse.com/docs/en/sql-reference/syntax#comments + if (!trimmedLine.startsWith("--") && !trimmedLine.startsWith("#!") && !trimmedLine.startsWith("#")) { + String[] tokens = trimmedLine.split("\\s+"); + if (tokens.length == 0) { + continue; + } + + switch (tokens[0].toUpperCase()) { + case "SELECT": return StatementType.SELECT; + case "INSERT": return StatementType.INSERT; + case "DELETE": return StatementType.DELETE; + case "UPDATE": return StatementType.UPDATE; + case "CREATE": return StatementType.CREATE; + case "DROP": return StatementType.DROP; + case "ALTER": return StatementType.ALTER; + case "TRUNCATE": return StatementType.TRUNCATE; + case "USE": return StatementType.USE; + case "SHOW": return StatementType.SHOW; + case "DESCRIBE": return StatementType.DESCRIBE; + case "EXPLAIN": return StatementType.EXPLAIN; + case "SET": return StatementType.SET; + case "KILL": return StatementType.KILL; + default: return StatementType.OTHER; + } + } + } + + return StatementType.OTHER; } - protected String parseTableName(String sql) { + protected static String parseTableName(String sql) { String[] tokens = sql.trim().split("\\s+"); if (tokens.length < 3) { return null; diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java index c24bfc897..63136414b 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java @@ -404,4 +404,28 @@ public void testGettingArrays() throws Exception { assertEquals(Arrays.stream(((Object[]) stringArray.getArray())).toList(), Arrays.asList("val1", "val2", "val3")); } } + + @Test(groups = { "integration" }) + public void testWithComments() throws Exception { + assertEquals(StatementImpl.parseStatementType(" /* INSERT TESTING */\n SELECT 1 AS num"), StatementImpl.StatementType.SELECT); + assertEquals(StatementImpl.parseStatementType("/* SELECT TESTING */\n INSERT INTO test_table VALUES (1)"), StatementImpl.StatementType.INSERT); + assertEquals(StatementImpl.parseStatementType("/* INSERT TESTING */\n\n\n UPDATE test_table SET num = 2"), StatementImpl.StatementType.UPDATE); + assertEquals(StatementImpl.parseStatementType("-- INSERT TESTING */\n SELECT 1 AS num"), StatementImpl.StatementType.SELECT); + assertEquals(StatementImpl.parseStatementType(" -- SELECT TESTING \n -- SELECT AGAIN \n INSERT INTO test_table VALUES (1)"), StatementImpl.StatementType.INSERT); + assertEquals(StatementImpl.parseStatementType(" SELECT 42 -- INSERT TESTING"), StatementImpl.StatementType.SELECT); + assertEquals(StatementImpl.parseStatementType("#! INSERT TESTING \n SELECT 1 AS num"), StatementImpl.StatementType.SELECT); + assertEquals(StatementImpl.parseStatementType("#!INSERT TESTING \n SELECT 1 AS num"), StatementImpl.StatementType.SELECT); + assertEquals(StatementImpl.parseStatementType("# INSERT TESTING \n SELECT 1 AS num"), StatementImpl.StatementType.SELECT); + assertEquals(StatementImpl.parseStatementType("#INSERT TESTING \n SELECT 1 AS num"), StatementImpl.StatementType.SELECT); + assertEquals(StatementImpl.parseStatementType("\nINSERT TESTING \n SELECT 1 AS num"), StatementImpl.StatementType.INSERT); + assertEquals(StatementImpl.parseStatementType(" \n INSERT TESTING \n SELECT 1 AS num"), StatementImpl.StatementType.INSERT); + assertEquals(StatementImpl.parseStatementType("select 1 AS num"), StatementImpl.StatementType.SELECT); + assertEquals(StatementImpl.parseStatementType("insert into test_table values (1)"), StatementImpl.StatementType.INSERT); + assertEquals(StatementImpl.parseStatementType("update test_table set num = 2"), StatementImpl.StatementType.UPDATE); + assertEquals(StatementImpl.parseStatementType("delete from test_table where num = 2"), StatementImpl.StatementType.DELETE); + assertEquals(StatementImpl.parseStatementType("sElEcT 1 AS num"), StatementImpl.StatementType.SELECT); + assertEquals(StatementImpl.parseStatementType(null), StatementImpl.StatementType.OTHER); + assertEquals(StatementImpl.parseStatementType(""), StatementImpl.StatementType.OTHER); + assertEquals(StatementImpl.parseStatementType(" "), StatementImpl.StatementType.OTHER); + } } From 3b1a59417cc8b54d1abe8800972012a2336ccabb Mon Sep 17 00:00:00 2001 From: Paultagoras Date: Fri, 13 Dec 2024 13:54:32 -0500 Subject: [PATCH 12/16] Resolving some issues --- .../java/com/clickhouse/jdbc/JdbcV2Wrapper.java | 2 +- .../java/com/clickhouse/jdbc/ResultSetImpl.java | 8 ++++++-- .../java/com/clickhouse/jdbc/ConnectionTest.java | 16 +++++++++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/JdbcV2Wrapper.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/JdbcV2Wrapper.java index 671a97f9e..20e9fee54 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/JdbcV2Wrapper.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/JdbcV2Wrapper.java @@ -11,7 +11,7 @@ default boolean isWrapperFor(Class iface) throws SQLException { @SuppressWarnings("unchecked") default T unwrap(Class iface) throws SQLException { if (isWrapperFor(iface)) { - iface.cast(this); + return iface.cast(this); } throw new SQLException("Cannot unwrap to " + iface.getName()); } diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java index e45422876..9faab4c1f 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java @@ -57,8 +57,12 @@ public TableSchema getSchema() { public boolean next() throws SQLException { checkClosed(); - Map currentRow = reader.next(); - return currentRow != null; + try { + Map currentRow = reader.next(); + return currentRow != null; + } catch (Exception e) { + throw ExceptionUtils.toSqlState(e); + } } @Override diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java index 79d1621ed..c8757a62b 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java @@ -308,7 +308,7 @@ public void setShardingKeyTest() throws SQLException { assertThrows(SQLFeatureNotSupportedException.class, () -> localConnection.setShardingKey(null, null)); } - @Test + @Test(groups = { "integration" }) public void testMaxResultRowsProperty() throws Exception { Properties properties = new Properties(); properties.setProperty(Driver.chSettingKey(ServerSettings.MAX_RESULT_ROWS), "5"); @@ -323,7 +323,7 @@ public void testMaxResultRowsProperty() throws Exception { } } - @Test + @Test(groups = { "integration" }) public void testSecureConnection() throws Exception { if (isCloud()) { return; // this test uses self-signed cert @@ -357,7 +357,7 @@ public void testSecureConnection() throws Exception { } } - @Test + @Test(groups = { "integration" }) public void testSelectingDatabase() throws Exception { ClickHouseNode server = getServer(ClickHouseProtocol.HTTP); Properties properties = new Properties(); @@ -394,4 +394,14 @@ public void testSelectingDatabase() throws Exception { Assert.assertEquals(rs.getString(1), "system"); } } + + @Test(groups = { "integration" }) + public void testUnwrapping() throws Exception { + Connection conn = getJdbcConnection(); + Assert.assertTrue(conn.isWrapperFor(Connection.class)); + Assert.assertTrue(conn.isWrapperFor(JdbcV2Wrapper.class)); + Assert.assertEquals(conn.unwrap(Connection.class), conn); + Assert.assertEquals(conn.unwrap(JdbcV2Wrapper.class), conn); + assertThrows(SQLException.class, () -> conn.unwrap(ResultSet.class)); + } } From 636f428b264694bd13362ffcf3f0011ee686ab05 Mon Sep 17 00:00:00 2001 From: Paultagoras Date: Fri, 13 Dec 2024 16:38:31 -0500 Subject: [PATCH 13/16] Add SimpleAggregateFunction support --- .../internal/BinaryStreamReader.java | 3 +- .../clickhouse/client/query/QueryTests.java | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java index 24ce0bd6d..2aa6671d2 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java @@ -210,7 +210,8 @@ public T readValue(ClickHouseColumn column, Class typeHint) throws IOExce return (T) readTuple(column); case Nothing: return null; -// case SimpleAggregateFunction: + case SimpleAggregateFunction: + return (T) readValue(column.getNestedColumns().get(0)); case AggregateFunction: return (T) readBitmap( column); default: diff --git a/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java b/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java index 28046896f..d77056483 100644 --- a/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java @@ -52,6 +52,7 @@ import java.net.Inet4Address; import java.net.Inet6Address; import java.net.InetAddress; +import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; @@ -62,6 +63,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Random; @@ -73,6 +75,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; @@ -1929,4 +1932,29 @@ protected Client.Builder newClient() { .allowBinaryReaderToReuseBuffers(usePreallocatedBuffers) .useNewImplementation(System.getProperty("client.tests.useNewImplementation", "true").equals("true")); } + + @Test(groups = {"integration"}) + public void testReadingSimpleAggregateFunction() throws Exception { + final String tableName = "simple_aggregate_function_test_table"; + client.execute("DROP TABLE IF EXISTS " + tableName).get(); + client.execute("CREATE TABLE `" + tableName + "` " + + "(idx UInt8, lowest_value SimpleAggregateFunction(min, UInt8), count SimpleAggregateFunction(sum, Int64), mp SimpleAggregateFunction(maxMap, Map(UInt8, UInt8))) " + + "ENGINE Memory;").get(); + + + try (InsertResponse response = client.insert(tableName, new ByteArrayInputStream("1\t2\t3\t{1:2}".getBytes(StandardCharsets.UTF_8)), ClickHouseFormat.TSV).get(30, TimeUnit.SECONDS)) { + Assert.assertEquals(response.getWrittenRows(), 1); + } + + try (QueryResponse queryResponse = client.query("SELECT * FROM " + tableName + " LIMIT 1").get(30, TimeUnit.SECONDS)) { + + ClickHouseBinaryFormatReader reader = client.newBinaryFormatReader(queryResponse); + Assert.assertNotNull(reader.next()); + Assert.assertEquals(reader.getByte("idx"), Byte.valueOf("1")); + Assert.assertEquals((Short) reader.readValue("lowest_value"), Short.parseShort("2")); + Assert.assertEquals((Long) reader.readValue("count"), Long.parseLong("3")); + Assert.assertEquals(String.valueOf((LinkedHashMap) reader.readValue("mp")), "{1=2}"); + Assert.assertFalse(reader.hasNext()); + } + } } From 758f7651bbfa992e567eafed5812787a8d14611f Mon Sep 17 00:00:00 2001 From: restrry Date: Mon, 16 Dec 2024 15:49:24 +0100 Subject: [PATCH 14/16] add a link to parent issue --- .github/pull_request_template.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 6a83210ee..06d9934c1 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -3,6 +3,7 @@ ## Checklist Delete items not relevant to your PR: +- [ ] Closes issue - [ ] Unit and integration tests covering the common scenarios were added - [ ] A human-readable description of the changes was provided to include in CHANGELOG - [ ] For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials From 0e4ecfc904d85b84ba157fdb22f301c6465375d6 Mon Sep 17 00:00:00 2001 From: Paultagoras Date: Tue, 17 Dec 2024 11:45:48 -0500 Subject: [PATCH 15/16] No-op flags --- .../com/clickhouse/jdbc/ConnectionImpl.java | 98 +++- .../jdbc/PreparedStatementImpl.java | 4 +- .../com/clickhouse/jdbc/ResultSetImpl.java | 514 ++++++++++++++---- .../com/clickhouse/jdbc/StatementImpl.java | 23 +- 4 files changed, 498 insertions(+), 141 deletions(-) diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java index 05c96491b..91f13e13b 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java @@ -118,14 +118,22 @@ public PreparedStatement prepareStatement(String sql) throws SQLException { @Override public CallableStatement prepareCall(String sql) throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("CallableStatement not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("CallableStatement not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public String nativeSQL(String sql) throws SQLException { checkOpen(); /// TODO: this is not implemented according to JDBC spec and may not be used. - throw new SQLFeatureNotSupportedException("nativeSQL not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("nativeSQL not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override @@ -181,7 +189,7 @@ public DatabaseMetaData getMetaData() throws SQLException { @Override public void setReadOnly(boolean readOnly) throws SQLException { checkOpen(); - if (readOnly) { + if (!config.isIgnoreUnsupportedRequests() && readOnly) { throw new SQLFeatureNotSupportedException("read-only=true unsupported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); } } @@ -206,7 +214,7 @@ public String getCatalog() throws SQLException { @Override public void setTransactionIsolation(int level) throws SQLException { checkOpen(); - if (TRANSACTION_NONE != level) { + if (!config.isIgnoreUnsupportedRequests() && TRANSACTION_NONE != level) { throw new SQLFeatureNotSupportedException("setTransactionIsolation not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); } } @@ -243,19 +251,29 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res @Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("CallableStatement not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("CallableStatement not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public Map> getTypeMap() throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("getTypeMap not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("getTypeMap not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public void setTypeMap(Map> map) throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("setTypeMap not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("setTypeMap not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override @@ -273,13 +291,21 @@ public int getHoldability() throws SQLException { @Override public Savepoint setSavepoint() throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("Savepoint not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Savepoint not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public Savepoint setSavepoint(String name) throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("Savepoint not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Savepoint not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override @@ -293,7 +319,9 @@ public void rollback(Savepoint savepoint) throws SQLException { @Override public void releaseSavepoint(Savepoint savepoint) throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("Savepoint not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Savepoint not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override @@ -311,7 +339,11 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res @Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("CallableStatement not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("CallableStatement not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override @@ -350,25 +382,41 @@ public PreparedStatement prepareStatement(String sql, String[] columnNames) thro @Override public Clob createClob() throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("Clob not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Clob not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public Blob createBlob() throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("Blob not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Blob not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public NClob createNClob() throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("NClob not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("NClob not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public SQLXML createSQLXML() throws SQLException { checkOpen(); - throw new SQLFeatureNotSupportedException("SQLXML not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("SQLXML not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override @@ -445,7 +493,11 @@ public Array createArrayOf(String typeName, Object[] elements) throws SQLExcepti @Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { //TODO: Should this be supported? - throw new SQLFeatureNotSupportedException("createStruct not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("createStruct not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override @@ -462,19 +514,27 @@ public String getSchema() throws SQLException { @Override public void abort(Executor executor) throws SQLException { - throw new SQLFeatureNotSupportedException("abort not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("abort not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { //TODO: Should this be supported? - throw new SQLFeatureNotSupportedException("setNetworkTimeout not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("setNetworkTimeout not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public int getNetworkTimeout() throws SQLException { //TODO: Should this be supported? - throw new SQLFeatureNotSupportedException("getNetworkTimeout not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("getNetworkTimeout not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return -1; } @Override diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java index 36f89640d..0f6029942 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java @@ -235,7 +235,9 @@ public void setCharacterStream(int parameterIndex, Reader x, int length) throws @Override public void setRef(int parameterIndex, Ref x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Ref is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Ref is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java index 9faab4c1f..2ab8ed274 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java @@ -310,20 +310,32 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException { public InputStream getAsciiStream(int columnIndex) throws SQLException { checkClosed(); //TODO: Add this to ClickHouseBinaryFormatReader - throw new SQLFeatureNotSupportedException("AsciiStream is not yet supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("AsciiStream is not yet supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public InputStream getUnicodeStream(int columnIndex) throws SQLException { checkClosed(); - return new ByteArrayInputStream(reader.getString(columnIndex).getBytes(StandardCharsets.UTF_8)); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + return new ByteArrayInputStream(reader.getString(columnIndex).getBytes(StandardCharsets.UTF_8)); + } + + return null; } @Override public InputStream getBinaryStream(int columnIndex) throws SQLException { checkClosed(); //TODO: implement - throw new SQLFeatureNotSupportedException("BinaryStream is not yet supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("BinaryStream is not yet supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override @@ -542,7 +554,11 @@ public Timestamp getTimestamp(String columnLabel) throws SQLException { public InputStream getAsciiStream(String columnLabel) throws SQLException { checkClosed(); //TODO: Add this to ClickHouseBinaryFormatReader - throw new SQLFeatureNotSupportedException("AsciiStream is not yet supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("AsciiStream is not yet supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override @@ -555,7 +571,11 @@ public InputStream getUnicodeStream(String columnLabel) throws SQLException { public InputStream getBinaryStream(String columnLabel) throws SQLException { checkClosed(); //TODO: implement - throw new SQLFeatureNotSupportedException("BinaryStream is not yet supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("BinaryStream is not yet supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override @@ -626,13 +646,21 @@ public int findColumn(String columnLabel) throws SQLException { @Override public Reader getCharacterStream(int columnIndex) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("CharacterStream is not yet supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("CharacterStream is not yet supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public Reader getCharacterStream(String columnLabel) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("CharacterStream is not yet supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("CharacterStream is not yet supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override @@ -670,25 +698,41 @@ public BigDecimal getBigDecimal(String columnLabel) throws SQLException { @Override public boolean isBeforeFirst() throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("isBeforeFirst is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("isBeforeFirst is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return false; } @Override public boolean isAfterLast() throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("isAfterLast is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("isAfterLast is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return false; } @Override public boolean isFirst() throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("isFirst is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("isFirst is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return false; } @Override public boolean isLast() throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("isLast is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("isLast is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return false; } @Override @@ -704,37 +748,63 @@ public void afterLast() throws SQLException { @Override public boolean first() throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("first is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("first is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return false; } @Override public boolean last() throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("last is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("last is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return false; } @Override public int getRow() throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("getRow is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("getRow is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return 0; } @Override public boolean absolute(int row) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("absolute is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("absolute is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return false; } @Override public boolean relative(int rows) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("relative is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("relative is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return false; } @Override public boolean previous() throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("previous is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("previous is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return false; } @Override @@ -746,7 +816,9 @@ public int getFetchDirection() throws SQLException { @Override public void setFetchDirection(int direction) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("setFetchDirection is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("setFetchDirection is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override @@ -775,247 +847,335 @@ public int getConcurrency() throws SQLException { @Override public boolean rowUpdated() throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return false; } @Override public boolean rowInserted() throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return false; } @Override public boolean rowDeleted() throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return false; } @Override public void updateNull(int columnIndex) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBoolean(int columnIndex, boolean x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateByte(int columnIndex, byte x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateShort(int columnIndex, short x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateInt(int columnIndex, int x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateLong(int columnIndex, long x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateFloat(int columnIndex, float x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateDouble(int columnIndex, double x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateString(int columnIndex, String x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBytes(int columnIndex, byte[] x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateDate(int columnIndex, Date x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateTime(int columnIndex, Time x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateObject(int columnIndex, Object x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateNull(String columnLabel) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBoolean(String columnLabel, boolean x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateByte(String columnLabel, byte x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateShort(String columnLabel, short x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateInt(String columnLabel, int x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateLong(String columnLabel, long x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateFloat(String columnLabel, float x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateDouble(String columnLabel, double x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateString(String columnLabel, String x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBytes(String columnLabel, byte[] x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateDate(String columnLabel, Date x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateTime(String columnLabel, Time x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateObject(String columnLabel, Object x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override @@ -1068,19 +1228,31 @@ public Object getObject(int columnIndex, Map> map) throws SQLEx @Override public Ref getRef(int columnIndex) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Ref is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Ref is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public Blob getBlob(int columnIndex) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Blob is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Blob is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public java.sql.Clob getClob(int columnIndex) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Clob is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Clob is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override @@ -1098,19 +1270,31 @@ public Object getObject(String columnLabel, Map> map) throws SQ @Override public Ref getRef(String columnLabel) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Ref is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Ref is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public Blob getBlob(String columnLabel) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Blob is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Blob is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public Clob getClob(String columnLabel) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Clob is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Clob is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override @@ -1183,49 +1367,65 @@ public URL getURL(String columnLabel) throws SQLException { @Override public void updateRef(int columnIndex, Ref x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateRef(String columnLabel, Ref x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBlob(int columnIndex, Blob x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBlob(String columnLabel, Blob x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateClob(int columnIndex, Clob x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateClob(String columnLabel, Clob x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateArray(int columnIndex, java.sql.Array x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateArray(String columnLabel, java.sql.Array x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override @@ -1243,13 +1443,17 @@ public RowId getRowId(String columnLabel) throws SQLException { @Override public void updateRowId(int columnIndex, RowId x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateRowId(String columnLabel, RowId x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override @@ -1266,61 +1470,89 @@ public boolean isClosed() throws SQLException { @Override public void updateNString(int columnIndex, String nString) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateNString(String columnLabel, String nString) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateNClob(int columnIndex, NClob nClob) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateNClob(String columnLabel, NClob nClob) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public NClob getNClob(int columnIndex) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("NClob is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("NClob is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public NClob getNClob(String columnLabel) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("NClob is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("NClob is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public SQLXML getSQLXML(int columnIndex) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("SQLXML is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("SQLXML is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public SQLXML getSQLXML(String columnLabel) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("SQLXML is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("SQLXML is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } + + return null; } @Override public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override @@ -1350,169 +1582,225 @@ public Reader getNCharacterStream(String columnLabel) throws SQLException { @Override public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateClob(int columnIndex, Reader reader) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateClob(String columnLabel, Reader reader) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateNClob(int columnIndex, Reader reader) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override public void updateNClob(String columnLabel, Reader reader) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!parentStatement.connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Writes are not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java index 8ad9bc0ef..fedb77d2e 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java @@ -209,7 +209,9 @@ public int getMaxFieldSize() throws SQLException { @Override public void setMaxFieldSize(int max) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Set max field size is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Set max field size is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override @@ -226,7 +228,8 @@ public void setMaxRows(int max) throws SQLException { @Override public void setEscapeProcessing(boolean enable) throws SQLException { - + checkClosed(); + //TODO: Should we support this? } @Override @@ -258,17 +261,18 @@ public void cancel() throws SQLException { @Override public SQLWarning getWarnings() throws SQLException { + checkClosed(); return null; } @Override public void clearWarnings() throws SQLException { - + checkClosed(); } @Override public void setCursorName(String name) throws SQLException { - + checkClosed(); } @Override @@ -339,7 +343,9 @@ public boolean getMoreResults() throws SQLException { @Override public void setFetchDirection(int direction) throws SQLException { checkClosed(); - throw new SQLFeatureNotSupportedException("Set fetch direction is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + if (!connection.config.isIgnoreUnsupportedRequests()) { + throw new SQLFeatureNotSupportedException("Set fetch direction is not supported.", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED); + } } @Override @@ -350,11 +356,12 @@ public int getFetchDirection() throws SQLException { @Override public void setFetchSize(int rows) throws SQLException { - + checkClosed(); } @Override public int getFetchSize() throws SQLException { + checkClosed(); return 0; } @@ -451,7 +458,7 @@ public boolean isClosed() throws SQLException { @Override public void setPoolable(boolean poolable) throws SQLException { - + checkClosed(); } @Override @@ -461,7 +468,7 @@ public boolean isPoolable() throws SQLException { @Override public void closeOnCompletion() throws SQLException { - + checkClosed(); } @Override From 3b6fc1ca2caad8dad72775273dfd80b80c145886 Mon Sep 17 00:00:00 2001 From: Paultagoras Date: Tue, 17 Dec 2024 11:58:22 -0500 Subject: [PATCH 16/16] Adding IPs to the test values --- .../com/clickhouse/jdbc/StatementTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java index 63136414b..a519c338e 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java @@ -4,6 +4,8 @@ import org.testng.Assert; import org.testng.annotations.Test; +import java.net.Inet4Address; +import java.net.Inet6Address; import java.sql.Array; import java.sql.Connection; import java.sql.Date; @@ -428,4 +430,23 @@ public void testWithComments() throws Exception { assertEquals(StatementImpl.parseStatementType(""), StatementImpl.StatementType.OTHER); assertEquals(StatementImpl.parseStatementType(" "), StatementImpl.StatementType.OTHER); } + + + @Test(groups = { "integration" }) + public void testWithIPs() throws Exception { + try (Connection conn = getJdbcConnection()) { + try (Statement stmt = conn.createStatement()) { + try (ResultSet rs = stmt.executeQuery("SELECT toIPv4('127.0.0.1'), toIPv6('::1'), toIPv6('2001:438:ffff::407d:1bc1')")) { + assertTrue(rs.next()); + assertEquals(rs.getString(1), "/127.0.0.1"); + assertEquals(rs.getObject(1), Inet4Address.getByName("127.0.0.1")); + assertEquals(rs.getString(2), "/0:0:0:0:0:0:0:1"); + assertEquals(rs.getObject(2), Inet6Address.getByName("0:0:0:0:0:0:0:1")); + assertEquals(rs.getString(3), "/2001:438:ffff:0:0:0:407d:1bc1"); + assertEquals(rs.getObject(3), Inet6Address.getByName("2001:438:ffff:0:0:0:407d:1bc1")); + assertFalse(rs.next()); + } + } + } + } }