Skip to content

Commit 9df5c71

Browse files
committed
Merge branch 'main' into repo_review_dependencies
2 parents 537c2e8 + a607f93 commit 9df5c71

File tree

15 files changed

+276
-142
lines changed

15 files changed

+276
-142
lines changed

.github/workflows/run_examples.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Run Examples
2+
3+
on:
4+
workflow_dispatch:
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.number || github.sha }}
8+
cancel-in-progress: true
9+
10+
jobs:
11+
compile:
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 15
14+
name: Compile (JDK 8)
15+
steps:
16+
- name: Check out repository
17+
uses: actions/checkout@v4
18+
- name: Check out PR
19+
run: |
20+
git fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 \
21+
origin pull/${{ github.event.inputs.pr }}/merge:merged-pr && git checkout merged-pr
22+
if: github.event.inputs.pr != ''
23+
- name: Install JDK 8 and Maven
24+
uses: actions/setup-java@v4
25+
with:
26+
distribution: "temurin"
27+
java-version: |
28+
8
29+
21
30+
cache: "maven"
31+
- name: Save Repo Artifacts
32+
id: save-repo-artifacts
33+
uses: actions/cache/save@v4
34+
with:
35+
path: ~/.m2/repository/com/clickhouse
36+
key: ${{ github.run_id }}-ch-artifacts
37+
- name: Build and install libraries
38+
run: mvn --batch-mode --no-transfer-progress --show-version --strict-checksums --threads 2 -Dmaven.wagon.rto=30000 -Dj8 -DskipITs install
39+
- name: Compile examples
40+
run: |
41+
cd examples/jdbc
42+
mvn clean compile
43+
echo "Run Id ${{ github.run_id }}"
44+
run-examples:
45+
runs-on: ubuntu-latest
46+
timeout-minutes: 15
47+
name: Run Examples
48+
needs: compile
49+
steps:
50+
- name: Check out repository
51+
uses: actions/checkout@v4
52+
- name: Restore Repo Artifacts
53+
id: restore-repo-artifacts
54+
uses: actions/cache/restore@v4
55+
with:
56+
path: ~/.m2/repository/com/clickhouse
57+
key: ${{ github.run_id }}-ch-artifacts
58+
- name: Run Examples
59+
run: |
60+
docker run -d --name demo-service-db -e CLICKHOUSE_USER=default -e CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 -e CLICKHOUSE_PASSWORD=secret -p 8123:8123 clickhouse/clickhouse-server:24.8
61+
cd examples/jdbc
62+
mvn --batch-mode --no-transfer-progress --show-version clean compile
63+
mvn exec:java -Dexec.mainClass="com.clickhouse.examples.jdbc.Basic" -DchPassword=secret -DfailOnError=true

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ Historically, there are two versions of both components. The previous version of
5353

5454
## Important
5555

56+
### Artifact Changes in 0.9.0 (June)
57+
58+
We are going to retire some JDBC artifacts (actually only classifiers) in *0.9.0*. Here is the list:
59+
| Artifact | Classifier | Comments |
60+
|-----------------|---------|----------------------|
61+
| clickhouse-jdbc | shaded | Use one with `all` classifier instead |
62+
| clickhouse-jdbc | http | |
63+
| clickhouse-jdbc | shaded-all | Use one with `all` classifier instead |
64+
65+
Artifact `com.clickhouse:clickhouse-jdbc` remains untouched.
66+
Artifact `com.clickhouse:clickhouse-jdbc:0.9.0:all` will contain all required classes.
67+
5668
### Upcoming deprecations:
5769
| Component | Version | Comment |
5870
|--------------------------------|---------|--------------------------------------------------|

clickhouse-client/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<configuration>
8888
<excludes>
8989
<exclude>META-INF/services/*</exclude>
90+
<exclude>com/clickhouse/client/ClickHouseTestClient.class</exclude>
9091
</excludes>
9192
</configuration>
9293
</execution>

clickhouse-data/src/test/java/com/clickhouse/data/ClickHouseSimpleRecordTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public void testNullInput() {
2828
public void testMismatchedColumnsAndValues() {
2929

3030
Assert.assertThrows(IllegalArgumentException.class, () -> ClickHouseSimpleRecord
31-
.of(Map.of("a", 0), new ClickHouseValue[0]));
31+
.of(Collections.singletonMap("a", 0), new ClickHouseValue[0]));
3232

33-
ClickHouseSimpleRecord record = new ClickHouseSimpleRecord(Map.of("a", 0),
33+
ClickHouseSimpleRecord record = new ClickHouseSimpleRecord(Collections.singletonMap("a", 0),
3434
new ClickHouseValue[0]);
3535
Assert.assertEquals(record.getValues(), new ClickHouseValue[0]);
3636
}

examples/jdbc/src/main/java/com/clickhouse/examples/jdbc/Basic.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,23 @@ public class Basic {
2121
private static final Logger log = LoggerFactory.getLogger(Basic.class);
2222
static final String TABLE_NAME = "jdbc_example_basic";
2323

24-
public static void main(String[] args) {
24+
public static void main(String[] args) throws Exception {
2525
String url = System.getProperty("chUrl", "jdbc:ch://localhost:8123");
2626

2727
// Set user and password if needed
2828
Properties properties = new Properties();
2929
properties.setProperty("user", System.getProperty("chUser", "default"));
3030
properties.setProperty("password", System.getProperty("chPassword", ""));
3131

32-
try {
33-
createTable(url, properties);
34-
insertDateWithPreparedStatement(url, properties);
35-
printInsertedData(url, properties);
32+
createTable(url, properties);
33+
insertDateWithPreparedStatement(url, properties);
34+
printInsertedData(url, properties);
3635

37-
//Customizing client settings
38-
setClientSettings(properties);
36+
//Customizing client settings
37+
setClientSettings(properties);
3938

40-
//Using HikariCP with ClickHouseDataSource
41-
usedPooledConnection(url, properties);
42-
} catch (SQLException e) {
43-
log.error("Error", e);
44-
}
39+
//Using HikariCP with ClickHouseDataSource
40+
usedPooledConnection(url, properties);
4541
}
4642

4743
static void createTable(String url, Properties properties) throws SQLException {

jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/ClickHouseParser.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ topClause
382382

383383
fromClause
384384
: FROM joinExpr
385+
| FROM identifier LPAREN QUERY RPAREN
385386
;
386387

387388
arrayJoinClause

jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@
3333
import java.sql.SQLWarning;
3434
import java.sql.SQLXML;
3535
import java.sql.Savepoint;
36-
import java.sql.ShardingKey;
3736
import java.sql.Statement;
3837
import java.sql.Struct;
38+
import java.util.Arrays;
3939
import java.util.Calendar;
40+
import java.util.Collections;
4041
import java.util.HashSet;
4142
import java.util.List;
4243
import java.util.Map;
4344
import java.util.Properties;
4445
import java.util.Set;
4546
import java.util.concurrent.Executor;
47+
import java.util.stream.Collectors;
4648

4749
public class ConnectionImpl implements Connection, JdbcV2Wrapper {
4850
private static final Logger log = LoggerFactory.getLogger(ConnectionImpl.class);
@@ -548,7 +550,9 @@ public Properties getClientInfo() throws SQLException {
548550
@Override
549551
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
550552
try {
551-
return new com.clickhouse.jdbc.types.Array(List.of(elements), typeName, JdbcUtils.convertToSqlType(ClickHouseDataType.valueOf(typeName)).getVendorTypeNumber());
553+
List<Object> list =
554+
(elements == null || elements.length == 0) ? Collections.emptyList() : Arrays.stream(elements, 0, elements.length).collect(Collectors.toList());
555+
return new com.clickhouse.jdbc.types.Array(list, typeName, JdbcUtils.convertToSqlType(ClickHouseDataType.valueOf(typeName)).getVendorTypeNumber());
552556
} catch (Exception e) {
553557
throw new SQLException("Failed to create array", ExceptionUtils.SQL_STATE_CLIENT_ERROR, e);
554558
}
@@ -601,36 +605,6 @@ public int getNetworkTimeout() throws SQLException {
601605
return -1;
602606
}
603607

604-
@Override
605-
public void beginRequest() throws SQLException {
606-
Connection.super.beginRequest();
607-
}
608-
609-
@Override
610-
public void endRequest() throws SQLException {
611-
Connection.super.endRequest();
612-
}
613-
614-
@Override
615-
public boolean setShardingKeyIfValid(ShardingKey shardingKey, ShardingKey superShardingKey, int timeout) throws SQLException {
616-
return Connection.super.setShardingKeyIfValid(shardingKey, superShardingKey, timeout);
617-
}
618-
619-
@Override
620-
public boolean setShardingKeyIfValid(ShardingKey shardingKey, int timeout) throws SQLException {
621-
return Connection.super.setShardingKeyIfValid(shardingKey, timeout);
622-
}
623-
624-
@Override
625-
public void setShardingKey(ShardingKey shardingKey, ShardingKey superShardingKey) throws SQLException {
626-
Connection.super.setShardingKey(shardingKey, superShardingKey);
627-
}
628-
629-
@Override
630-
public void setShardingKey(ShardingKey shardingKey) throws SQLException {
631-
Connection.super.setShardingKey(shardingKey);
632-
}
633-
634608
/**
635609
* Returns instance of the client used to execute queries by this connection.
636610
* @return - client instance

jdbc-v2/src/main/java/com/clickhouse/jdbc/DataSourceImpl.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import javax.sql.DataSource;
66
import java.io.PrintWriter;
77
import java.sql.Connection;
8-
import java.sql.ConnectionBuilder;
98
import java.sql.SQLException;
109
import java.sql.SQLFeatureNotSupportedException;
11-
import java.sql.ShardingKeyBuilder;
1210
import java.util.Properties;
1311
import java.util.logging.Logger;
1412

@@ -78,18 +76,8 @@ public int getLoginTimeout() throws SQLException {
7876
throw new SQLFeatureNotSupportedException("Method not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
7977
}
8078

81-
@Override
82-
public ConnectionBuilder createConnectionBuilder() throws SQLException {
83-
return DataSource.super.createConnectionBuilder();
84-
}
85-
8679
@Override
8780
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
8881
throw new SQLFeatureNotSupportedException("Method not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
8982
}
90-
91-
@Override
92-
public ShardingKeyBuilder createShardingKeyBuilder() throws SQLException {
93-
return DataSource.super.createShardingKeyBuilder();
94-
}
9583
}

jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,21 +403,29 @@ public ResultSetMetaData getMetaData() throws SQLException {
403403

404404
private static final Pattern REPLACE_Q_MARK_PATTERN = Pattern.compile("(\"[^\"]*\"|`[^`]*`|'[^']*')|(\\?)");
405405

406-
public static String replaceQuestionMarks(String sql, String replacement) {
406+
public static String replaceQuestionMarks(String sql, final String replacement) {
407407
Matcher matcher = REPLACE_Q_MARK_PATTERN.matcher(sql);
408408

409409
StringBuilder result = new StringBuilder();
410410

411+
int lastPos = 0;
411412
while (matcher.find()) {
412-
if (matcher.group(1) != null) {
413+
String text;
414+
if ((text = matcher.group(1)) != null) {
413415
// Quoted string — keep as-is
414-
matcher.appendReplacement(result, Matcher.quoteReplacement(matcher.group(1)));
416+
String str = Matcher.quoteReplacement(text);
417+
result.append(sql, lastPos, matcher.start()).append(str);
418+
lastPos = matcher.end();
415419
} else if (matcher.group(2) != null) {
416420
// Question mark outside quotes — replace it
417-
matcher.appendReplacement(result, Matcher.quoteReplacement(replacement));
421+
String str = Matcher.quoteReplacement(replacement);
422+
result.append(sql, lastPos, matcher.start()).append(str);
423+
lastPos = matcher.end();
418424
}
419425
}
420-
matcher.appendTail(result);
426+
427+
// Add rest of the `sql`
428+
result.append(sql, lastPos, sql.length());
421429
return result.toString();
422430
}
423431

jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -526,30 +526,6 @@ public long executeLargeUpdate(String sql, String[] columnNames) throws SQLExcep
526526
return executeUpdate(sql, columnNames);
527527
}
528528

529-
@Override
530-
public String enquoteLiteral(String val) throws SQLException {
531-
checkClosed();
532-
return Statement.super.enquoteLiteral(val);
533-
}
534-
535-
@Override
536-
public String enquoteIdentifier(String identifier, boolean alwaysQuote) throws SQLException {
537-
checkClosed();
538-
return Statement.super.enquoteIdentifier(identifier, alwaysQuote);
539-
}
540-
541-
@Override
542-
public boolean isSimpleIdentifier(String identifier) throws SQLException {
543-
checkClosed();
544-
return Statement.super.isSimpleIdentifier(identifier);
545-
}
546-
547-
@Override
548-
public String enquoteNCharLiteral(String val) throws SQLException {
549-
checkClosed();
550-
return Statement.super.enquoteNCharLiteral(val);
551-
}
552-
553529
/**
554530
* Return query ID of last executed statement. It is not guaranteed when statements is used concurrently.
555531
* @return query ID

0 commit comments

Comments
 (0)