Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 43 additions & 0 deletions tests/clickhouse-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# clickhouse-client-cli

A simple CLI tool that mimics `clickhouse-client` for executing SQL queries against a ClickHouse server.
Used to test with ClickHouse test framework designed for `clickhouse-client` (https://github.com/ClickHouse/ClickHouse/blob/master/tests/clickhouse-test).
Note: do not clone ClickHouse repo - it takes a lot of time. Download zip instead.

## Build Java Application

```bash
cd tests/clickhouse-client
mvn package -DskipTests
```

This produces an executable fat JAR at `target/clickhouse-client-cli-1.0.0.jar`.

## Wrapper executable

A wrapper script named `clickhouse-client` is provided in `bin/` directory. It is a simple shell script that calls
java application. It is required because `clickhouse-test` script calls `clickhouse-client` binary found in `PATH` environment variable.
It is recommended to set `PATH` locally in terminal session to not override real `clickhouse-client`.

## Environment variables

| Variable | Description |
|---|---|
| `CLICKHOUSE_CLIENT_CLI_IMPL` | Backend implementation to use: `client` (default, uses client-v2 API) or `jdbc` (uses ClickHouse JDBC driver) |
| `CLICKHOUSE_CLIENT_CLI_LOG` | Path to log file for troubleshooting |

## Examples

Run tests using the default client-v2 backend:

```shell
cd ClickHouse-master
CLICKHOUSE_CLIENT_CLI_LOG=./test-run.log PATH="$PATH:/home/someuser/clickhouse-java/tests/clickhouse-client/bin/" tests/clickhouse-test 01428_hash_set_nan_key
```

Run tests using the JDBC backend:

```shell
cd ClickHouse-master
CLICKHOUSE_CLIENT_CLI_IMPL=jdbc CLICKHOUSE_CLIENT_CLI_LOG=./test-run.log PATH="$PATH:/home/someuser/clickhouse-java/tests/clickhouse-client/bin/" tests/clickhouse-test 01428_hash_set_nan_key
```
39 changes: 39 additions & 0 deletions tests/clickhouse-client/bin/clickhouse
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
JAR_PATH="${SCRIPT_DIR}/../target/clickhouse-client-cli-1.0.0.jar"

if [[ "${1:-}" == "extract-from-config" ]]; then
shift
key=""
while [[ $# -gt 0 ]]; do
case "$1" in
--key)
key="${2:-}"
shift 2
;;
--key=*)
key="${1#--key=}"
shift
;;
*)
shift
;;
esac
done

# Minimal compatibility for clickhouse-test usage.
if [[ "${key}" == "listen_host" ]]; then
echo "127.0.0.1"
fi
exit 0
fi

if [[ ! -f "${JAR_PATH}" ]]; then
echo "Jar not found: ${JAR_PATH}" >&2
echo "Build it first: (cd ${SCRIPT_DIR} && mvn package -DskipTests)" >&2
exit 1
fi

exec java -jar "${JAR_PATH}" "$@"
92 changes: 92 additions & 0 deletions tests/clickhouse-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-client-cli</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>clickhouse-client-cli</name>
<description>Simple CLI tool that mimics clickhouse-client for executing SQL queries</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<clickhouse-java.version>0.9.6-SNAPSHOT</clickhouse-java.version>
<main.class>com.clickhouse.client.cli.Main</main.class>
</properties>

<dependencies>
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>${clickhouse-java.version}</version>
<classifier>all</classifier>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.13</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.13</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${main.class}</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading
Loading