Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge most recent changes on develop branch #1056

Merged
merged 21 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Nightly

on:
schedule:
# Build and publish nightly snapshot at 3:55pm every day
- cron: "55 15 * * *"

env:
CHC_BRANCH: "develop"
CHC_VERSION: "0.3.3"

jobs:
nightly:
if: ${{ startsWith(github.repository, 'ClickHouse/') }}
name: "Build and Publish Nightly Snapshot"
runs-on: "ubuntu-latest"

steps:
- name: Check out Git repository
uses: actions/checkout@v3
with:
ref: ${{ env.CHC_BRANCH }}
- name: Install JDK 11
uses: AdoptOpenJDK/install-jdk@v1
with:
version: "11"
targets: "JDK11_HOME"
- name: Setup Toolchain
shell: bash
run: |
mkdir -p $HOME/.m2 \
&& cat << EOF > $HOME/.m2/toolchains.xml
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>11</version>
</provides>
<configuration>
<jdkHome>${{ env.JDK11_HOME }}</jdkHome>
</configuration>
</toolchain>
</toolchains>
EOF
- name: Install JDK 8 and Maven
uses: actions/setup-java@v2
with:
distribution: "temurin"
java-version: 8
- name: Update Configuration
run: |
find . -type f -name "pom.xml" -exec sed -i -e 's|${revision}|${{ env.CHC_VERSION }}-SNAPSHOT|g' \
-e 's|^\( <version>\).*\(</version>\)$|\1${{ env.CHC_VERSION }}-SNAPSHOT\2|' \
-e 's|${parent.groupId}|com.clickhouse|g' -e 's|${project.parent.groupId}|com.clickhouse|g' '{}' \;
find . -type f -name "simplelogger.*" -exec rm -fv '{}' \;
- name: Release Snapshot
uses: samuelmeuli/action-maven-publish@v1
with:
maven_profiles: release
maven_args: -q --batch-mode
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
nexus_username: ${{ secrets.SONATYPE_USER }}
nexus_password: ${{ secrets.SONATYPE_PASSWD }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*.ear

# VSCode
.bloop
.metals
.vscode
.factorypath

Expand All @@ -33,6 +35,7 @@ target/
# Generated files
.flattened-pom.xml
dependency-reduced-pom.xml
**/parser/javacc/*
**/parser/*CharStream.java
**/parser/ClickHouseSqlParser.java
**/parser/ClickHouseSqlParserConstants.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ protected static int readColumn(String args, int startIndex, int len, String nam
List<ClickHouseColumn> nestedColumns = new LinkedList<>();
for (String p : params) {
if (isFirst) {
int pIndex = p.indexOf('(');
aggFunc = ClickHouseAggregateFunction.of(pIndex > 0 ? p.substring(0, pIndex) : p);
if (matchedKeyword == KEYWORD_AGGREGATE_FUNCTION) {
int pIndex = p.indexOf('(');
aggFunc = ClickHouseAggregateFunction.of(pIndex > 0 ? p.substring(0, pIndex) : p);
}
isFirst = false;
} else {
nestedColumns.add(ClickHouseColumn.of("", p));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ public Builder addOption(String option, String value) {
return this;
}

/**
* Removes an option from this node.
*
* @param option option to be removed, null value will be ignored
* @return this builder
*/
public Builder removeOption(String option) {
if (!ClickHouseChecker.isNullOrEmpty(option)) {
options.remove(option);
}

return this;
}

/**
* Sets all options for this node. Use null or empty value to clear all existing
* options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,12 @@ public int getUpdateCount() {
public boolean isEmpty() {
return progress.get().isEmpty() && stats.get().isEmpty();
}

@Override
public String toString() {
return new StringBuilder().append("ClickHouseResponseSummary [readBytes=").append(getReadBytes())
.append(", readRows=").append(getReadRows()).append(", totalRowsToRead=").append(getTotalRowsToRead())
.append(", writtenBytes=").append(getWrittenBytes()).append(", writtenRows=").append(getWrittenRows())
.append(", updates=").append(getUpdateCount()).append(']').toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ public ClickHouseLongValue update(double value) {

@Override
public ClickHouseLongValue update(BigInteger value) {
return value == null ? resetToNullOrEmpty() : set(false, unsigned, value.longValueExact());
return value == null ? resetToNullOrEmpty() : set(false, unsigned, value.longValue());
}

@Override
public ClickHouseLongValue update(BigDecimal value) {
return value == null ? resetToNullOrEmpty() : set(false, unsigned, value.longValueExact());
return value == null ? resetToNullOrEmpty() : set(false, unsigned, value.longValue());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,11 @@ public void testUnsignedValue() throws Exception {
Assert.assertEquals(v.asBigInteger(), new BigInteger("10223372036854775101"));
Assert.assertEquals(v.asBigDecimal(), new BigDecimal("10223372036854775101"));
Assert.assertEquals(v.asString(), "10223372036854775101");

v.update(new BigDecimal("10223372036854775101"));
Assert.assertEquals(v.asLong(), -8223372036854776515L);
Assert.assertEquals(v.asBigInteger(), new BigInteger("10223372036854775101"));
Assert.assertEquals(v.asBigDecimal(), new BigDecimal("10223372036854775101"));
Assert.assertEquals(v.asString(), "10223372036854775101");
}
}
20 changes: 18 additions & 2 deletions clickhouse-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@
<pattern>org.apache</pattern>
<shadedPattern>${shade.base}.apache</shadedPattern>
</relocation>
<relocation>
<pattern>net.jpountz</pattern>
<shadedPattern>${shade.base}.jpountz</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
Expand Down Expand Up @@ -277,6 +281,20 @@
<createDependencyReducedPom>true</createDependencyReducedPom>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<shadedClassifierName>all</shadedClassifierName>
<relocations>
<relocation>
<pattern>com.google.gson</pattern>
<shadedPattern>${shade.base}.gson</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache</pattern>
<shadedPattern>${shade.base}.apache</shadedPattern>
</relocation>
<relocation>
<pattern>net.jpountz</pattern>
<shadedPattern>${shade.base}.jpountz</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer" />
Expand All @@ -293,9 +311,7 @@
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>com/google/**</exclude>
<exclude>mozilla/**</exclude>
<exclude>org/**</exclude>
<exclude>**/module-info.class</exclude>
<exclude>META-INF/DEPENDENCIES</exclude>
<exclude>META-INF/MANIFEST.MF</exclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import com.clickhouse.client.ClickHouseChecker;
import com.clickhouse.client.ClickHouseClient;
import com.clickhouse.client.ClickHouseConfig;
import com.clickhouse.client.ClickHouseDataStreamFactory;
import com.clickhouse.client.ClickHouseDeserializer;
import com.clickhouse.client.ClickHouseFormat;
import com.clickhouse.client.ClickHouseNode;
import com.clickhouse.client.ClickHouseRequest;
import com.clickhouse.client.ClickHouseResponse;
import com.clickhouse.client.ClickHouseResponseSummary;
Expand Down Expand Up @@ -427,14 +430,27 @@ public void cancel() throws SQLException {

final String qid;
if ((qid = this.queryId) != null) {
ClickHouseClient.send(request.getServer(), String.format("KILL QUERY WHERE query_id='%s'", qid))
.whenComplete((summary, exception) -> {
if (exception != null) {
log.warn("Failed to kill query [%s] due to: %s", qid, exception.getMessage());
} else if (summary != null) {
log.debug("Killed query [%s]", qid);
}
});
String sessionIdKey = ClickHouseClientOption.SESSION_ID.getKey();
ClickHouseNode server = request.getServer();
if (server.getOptions().containsKey(sessionIdKey)) {
server = ClickHouseNode.builder(request.getServer()).removeOption(sessionIdKey)
.removeOption(ClickHouseClientOption.SESSION_CHECK.getKey())
.removeOption(ClickHouseClientOption.SESSION_TIMEOUT.getKey()).build();
}
try {
List<ClickHouseResponseSummary> summaries = ClickHouseClient
.send(server, String.format("KILL QUERY WHERE query_id='%s'", qid))
.get(request.getConfig().getConnectionTimeout(), TimeUnit.MILLISECONDS);
log.info("Killed query [%s]: %s", qid, summaries.get(0));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.warn("Interrupted for killing query [%s]", qid);
} catch (TimeoutException e) {
log.warn("Timed out after waiting %d ms for killing query [%s]",
request.getConfig().getConnectionTimeout(), qid);
} catch (Exception e) { // unexpected
throw SqlExceptionUtils.handle(e.getCause());
}
}
if (request.getTransaction() != null) {
request.getTransaction().abort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ private Object[][] getTimeZoneTestOptions() {
new Object[] { true }, new Object[] { false } };
}

@DataProvider(name = "connectionProperties")
private Object[][] getConnectionProperties() {
Properties emptyProps = new Properties();
Properties sessionProps = new Properties();
sessionProps.setProperty(ClickHouseClientOption.SESSION_ID.getKey(), UUID.randomUUID().toString());
return new Object[][] {
new Object[] { emptyProps }, new Object[] { sessionProps } };
}

@Test(groups = "integration")
public void testJdbcEscapeSyntax() throws SQLException {
try (ClickHouseConnection conn = newConnection(new Properties());
Expand Down Expand Up @@ -237,13 +246,15 @@ public void testAsyncInsert() throws SQLException {
}
}

@Test(groups = "integration")
public void testCancelQuery() throws Exception {
try (ClickHouseConnection conn = newConnection(new Properties());
@Test(dataProvider = "connectionProperties", groups = "integration")
public void testCancelQuery(Properties props) throws Exception {
try (ClickHouseConnection conn = newConnection(props);
ClickHouseStatement stmt = conn.createStatement();) {
CountDownLatch c = new CountDownLatch(1);
ClickHouseClient.submit(() -> stmt.executeQuery("select * from numbers(100000000)")).whenComplete(
(rs, e) -> {
Assert.assertNull(e, "Should NOT have any exception");

int index = 0;

try {
Expand All @@ -252,15 +263,22 @@ public void testCancelQuery() throws Exception {
c.countDown();
}
}
Assert.fail("Query should have been cancelled");
} catch (SQLException ex) {
// ignore
Assert.assertNotNull(ex, "Should end up with exception");
}
});
try {
c.await(5, TimeUnit.SECONDS);
} finally {
stmt.cancel();
}

try (ResultSet rs = stmt.executeQuery("select 5")) {
Assert.assertTrue(rs.next(), "Should have at least one record");
Assert.assertEquals(rs.getInt(1), 5);
Assert.assertFalse(rs.next(), "Should have only one record");
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>1.0.0</version>
<packaging>jar</packaging>

<name>jdbc-examples</name>
<name>JDBC Examples</name>
<description>JDBC Examples</description>
<url>https://github.com/ClickHouse/clickhouse-jdbc</url>
<inceptionYear>2022</inceptionYear>
Expand Down Expand Up @@ -56,7 +56,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<clickhouse-jdbc.version>0.3.2-patch9</clickhouse-jdbc.version>
<clickhouse-jdbc.version>0.3.3-SNAPSHOT</clickhouse-jdbc.version>

<compiler-plugin.version>3.8.1</compiler-plugin.version>

Expand Down
Loading