From 0fc2cb0871cf55b119b60a919b9017d826633557 Mon Sep 17 00:00:00 2001 From: Sergey Chernov Date: Mon, 5 Oct 2026 15:04:36 -0700 Subject: [PATCH 1/7] Reorganized Server for tests as container starter and interface to target server information --- .github/workflows/analysis.yml | 6 +- .github/workflows/build.yml | 115 ++++- .github/workflows/jvm-compatibility.yml | 4 +- .github/workflows/nightly.yml | 4 +- .github/workflows/release.yml | 3 +- .github/workflows/test_head.yml | 10 +- CONTRIBUTING.md | 49 +- .../client/ClickHouseContainerStarter.java | 181 +++++++ .../client/ClickHouseServerForTest.java | 474 +++++++----------- .../client/ClickHouseTestEnvironment.java | 291 +++++++++++ .../client/ClickHouseTestEnvironmentTest.java | 161 ++++++ .../ClusterClickHouseContainerStarter.java | 128 +++++ .../SingleClickHouseContainerStarter.java | 60 +++ .../config.d/custom_config.xml | 87 ++++ .../users.d/cluster_quorum.xml | 9 + .../clickhouse-keeper/keeper_config.xml | 23 + .../resources/containers/nginx/nginx.conf | 79 +++ 17 files changed, 1323 insertions(+), 361 deletions(-) create mode 100644 clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java create mode 100644 clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironment.java create mode 100644 clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironmentTest.java create mode 100644 clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java create mode 100644 clickhouse-client/src/test/java/com/clickhouse/client/SingleClickHouseContainerStarter.java create mode 100644 clickhouse-client/src/test/resources/containers/clickhouse-cluster/config.d/custom_config.xml create mode 100644 clickhouse-client/src/test/resources/containers/clickhouse-cluster/users.d/cluster_quorum.xml create mode 100644 clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml create mode 100644 clickhouse-client/src/test/resources/containers/nginx/nginx.conf diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index c98a35e2e..c8278e037 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -92,14 +92,14 @@ jobs: - name: Build and install run: | find . -type f -name "simplelogger.*" -exec rm -fv '{}' \; - mvn -q --no-transfer-progress --batch-mode -DclickhouseVersion=$PREFERRED_LTS_VERSION \ - -DskipTests install + mvn -q --no-transfer-progress --batch-mode -DskipTests install - name: Generate coverage report env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + TEST_CLICKHOUSE_IMAGE_VERSION: ${{ env.PREFERRED_LTS_VERSION }} run: | - mvn -fn --no-transfer-progress --batch-mode -DclickhouseVersion=$PREFERRED_LTS_VERSION \ + mvn -fn --no-transfer-progress --batch-mode \ -Pcoverage verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=ClickHouse_clickhouse-java continue-on-error: true - name: Generate and post coverage report diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 002a3c3e9..82221c843 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,7 +54,7 @@ jobs: java-version: 21 cache: "maven" - name: Build and install libraries - run: mvn --batch-mode --no-transfer-progress --show-version --strict-checksums --threads 2 -Dmaven.wagon.rto=30000 -Dj8 -DskipITs -DclickhouseVersion=$PREFERRED_LTS_VERSION install + run: mvn --batch-mode --no-transfer-progress --show-version --strict-checksums --threads 2 -Dmaven.wagon.rto=30000 -Dj8 -DskipITs install - name: Copy Artifacts to Build dir run: | mkdir clickhouse-jdbc-artifacts @@ -193,8 +193,10 @@ jobs: - name: Build and install libraries run: mvn --batch-mode --no-transfer-progress --show-version --strict-checksums --threads 2 -Dmaven.wagon.rto=30000 -Dj8 -DskipTests=true -Dmaven.javadoc.skip=true install - name: Test Java client + env: + TEST_CLICKHOUSE_IMAGE_VERSION: ${{ matrix.clickhouse }} run: | - mvn --also-make --batch-mode --no-transfer-progress --projects ${{ matrix.project }} -DclickhouseVersion=${{ matrix.clickhouse }} -Dmaven.javadoc.skip=true verify + mvn --also-make --batch-mode --no-transfer-progress --projects ${{ matrix.project }} -Dmaven.javadoc.skip=true verify - name: Upload test results uses: actions/upload-artifact@v4 if: failure() @@ -210,14 +212,16 @@ jobs: needs: compile strategy: matrix: - # most recent LTS releases as well as latest stable builds - # https://github.com/ClickHouse/ClickHouse/pulls?q=is%3Aopen+is%3Apr+label%3Arelease - clickhouse: ["cloud"] -# project: ["clickhouse-http-client", "clickhouse-jdbc", "client-v2", "jdbc-v2"] project: ["client-v2", "jdbc-v2"] fail-fast: false timeout-minutes: 20 - name: ${{ matrix.project }} + CH ${{ matrix.clickhouse }} + name: ${{ matrix.project }} + ClickHouse Cloud + env: + TEST_CLICKHOUSE_CONTAINER: none + TEST_CLICKHOUSE_SECURE: "true" + TEST_CLICKHOUSE_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT_PROD }} + TEST_CLICKHOUSE_USER: default + TEST_CLICKHOUSE_PASSWORD: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD_SMT_PROD }} steps: - name: Check out repository uses: actions/checkout@v4 @@ -261,12 +265,9 @@ jobs: echo "TEST_DB_NAME=$RANDOM_DB" >> $GITHUB_ENV echo "Generated database name: $RANDOM_DB" - name: Create Temporary Database - env: - CLICKHOUSE_CLOUD_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT_PROD }} - CLICKHOUSE_CLOUD_PASSWORD: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD_SMT_PROD }} run: | echo "Creating database: \`$TEST_DB_NAME\`" - curl --fail-with-body -s -u "default:$CLICKHOUSE_CLOUD_PASSWORD" "https://$CLICKHOUSE_CLOUD_HOST:8443" --data-binary "CREATE DATABASE IF NOT EXISTS $TEST_DB_NAME" + curl --fail-with-body -s -u "$TEST_CLICKHOUSE_USER:$TEST_CLICKHOUSE_PASSWORD" "https://$TEST_CLICKHOUSE_HOST:8443" --data-binary "CREATE DATABASE IF NOT EXISTS $TEST_DB_NAME" - name: Set up Python uses: actions/setup-python@v5 with: @@ -275,38 +276,95 @@ jobs: run: python3 -m pip install -r .github/scripts/requirements.txt - name: Test http client env: - CLICKHOUSE_CLOUD_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT_PROD }} - CLICKHOUSE_CLOUD_PASSWORD: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD_SMT_PROD }} JWT_PKEY: ${{ secrets.JWT_PKEY }} run: | python3 .github/scripts/generate_jwt.py jwt.token JWT_TOKEN="$(cat jwt.token)" rm -f jwt.token export JWT_TOKEN - mvn --batch-mode --no-transfer-progress --projects ${{ matrix.project }} -DclickhouseVersion=${{ matrix.clickhouse }} -Dprotocol=http -Dmaven.javadoc.skip=true verify + mvn --batch-mode --no-transfer-progress --projects ${{ matrix.project }} -Dprotocol=http -Dmaven.javadoc.skip=true verify - name: Upload test results uses: actions/upload-artifact@v4 if: failure() with: - name: result ${{ github.job }}_${{ matrix.project }}_${{ matrix.clickhouse }} + name: result ${{ github.job }}_${{ matrix.project }} path: | **/target/failsafe-reports **/target/surefire-reports - name: Cleanup Database Unconditionally if: always() # CRITICAL: This ensures the step runs regardless of previous success/failure - env: - CLICKHOUSE_CLOUD_HOST: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_HOST_SMT_PROD }} - CLICKHOUSE_CLOUD_PASSWORD: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD_SMT_PROD }} run: | - # Verify we actually generated a DB name to avoid dropping something accidentally + # Verify we actually generated a DB name to avoid dropping something accidentally if [ -n "$TEST_DB_NAME" ]; then - DROP_STMT="DROP DATABASE IF EXISTS \`$TEST_DB_NAME\`" + DROP_STMT="DROP DATABASE IF EXISTS \`$TEST_DB_NAME\`" echo "Cleaning up database: \`$TEST_DB_NAME\` with statement '$DROP_STMT'"; - curl --fail-with-body -s -u "default:$CLICKHOUSE_CLOUD_PASSWORD" "https://$CLICKHOUSE_CLOUD_HOST:8443" --data-binary "$DROP_STMT"; + curl --fail-with-body -s -u "$TEST_CLICKHOUSE_USER:$TEST_CLICKHOUSE_PASSWORD" "https://$TEST_CLICKHOUSE_HOST:8443" --data-binary "$DROP_STMT"; else echo "No database name was generated; skipping cleanup."; fi; + test-with-cluster: + runs-on: ubuntu-latest + needs: compile + strategy: + matrix: + clickhouse: ["25.8", "26.3", "latest"] + project: ["client-v2", "jdbc-v2"] + fail-fast: false + timeout-minutes: 40 + name: ${{ matrix.project }} + CH cluster ${{ matrix.clickhouse }} + env: + TEST_CLICKHOUSE_CONTAINER: cluster + TEST_CLICKHOUSE_IMAGE_VERSION: ${{ matrix.clickhouse }} + steps: + - name: Check out repository + uses: actions/checkout@v4 + - name: Check out PR + run: | + git fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 \ + origin pull/${{ github.event.inputs.pr }}/merge:merged-pr && git checkout merged-pr + if: github.event.inputs.pr != '' + - name: Install JDK 17 and Maven + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: | + 8 + 17 + cache: "maven" + - name: Setup Toolchain + shell: bash + run: | + mkdir -p $HOME/.m2 \ + && cat << EOF > $HOME/.m2/toolchains.xml + + + + jdk + + 17 + + + ${{ env.JAVA_HOME }} + + + + EOF + - name: Install Java client + run: mvn --also-make --batch-mode --no-transfer-progress -DskipTests=true -Dmaven.javadoc.skip=true install + - name: Test ${{ matrix.project }} + run: | + mvn --batch-mode --no-transfer-progress --projects ${{ matrix.project }} -Dmaven.javadoc.skip=true verify + - name: Upload test results + uses: actions/upload-artifact@v4 + if: failure() + with: + name: result ${{ github.job }}_${{ matrix.project }}_${{ matrix.clickhouse }} + path: | + **/target/failsafe-reports + **/target/surefire-reports + retention-days: 5 + test-jdbc-driver: runs-on: ubuntu-latest strategy: @@ -355,8 +413,10 @@ jobs: - name: Install Java client run: mvn --also-make --batch-mode --no-transfer-progress --projects clickhouse-http-client,client-v2 -DskipTests=true -Dmaven.javadoc.skip=true install - name: Test JDBC driver + env: + TEST_CLICKHOUSE_IMAGE_VERSION: ${{ matrix.clickhouse }} run: | - mvn --batch-mode --no-transfer-progress --projects clickhouse-jdbc,jdbc-v2 -DclickhouseVersion=${{ matrix.clickhouse }} -Dprotocol=${{ matrix.protocol }} -Dmaven.javadoc.skip=true verify + mvn --batch-mode --no-transfer-progress --projects clickhouse-jdbc,jdbc-v2 -Dprotocol=${{ matrix.protocol }} -Dmaven.javadoc.skip=true verify - name: Upload test results uses: actions/upload-artifact@v4 if: failure() @@ -415,8 +475,10 @@ jobs: - name: Install Java client run: mvn --also-make --no-transfer-progress --batch-mode --projects clickhouse-jdbc -DskipTests=true -Dmaven.javadoc.skip=true install - name: Test R2DBC ${{ matrix.r2dbc }} + env: + TEST_CLICKHOUSE_IMAGE_VERSION: ${{ matrix.clickhouse }} run: | - mvn --batch-mode --no-transfer-progress --projects clickhouse-r2dbc -DclickhouseVersion=${{ matrix.clickhouse }} \ + mvn --batch-mode --no-transfer-progress --projects clickhouse-r2dbc \ -D'r2dbc-spi.version=${{ matrix.r2dbc }}' -Dprotocol=${{ matrix.protocol }} -Dmaven.javadoc.skip=true verify - name: Upload test results uses: actions/upload-artifact@v4 @@ -468,9 +530,12 @@ jobs: # - name: Install Java client # run: mvn --also-make --batch-mode --no-transfer-progress --projects clickhouse-http-client -Dj8 -DskipTests install # - name: Test JDBC and R2DBC drivers +# env: +# TEST_CLICKHOUSE_IMAGE_VERSION: ${{ env.PREFERRED_LTS_VERSION }} +# TEST_CLICKHOUSE_TIMEZONE: ${{ matrix.serverTz }} # run: | -# mvn --batch-mode --no-transfer-progress --projects clickhouse-jdbc,clickhouse-r2dbc -DclickhouseVersion=$PREFERRED_LTS_VERSION \ -# -DclickhouseTimezone=${{ matrix.serverTz }} -Duser.timezone=${{ matrix.clientTz }} \ +# mvn --batch-mode --no-transfer-progress --projects clickhouse-jdbc,clickhouse-r2dbc \ +# -Duser.timezone=${{ matrix.clientTz }} \ # -Dj8 -DskipUTs verify # - name: Upload test results # uses: actions/upload-artifact@v4 diff --git a/.github/workflows/jvm-compatibility.yml b/.github/workflows/jvm-compatibility.yml index df839dd9f..5e4036494 100644 --- a/.github/workflows/jvm-compatibility.yml +++ b/.github/workflows/jvm-compatibility.yml @@ -122,9 +122,11 @@ jobs: tar -xzf \ "$RUNNER_TEMP/clickhouse-maven-repository/compiled-tests.tar.gz" - name: Test all modules + env: + TEST_CLICKHOUSE_IMAGE_VERSION: ${{ env.PREFERRED_LTS_VERSION }} run: | mvn --batch-mode --no-transfer-progress --show-version --strict-checksums --threads 2 \ - -Dmaven.wagon.rto=30000 -DclickhouseVersion=$PREFERRED_LTS_VERSION -Dj8 \ + -Dmaven.wagon.rto=30000 -Dj8 \ -Pcompile-java11,compile-java17 \ org.apache.maven.plugins:maven-surefire-plugin:3.5.3:test \ org.apache.maven.plugins:maven-failsafe-plugin:3.1.2:integration-test \ diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index f74bce8ab..3c50bb5af 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -72,10 +72,12 @@ jobs: echo "Published snapshot version: $VERSION" echo "jdbc_version=$VERSION" >> "$GITHUB_OUTPUT" - name: Release Snapshot + env: + TEST_CLICKHOUSE_IMAGE_VERSION: ${{ env.CH_VERSION }} uses: samuelmeuli/action-maven-publish@v1 with: maven_profiles: release - maven_args: -q --batch-mode -DclickhouseVersion=${{ env.CH_VERSION }} + maven_args: -q --batch-mode server_id: central gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 90e4c1209..d748fbb38 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,7 +61,8 @@ jobs: MAVEN_USERNAME: ${{ secrets.SONATYPE_TOKEN_USER }} MAVEN_PASSWORD: ${{ secrets.SONATYPE_TOKEN }} MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} - run: mvn -q --batch-mode -P release -DclickhouseVersion=${{ env.CH_VERSION }} clean deploy + TEST_CLICKHOUSE_IMAGE_VERSION: ${{ env.CH_VERSION }} + run: mvn -q --batch-mode -P release clean deploy - name: Create Pre-release on Github env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test_head.yml b/.github/workflows/test_head.yml index f1129021b..53a039f47 100644 --- a/.github/workflows/test_head.yml +++ b/.github/workflows/test_head.yml @@ -37,8 +37,10 @@ jobs: distribution: 'temurin' architecture: x64 - name: Test Java client + env: + TEST_CLICKHOUSE_IMAGE_VERSION: ${{ env.CH_VERSION }} run: | - mvn --also-make --batch-mode --no-transfer-progress --projects ${{ matrix.project }} -DclickhouseVersion=$CH_VERSION -Dmaven.javadoc.skip=true clean install + mvn --also-make --batch-mode --no-transfer-progress --projects ${{ matrix.project }} -Dmaven.javadoc.skip=true clean install - name: Upload test results uses: actions/upload-artifact@v4 if: failure() @@ -68,10 +70,12 @@ jobs: architecture: x64 - name: Build run: | - mvn --also-make --batch-mode --no-transfer-progress -DclickhouseVersion=$CH_VERSION -Dmaven.javadoc.skip=true -DskipTests=true clean install + mvn --also-make --batch-mode --no-transfer-progress -Dmaven.javadoc.skip=true -DskipTests=true clean install - name: Test R2DBC ${{ matrix.r2dbc }} + env: + TEST_CLICKHOUSE_IMAGE_VERSION: ${{ env.CH_VERSION }} run: | - mvn --batch-mode --no-transfer-progress --projects clickhouse-r2dbc -DclickhouseVersion=$CH_VERSION \ + mvn --batch-mode --no-transfer-progress --projects clickhouse-r2dbc \ -D'r2dbc-spi.version=${{ matrix.r2dbc }}' -Dprotocol=${{ matrix.protocol }} -Dmaven.javadoc.skip=true clean install - name: Upload test results uses: actions/upload-artifact@v4 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6bac66743..5ba6ca6c4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -139,36 +139,35 @@ Compile examples or packaging modules when your change affects examples, packagi Unit tests do not require a running ClickHouse server. Relevant unit tests should pass locally before a PR is submitted. -Integration tests usually require [Docker](https://docs.docker.com/engine/install/). The Docker image defaults to `clickhouse/clickhouse-server`, and containers are created automatically by [testcontainers](https://www.testcontainers.org/). To test against a specific ClickHouse version, pass a Maven parameter such as: +Integration tests usually require [Docker](https://docs.docker.com/engine/install/). The Docker image defaults to `clickhouse/clickhouse-server`, and containers are created automatically by [testcontainers](https://www.testcontainers.org/). Configuration is read from environment variables prefixed with `TEST_`: + +| Variable | Default | Purpose | +| --- | --- | --- | +| `TEST_CLICKHOUSE_CONTAINER` | `single` | `single` starts one server, `cluster` starts three servers behind nginx, `none` starts nothing | +| `TEST_CLICKHOUSE_IMAGE_VERSION` | | Image tag used when a container is started, for example `24.8` | +| `TEST_CLICKHOUSE_IMAGE` | `clickhouse/clickhouse-server` | Image repository | +| `TEST_CLICKHOUSE_HOST` | `localhost` | Host used when no container is started | +| `TEST_CLICKHOUSE_USER` | `default` | User name | +| `TEST_CLICKHOUSE_PASSWORD` | `test_default_password` | Password | +| `TEST_CLICKHOUSE_SECURE` | `false` | `true` uses HTTPS on port 8443 (ClickHouse Cloud) | +| `TEST_CLICKHOUSE_TIMEZONE` | `UTC` | Timezone inside a started container | +| `TEST_CLICKHOUSE_ADDITIONAL_PACKAGES` | | Extra apt packages installed into the image | +| `TEST_DB_NAME` | generated | Database name. An external name must start with `clickhouse_java_test_` | +| `TEST_PROXY_ADDRESS` | | External proxy as `host:port` | +| `TEST_PROXY_IMAGE` | `ghcr.io/shopify/toxiproxy:2.5.0` | Toxiproxy image | + +To test against a specific ClickHouse version: ```bash -mvn -pl test -DclickhouseVersion=23.3 +TEST_CLICKHOUSE_IMAGE_VERSION=24.8 mvn -pl test ``` -If you do not want to use Docker, or you prefer to test against an existing server: +To use an existing server instead of Docker, set `TEST_CLICKHOUSE_CONTAINER=none` and point `TEST_CLICKHOUSE_HOST` at that server. The server must accept `TEST_CLICKHOUSE_USER` / `TEST_CLICKHOUSE_PASSWORD` (defaults: `default` / `test_default_password`) with DDL and DML privileges. For ClickHouse Cloud also set `TEST_CLICKHOUSE_SECURE=true`. -- make sure the server can be accessed with the default account, user `default` and no password, with both DDL and DML privileges -- add the test server configuration files and expose all default ports: - - [ports.xml](clickhouse-client/src/test/resources/containers/clickhouse-server/config.d/ports.xml) - - [users.xml](clickhouse-client/src/test/resources/containers/clickhouse-server/users.d/users.xml) -- make sure the ClickHouse binary, usually `/usr/bin/clickhouse`, is available in `PATH` for `clickhouse-cli-client` tests -- put `test.properties` under either `~/.clickhouse` or the module's `src/test/resources` - -Example `test.properties`: - -```properties -# ClickHouse server for integration tests -clickhouseServer=x.x.x.x - -# Custom HTTP proxy for integration tests -proxyAddress=: - -# Properties below are only useful for testcontainers -#clickhouseVersion=latest -#clickhouseTimezone=UTC -#clickhouseImage=clickhouse/clickhouse-server -#additionalPackages= -#proxyImage=ghcr.io/shopify/toxiproxy:2.5.0 +```bash +TEST_CLICKHOUSE_CONTAINER=none \ +TEST_CLICKHOUSE_HOST=127.0.0.1 \ +mvn -pl test ``` TBD: document a dockerized development environment for running the standard local test suite. diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java new file mode 100644 index 000000000..b719597c1 --- /dev/null +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java @@ -0,0 +1,181 @@ +package com.clickhouse.client; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.BindMode; +import org.testcontainers.containers.Container; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.images.builder.ImageFromDockerfile; + +import java.time.Duration; +import java.util.List; + +import static java.time.temporal.ChronoUnit.SECONDS; + +/** + * Starts the ClickHouse containers integration tests connect to. + *

+ * {@code single} starts one server. {@code cluster} starts three servers behind nginx. + * The process that calls {@link #getHost()} always sees one host and the published service ports. + */ +public abstract class ClickHouseContainerStarter { + private static final Logger LOGGER = LoggerFactory.getLogger(ClickHouseContainerStarter.class); + + static final String FRONTEND_ALIAS = "clickhouse"; + static final String CONTAINER_TMP_DIR = "/tmp"; + private static final String CUSTOM_DIRECTORY = "/custom"; + private static final String CONFIG_RESOURCE = "containers/clickhouse-server"; + + protected final ClickHouseTestEnvironment environment; + protected final Network network; + + ClickHouseContainerStarter(ClickHouseTestEnvironment environment, Network network) { + this.environment = environment; + this.network = network; + } + + /** + * @return a starter for {@code single} or {@code cluster}, or null when the mode is {@code none} + */ + static ClickHouseContainerStarter create(ClickHouseTestEnvironment environment, Network network) { + switch (environment.getContainerMode()) { + case SINGLE: + return new SingleClickHouseContainerStarter(environment, network); + case CLUSTER: + return new ClusterClickHouseContainerStarter(environment, network); + case NONE: + return null; + default: + throw new IllegalStateException("Unsupported container mode: " + environment.getContainerMode()); + } + } + + public abstract void start(); + + public abstract void stop(); + + public abstract boolean isRunning(); + + public abstract String getHost(); + + public abstract int getMappedPort(int port); + + public abstract Container.ExecResult execInContainer(String... command) throws Exception; + + /** + * Cluster name when these servers are replicas of one shard, otherwise null. + */ + public String replicatedClusterName() { + return null; + } + + /** + * Runs a query inside every ClickHouse server. + */ + public final boolean execQueryOnServers(String sql, String user, String password) throws Exception { + boolean succeeded = true; + for (GenericContainer server : clickHouseServers()) { + Container.ExecResult result = server.execInContainer("clickhouse-client", + "-u", user, "--password", password, "--query", sql); + if (result.getExitCode() != 0) { + LOGGER.error("query failed: stderr={}, stdout={}", result.getStderr(), result.getStdout()); + succeeded = false; + } + } + return succeeded; + } + + protected abstract List> clickHouseServers(); + + public abstract GenericContainer getEndpointContainer(); + + public Network getNetwork() { + return network; + } + + protected final GenericContainer newClickHouseServer(String networkAlias, String containerName) { + return newClickHouseServer(networkAlias, containerName, null); + } + + /** + * @param replicaName replica macro for a cluster node, or null for the single-server config + */ + @SuppressWarnings({"rawtypes", "unchecked"}) + protected final GenericContainer newClickHouseServer(String networkAlias, String containerName, + String replicaName) { + String additionalPackages = environment.getAdditionalPackages(); + GenericContainer container = ((additionalPackages == null) + ? new GenericContainer<>(environment.getImageRef()) + : new GenericContainer<>(new ImageFromDockerfile().withDockerfileFromBuilder(builder -> builder + .from(environment.getImageRef()) + .run("apt-get update && apt-get install -y " + additionalPackages)))) + .withCreateContainerCmdModifier(command -> { + command.withEntrypoint("/bin/sh"); + if (containerName != null) { + command.withName(containerName); + } + }) + .withCommand("-c", String.format("chmod +x %1$s/patch && %1$s/patch", CUSTOM_DIRECTORY)) + .withEnv("TZ", environment.getTimezone()) + .withExposedPorts( + ClickHouseProtocol.GRPC.getDefaultPort(), + ClickHouseProtocol.HTTP.getDefaultPort(), + ClickHouseProtocol.HTTP.getDefaultSecurePort(), + ClickHouseProtocol.MYSQL.getDefaultPort(), + ClickHouseProtocol.TCP.getDefaultPort(), + ClickHouseProtocol.TCP.getDefaultSecurePort(), + ClickHouseProtocol.POSTGRESQL.getDefaultPort()) + .withClasspathResourceMapping(CONFIG_RESOURCE, CUSTOM_DIRECTORY, BindMode.READ_ONLY) + .withClasspathResourceMapping("empty.csv", "/var/lib/clickhouse/user_files/empty.csv", + BindMode.READ_ONLY) + .withFileSystemBind(System.getProperty("java.io.tmpdir"), CONTAINER_TMP_DIR, BindMode.READ_WRITE) + .withNetwork(network) + .withNetworkAliases(networkAlias); + if (replicaName != null) { + container = container + .withEnv("CLICKHOUSE_REPLICA", replicaName) + .withEnv("CLICKHOUSE_INTERSERVER_HOST", networkAlias) + .withClasspathResourceMapping("containers/clickhouse-cluster/config.d/custom_config.xml", + CUSTOM_DIRECTORY + "/config.d/custom_config.xml", BindMode.READ_ONLY) + .withClasspathResourceMapping("containers/clickhouse-cluster/users.d/cluster_quorum.xml", + CUSTOM_DIRECTORY + "/users.d/cluster_quorum.xml", BindMode.READ_ONLY); + } + return container.waitingFor(Wait.forHttp("/ping").forPort(ClickHouseProtocol.HTTP.getDefaultPort()) + .forStatusCode(200).withStartupTimeout(Duration.of(600, SECONDS))); + } + + protected final GenericContainer newNginx(String containerName, String configResource) { + return new GenericContainer<>("nginx:1.27-alpine") + .withCreateContainerCmdModifier(command -> { + if (containerName != null) { + command.withName(containerName); + } + }) + .withNetwork(network) + .withNetworkAliases(FRONTEND_ALIAS) + .withClasspathResourceMapping(configResource, "/etc/nginx/nginx.conf", BindMode.READ_ONLY) + .withExposedPorts( + ClickHouseProtocol.GRPC.getDefaultPort(), + ClickHouseProtocol.HTTP.getDefaultPort(), + ClickHouseProtocol.HTTP.getDefaultSecurePort(), + ClickHouseProtocol.MYSQL.getDefaultPort(), + ClickHouseProtocol.TCP.getDefaultPort(), + ClickHouseProtocol.TCP.getDefaultSecurePort(), + ClickHouseProtocol.POSTGRESQL.getDefaultPort()) + .waitingFor(Wait.forHttp("/ping").forPort(ClickHouseProtocol.HTTP.getDefaultPort()) + .forStatusCode(200).withStartupTimeout(Duration.of(600, SECONDS))); + } + + protected static void stopQuietly(GenericContainer container) { + if (container == null) { + return; + } + try { + container.stop(); + } catch (RuntimeException e) { + LOGGER.warn("Failed to stop test container", e); + } + } +} diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java index fc4f5f26c..399ca0e30 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java @@ -2,12 +2,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.BindMode; import org.testcontainers.containers.Container; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; @@ -16,185 +13,69 @@ import java.net.InetSocketAddress; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.time.Duration; +import java.util.Locale; import java.util.Base64; import java.util.Collections; import java.util.Map; -import java.util.Properties; -import java.util.UUID; - -import static java.time.temporal.ChronoUnit.SECONDS; /** - * Adaptive ClickHouse server environment for integration test. Two modes are - * supported: 1) existing server(when system property {@code clickhouseServer} - * is defined); and 2) test container. - * + * ClickHouse endpoint for integration tests. *

- * Below system properties can be used for customization: - *

    - *
  • clickhouseServer - host of clickhouse server
  • - *
  • clickhouse<Protocol>Port - port of specific protocol, for example: - * {@code clickhouseGRPCPort}
  • - *
  • clickhouseImage - custom docker image, with or without tag and/or image - * digest
  • - *
  • clickhouseVersion - version of clickhouse, could be replaced by the one - * used in {@code clickhouseImage}
  • - *
  • clickhouseTimezone - server timezone
  • - *
  • additionalPackages - additional system packages should be installed in - * container mode
  • - *
+ * What to start is {@code TEST_CLICKHOUSE_CONTAINER}: {@code single} (default) starts one + * server, {@code cluster} starts three servers behind nginx, and {@code none} starts nothing. + * Where tests connect when no container is started comes from {@code TEST_CLICKHOUSE_HOST} + * (default {@code localhost}), {@code TEST_CLICKHOUSE_USER}, and {@code TEST_CLICKHOUSE_PASSWORD}. + * {@code TEST_CLICKHOUSE_IMAGE_VERSION} is the image tag used to start a container. + * The removed {@code clickhouseVersion} system property throws {@link IllegalArgumentException}. + * {@code TEST_CLICKHOUSE_SECURE=true} selects the HTTPS endpoint on port 8443 (ClickHouse Cloud). */ @SuppressWarnings("squid:S2187") public class ClickHouseServerForTest { private static final Logger LOGGER = LoggerFactory.getLogger(ClickHouseServerForTest.class); - private static final Network network = Network.newNetwork(); - private static final Properties properties; - - private static final String clickhouseServer; - private static final String clickhouseVersion; - private static final GenericContainer clickhouseContainer; + private static final Network network; + private static final ClickHouseTestEnvironment environment; + private static final ClickHouseContainerStarter starter; private static final String proxyHost; private static final int proxyPort; private static final String proxyImage; - private static boolean isCloud = false; - - private static final String database; - private static final boolean localDatabase; static { - properties = new Properties(System.getProperties()); - String externalDatabase = System.getenv("TEST_DB_NAME"); // see build.yaml workflow - if (externalDatabase != null && !externalDatabase.trim().isEmpty()) { - if (!externalDatabase.startsWith("clickhouse_java_test_")) { - throw new RuntimeException("external database for tests should start with 'clickhouse_java_test_'"); - } - localDatabase = false; - database = externalDatabase; - } else { - localDatabase = true; - database = "clickhouse_java_" + UUID.randomUUID().toString().substring(0, 8) + "_test_" + System.currentTimeMillis(); - } - - LOGGER.info("Local database: {}", localDatabase); - - String proxy = properties.getProperty("proxyAddress"); - if (proxy != null && !proxy.isEmpty()) { // use external proxy - int index = proxy.indexOf(':'); - if (index > 0) { - proxyHost = proxy.substring(0, index); - proxyPort = Integer.parseInt(proxy.substring(index + 1)); - } else { - proxyHost = proxy; - proxyPort = 8666; - } - proxyImage = ""; - } else { - proxyHost = ""; - proxyPort = -1; - String image = properties.getProperty("proxyImage"); - proxyImage = image == null ? "ghcr.io/shopify/toxiproxy:2.5.0" : image; - } - - final String containerName = System.getenv("CHC_TEST_CONTAINER_ID"); - - clickhouseServer = properties.getProperty("clickhouseServer"); - String imageTag = properties.getProperty("clickhouseVersion"); - if (imageTag != null && imageTag.equalsIgnoreCase("cloud")) { - isCloud = true; - imageTag = ""; - } - if (clickhouseServer != null || isCloud) { // use external server - clickhouseVersion = imageTag == null - || ClickHouseVersionUtils.of(imageTag).getYear() == 0 ? "" : imageTag; - clickhouseContainer = null; - } else { // use test container - String timezone = properties.getProperty("clickhouseTimezone"); - if (timezone == null) { - timezone = "UTC"; - } - - String imageName = properties.getProperty("clickhouseImage"); - if (imageName == null) { - imageName = "clickhouse/clickhouse-server"; - } - - int tagIndex = imageName.indexOf(':'); - int digestIndex = imageName.indexOf('@'); - if (tagIndex > 0) { - imageTag = ""; - clickhouseVersion = digestIndex > 0 ? imageName.substring(tagIndex + 1, digestIndex) - : imageName.substring(tagIndex + 1); - } else if (digestIndex > 0 || imageTag == null) { - clickhouseVersion = imageTag = ""; - } else { - if (ClickHouseVersionUtils.of(imageTag).getYear() == 0) { - clickhouseVersion = ""; - } else { - clickhouseVersion = imageTag; - } - imageTag = ":" + imageTag; - } - - String imageNameWithTag = imageName + imageTag; - String customPackages = properties.getProperty("additionalPackages"); - if (ClickHouseVersionUtils.check(clickhouseVersion, "(,21.3]")) { - if (customPackages == null) { - customPackages = "tzdata"; - } else if (!customPackages.contains("tzdata")) { - customPackages += " tzdata"; - } - } - - final String additionalPackages = customPackages; - final String customDirectory = "/custom"; - clickhouseContainer = ((additionalPackages == null) - ? new GenericContainer<>(imageNameWithTag) - : new GenericContainer<>(new ImageFromDockerfile().withDockerfileFromBuilder(builder -> builder - .from(imageNameWithTag).run("apt-get update && apt-get install -y " + additionalPackages)))) - .withCreateContainerCmdModifier( - it -> { - it.withEntrypoint("/bin/sh"); - if (containerName != null) { - it.withName(containerName); - } - }) - .withCommand("-c", String.format("chmod +x %1$s/patch && %1$s/patch", customDirectory)) - .withEnv("TZ", timezone) - .withExposedPorts(ClickHouseProtocol.GRPC.getDefaultPort(), - ClickHouseProtocol.HTTP.getDefaultPort(), - ClickHouseProtocol.HTTP.getDefaultSecurePort(), - ClickHouseProtocol.MYSQL.getDefaultPort(), - ClickHouseProtocol.TCP.getDefaultPort(), - ClickHouseProtocol.TCP.getDefaultSecurePort(), - ClickHouseProtocol.POSTGRESQL.getDefaultPort()) - .withClasspathResourceMapping("containers/clickhouse-server", customDirectory, BindMode.READ_ONLY) - .withClasspathResourceMapping("empty.csv", "/var/lib/clickhouse/user_files/empty.csv", BindMode.READ_ONLY) - .withFileSystemBind(System.getProperty("java.io.tmpdir"), getClickHouseContainerTmpDir(), - BindMode.READ_WRITE) - .withNetwork(network) - .withNetworkAliases("clickhouse") - .waitingFor(Wait.forHttp("/ping").forPort(ClickHouseProtocol.HTTP.getDefaultPort()) - .forStatusCode(200).withStartupTimeout(Duration.of(600, SECONDS))); - } + ClickHouseTestEnvironment.rejectRemovedOptions(System.getProperties()); + network = Network.newNetwork(); + environment = ClickHouseTestEnvironment.from(System.getenv()); + LOGGER.info("Local database: {}", environment.isLocalDatabase()); + + proxyHost = environment.getProxyHost(); + proxyPort = environment.getProxyPort(); + proxyImage = environment.getProxyImage(); + + starter = ClickHouseContainerStarter.create(environment, network); + + LOGGER.info( + "ClickHouse test target: container={}, image={}, host={}, user={}, secure={}, database={}", + environment.getContainerMode(), environment.getImageRef(), environment.getHost(), + environment.getUser(), environment.isSecure(), environment.getDatabase()); + System.out.println("TEST_CLICKHOUSE_CONTAINER=" + + environment.getContainerMode().name().toLowerCase(Locale.ROOT)); + System.out.println("TEST_CLICKHOUSE_IMAGE_VERSION=" + environment.getImageRef()); } public static String getClickHouseVersion() { - return clickhouseVersion; + return environment.getClickHouseVersion(); } public static boolean hasClickHouseContainer() { - return clickhouseContainer != null; + return starter != null; } public static GenericContainer getClickHouseContainer() { - return clickhouseContainer; + return starter == null ? null : starter.getEndpointContainer(); } public static String getClickHouseContainerTmpDir() { - return "/tmp"; + return ClickHouseContainerStarter.CONTAINER_TMP_DIR; } public static String getClickHouseAddress() { @@ -202,88 +83,57 @@ public static String getClickHouseAddress() { } public static String getClickHouseAddress(ClickHouseProtocol protocol, boolean useIPaddress) { - StringBuilder builder = new StringBuilder(); - if (isCloud) { - String host = System.getenv("CLICKHOUSE_CLOUD_HOST"); - int port = 8443; - builder.append("https://").append(host).append(':').append(port); - return builder.toString(); - } else if (clickhouseContainer != null) { - builder.append(clickhouseContainer.getHost()) - .append(':').append(clickhouseContainer.getMappedPort(protocol.getDefaultPort())); - } else { - String port = properties - .getProperty(String.format("clickhouse%SPort", protocol.name()), String.valueOf(protocol.getDefaultPort())); - builder.append(clickhouseServer).append(':').append(port); + if (isCloud()) { + Endpoint endpoint = cloudHttpEndpoint(); + return "https://" + endpoint.host + ":" + endpoint.port; } - - return builder.toString(); + Endpoint endpoint = resolve(protocol, protocol.getDefaultPort(), true); + return endpoint.host + ":" + endpoint.port; } public static ClickHouseNode getClickHouseNode(ClickHouseProtocol protocol, boolean useSecurePort, ClickHouseNode template) { - String host = clickhouseServer; - int port = useSecurePort ? protocol.getDefaultSecurePort() : protocol.getDefaultPort(); String database = template != null ? template.getDatabase().orElse("default") : "default"; - GenericContainer container = clickhouseContainer; if (isCloud()) { - port = 8443; - host = System.getenv("CLICKHOUSE_CLOUD_HOST"); + Endpoint endpoint = cloudHttpEndpoint(); return ClickHouseNode.builder(template) - .address(ClickHouseProtocol.HTTP, new InetSocketAddress(host, port)) - .credentials(new ClickHouseCredentials("default", getPassword())) + .address(ClickHouseProtocol.HTTP, new InetSocketAddress(endpoint.host, endpoint.port)) + .credentials(new ClickHouseCredentials(getUsername(), getPassword())) .options(Collections.singletonMap("ssl", "true")) .database(database) .build(); - } else if (container != null) { - host = container.getHost(); - port = container.getMappedPort(port); - } else { - String config = properties - .getProperty(String.format("clickhouse%SPort", protocol.name())); - if (config != null && !config.isEmpty()) { - port = Integer.parseInt(config); - } } - return ClickHouseNode.builder(template).address(protocol, new InetSocketAddress(host, port)) - .credentials(new ClickHouseCredentials("default", getPassword())) + int port = useSecurePort ? protocol.getDefaultSecurePort() : protocol.getDefaultPort(); + Endpoint endpoint = resolve(protocol, port, true); + return ClickHouseNode.builder(template).address(protocol, new InetSocketAddress(endpoint.host, endpoint.port)) + .credentials(new ClickHouseCredentials(getUsername(), getPassword())) .build(); } public static ClickHouseNode getClickHouseNode(ClickHouseProtocol protocol, int port) { - String host = clickhouseServer; - - if (isCloud) { - host = System.getenv("CLICKHOUSE_CLOUD_HOST"); - port = 8443; - return ClickHouseNode.builder(). - address(protocol, new InetSocketAddress(host, port)) - .credentials(new ClickHouseCredentials("default", getPassword())) - .database(database) + if (isCloud()) { + Endpoint endpoint = cloudHttpEndpoint(); + return ClickHouseNode.builder() + .address(protocol, new InetSocketAddress(endpoint.host, endpoint.port)) + .credentials(new ClickHouseCredentials(getUsername(), getPassword())) + .database(getDatabase()) .build(); } - if (clickhouseContainer != null) { - host = clickhouseContainer.getHost(); - port = clickhouseContainer.getMappedPort(port); - } - return ClickHouseNode.builder().address(protocol, new InetSocketAddress(host, port)).build(); + Endpoint endpoint = resolve(protocol, port, false); + return ClickHouseNode.builder().address(protocol, new InetSocketAddress(endpoint.host, endpoint.port)).build(); } public static ClickHouseNode getClickHouseNode(ClickHouseProtocol protocol, Map options) { - String host = clickhouseServer; - String url = null; - int port = protocol.getDefaultPort(); - if (isCloud) { - host = System.getenv("CLICKHOUSE_CLOUD_HOST"); - port = 8443; + String url; + if (isCloud()) { + Endpoint endpoint = cloudHttpEndpoint(); options.put("password", getPassword()); - url = String.format("https://%s:%d/%s", host, port, database); - } else if (clickhouseContainer != null) { - host = clickhouseContainer.getHost(); - port = clickhouseContainer.getMappedPort(port); - url = String.format("http://%s:%d/default", host, port);//TODO: Should this always be http? + url = String.format("https://%s:%d/%s", endpoint.host, endpoint.port, getDatabase()); + } else { + Endpoint endpoint = resolve(protocol, protocol.getDefaultPort(), true); + url = String.format("http://%s:%d/default", endpoint.host, endpoint.port); } return ClickHouseNode.of(url, options); } @@ -309,132 +159,152 @@ public static Network getNetwork() { } public static String getUsername() { - // For cloud, the username is set in environment variable - if (isCloud) { - return System.getenv("CLICKHOUSE_CLOUD_USERNAME") == null ? "default" : System.getenv("CLICKHOUSE_CLOUD_USERNAME"); - } else { - return "default"; - } + return environment.getUser(); } public static String getPassword() { - // For cloud, the password is set in environment variable - if (isCloud) { - return System.getenv("CLICKHOUSE_CLOUD_PASSWORD"); - } else { - return "test_default_password"; - } + return environment.getPassword(); } public static boolean isCloud() { - return isCloud; + return environment.isSecure(); } @BeforeSuite(groups = {"integration"}) public static void beforeSuite() { - if (isCloud) { - if (localDatabase) { - if (!runQuery("CREATE DATABASE IF NOT EXISTS " + database)) { - throw new RuntimeException("Failed to create database for testing."); + if (starter != null) { + if (!starter.isRunning()) { + try { + starter.start(); + } catch (RuntimeException e) { + throw new IllegalStateException(new StringBuilder() + .append("Failed to start docker container for integration test.\r\n") + .append("To use an existing server, set TEST_CLICKHOUSE_CONTAINER=none ") + .append("and TEST_CLICKHOUSE_HOST. See ") + .append("https://github.com/ClickHouse/clickhouse-java#testing") + .toString(), e); } } + if (starter.isRunning() && !createDatabaseOnServers()) { + throw new RuntimeException("Failed to create database"); + } return; } - if (clickhouseContainer != null) { - if (clickhouseContainer.isRunning()) { - return; - } - - try { - clickhouseContainer.start(); - - if (clickhouseContainer.isRunning()) { - if (!runQuery("CREATE DATABASE IF NOT EXISTS `" + getDatabase() + "`")) { - throw new RuntimeException("Failed to create database"); - } - } - } catch (RuntimeException e) { - throw new IllegalStateException(new StringBuilder() - .append("Failed to start docker container for integration test.\r\n") - .append("If you prefer to run tests without docker, ") - .append("please follow instructions at https://github.com/ClickHouse/clickhouse-java#testing") - .toString(), e); + if (isCloud() && environment.isLocalDatabase()) { + if (!runQuery("CREATE DATABASE IF NOT EXISTS `" + getDatabase() + "`")) { + throw new RuntimeException("Failed to create database for testing."); } } } @AfterSuite(groups = {"integration"}) public static void afterSuite() { - if (clickhouseContainer != null) { -// clickhouseContainer.copyFileFromContainer("/var/log/clickhouse-server/clickhouse-server.log", "server-container.log"); - clickhouseContainer.stop(); + if (starter != null) { + starter.stop(); } - if (isCloud) { - if (localDatabase) { - if (!runQuery("DROP DATABASE IF EXISTS `" + database + "`")) { - LOGGER.warn("Failed to drop database for testing."); - } + if (isCloud() && environment.isLocalDatabase() && starter == null) { + if (!runQuery("DROP DATABASE IF EXISTS `" + getDatabase() + "`")) { + LOGGER.warn("Failed to drop database for testing."); } } } public static String getDatabase() { - return database; + return environment.getDatabase(); } - public static boolean runQuery(String sql) { - LOGGER.info("runQuery: (\"" + sql + "\")"); - if (clickhouseContainer != null) { - try { - Container.ExecResult res = clickhouseContainer.execInContainer("clickhouse-client", - "-u", "default", "--password", getPassword(), "--query", sql); - if (res.getExitCode() != 0) { - LOGGER.error("query execution result: stderr={}, stdout={}", res.getStderr(), res.getStdout() ); - } - return res.getExitCode() == 0; - } catch (Exception e) { - throw new RuntimeException("runQuery('" + sql + "') failed", e); + private static boolean createDatabaseOnServers() { + String database = getDatabase(); + String cluster = starter.replicatedClusterName(); + try { + if (cluster == null) { + return starter.execQueryOnServers("CREATE DATABASE IF NOT EXISTS `" + database + "`", + getUsername(), getPassword()); } - } else { - //Create database for testing - - ClickHouseNode server = getClickHouseNode(ClickHouseProtocol.HTTP, isCloud(), ClickHouseNode.builder().build()); - - String uri = server.getBaseUri(); - - try { - URL serverURL = new URL(uri); - LOGGER.info("sending request to {} (uri={})", serverURL, uri); - byte[] postData = sql.getBytes(StandardCharsets.UTF_8); - for (int attempts = 0; attempts < 10; attempts++) { - HttpURLConnection httpConn = (HttpURLConnection) serverURL.openConnection(); - try { - httpConn.setRequestMethod("POST"); - httpConn.setDoOutput(true); - httpConn.setRequestProperty("Authorization", "Basic " + Base64.getEncoder().encodeToString(("default:" + getPassword()).getBytes())); - httpConn.setFixedLengthStreamingMode(postData.length); - - try (OutputStream out = httpConn.getOutputStream()) { - out.write(postData, 0, postData.length); - out.flush(); - } - - if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) { - return true; - } - } finally { - if (httpConn != null) { - httpConn.disconnect(); - } + String sql = "CREATE DATABASE IF NOT EXISTS `" + database + "` ON CLUSTER " + cluster + + " ENGINE = Replicated('/clickhouse/databases/" + database + "', '{shard}', '{replica}')"; + Container.ExecResult result = starter.execInContainer("clickhouse-client", + "-u", getUsername(), "--password", getPassword(), "--query", sql); + if (result.getExitCode() != 0) { + LOGGER.error("query failed: stderr={}, stdout={}", result.getStderr(), result.getStdout()); + return false; + } + return true; + } catch (Exception e) { + throw new RuntimeException("Failed to create database", e); + } + } + + public static boolean runQuery(String sql) { + LOGGER.info("runQuery: (\"{}\")", sql); + ClickHouseNode server = getClickHouseNode(ClickHouseProtocol.HTTP, isCloud(), ClickHouseNode.builder().build()); + String uri = server.getBaseUri(); + + try { + URL serverURL = new URL(uri); + LOGGER.info("sending request to {} (uri={})", serverURL, uri); + byte[] postData = sql.getBytes(StandardCharsets.UTF_8); + String authorization = Base64.getEncoder() + .encodeToString((getUsername() + ":" + getPassword()).getBytes(StandardCharsets.UTF_8)); + for (int attempts = 0; attempts < 10; attempts++) { + HttpURLConnection httpConn = (HttpURLConnection) serverURL.openConnection(); + try { + httpConn.setRequestMethod("POST"); + httpConn.setDoOutput(true); + httpConn.setRequestProperty("Authorization", "Basic " + authorization); + httpConn.setFixedLengthStreamingMode(postData.length); + + try (OutputStream out = httpConn.getOutputStream()) { + out.write(postData, 0, postData.length); + out.flush(); + } + + if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) { + return true; } + } finally { + httpConn.disconnect(); } - } catch (Exception e) { - LOGGER.error("failed to run query", e); } + } catch (Exception e) { + LOGGER.error("failed to run query", e); + } + + return false; + } + + private static Endpoint resolve(ClickHouseProtocol protocol, int port, boolean applyOverride) { + if (starter != null) { + return new Endpoint(starter.getHost(), starter.getMappedPort(port)); + } + if (applyOverride) { + String override = environment.portOverride(protocol); + if (override != null) { + port = Integer.parseInt(override); + } + } + return new Endpoint(environment.getHost(), port); + } + + private static Endpoint cloudHttpEndpoint() { + if (starter != null) { + int port = ClickHouseProtocol.HTTP.getDefaultSecurePort(); + return new Endpoint(starter.getHost(), starter.getMappedPort(port)); + } + String override = environment.portOverride(ClickHouseProtocol.HTTP); + int port = override != null ? Integer.parseInt(override) : ClickHouseProtocol.HTTP.getDefaultSecurePort(); + return new Endpoint(environment.getHost(), port); + } + + private static final class Endpoint { + private final String host; + private final int port; - return false; + private Endpoint(String host, int port) { + this.host = host; + this.port = port; } } } diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironment.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironment.java new file mode 100644 index 000000000..bef09c5aa --- /dev/null +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironment.java @@ -0,0 +1,291 @@ +package com.clickhouse.client; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; + +/** + * Integration-test target read from {@code TEST_*} environment variables. + */ +final class ClickHouseTestEnvironment { + static final String CONTAINER = "TEST_CLICKHOUSE_CONTAINER"; + static final String IMAGE = "TEST_CLICKHOUSE_IMAGE"; + static final String IMAGE_VERSION = "TEST_CLICKHOUSE_IMAGE_VERSION"; + static final String HOST = "TEST_CLICKHOUSE_HOST"; + static final String USER = "TEST_CLICKHOUSE_USER"; + static final String PASSWORD = "TEST_CLICKHOUSE_PASSWORD"; + static final String SECURE = "TEST_CLICKHOUSE_SECURE"; + static final String TIMEZONE = "TEST_CLICKHOUSE_TIMEZONE"; + static final String ADDITIONAL_PACKAGES = "TEST_CLICKHOUSE_ADDITIONAL_PACKAGES"; + static final String CONTAINER_ID = "TEST_CLICKHOUSE_CONTAINER_ID"; + static final String DATABASE = "TEST_DB_NAME"; + static final String PROXY_ADDRESS = "TEST_PROXY_ADDRESS"; + static final String PROXY_IMAGE = "TEST_PROXY_IMAGE"; + + static final String DEFAULT_IMAGE = "clickhouse/clickhouse-server"; + static final String DEFAULT_HOST = "localhost"; + static final String DEFAULT_USER = "default"; + static final String DEFAULT_PASSWORD = "test_default_password"; + static final String DEFAULT_TIMEZONE = "UTC"; + static final String DEFAULT_PROXY_IMAGE = "ghcr.io/shopify/toxiproxy:2.5.0"; + + enum ContainerMode { + SINGLE, CLUSTER, NONE + } + + private final Map env; + private final ContainerMode containerMode; + private final String imageRef; + private final String clickHouseVersion; + private final String additionalPackages; + private final String host; + private final String user; + private final String password; + private final boolean secure; + private final String timezone; + private final String containerName; + private final String database; + private final boolean localDatabase; + private final String proxyHost; + private final int proxyPort; + private final String proxyImage; + + private ClickHouseTestEnvironment(Map env, ContainerMode containerMode, String imageRef, + String clickHouseVersion, String additionalPackages, String host, String user, String password, + boolean secure, String timezone, String containerName, String database, boolean localDatabase, + String proxyHost, int proxyPort, String proxyImage) { + this.env = env; + this.containerMode = containerMode; + this.imageRef = imageRef; + this.clickHouseVersion = clickHouseVersion; + this.additionalPackages = additionalPackages; + this.host = host; + this.user = user; + this.password = password; + this.secure = secure; + this.timezone = timezone; + this.containerName = containerName; + this.database = database; + this.localDatabase = localDatabase; + this.proxyHost = proxyHost; + this.proxyPort = proxyPort; + this.proxyImage = proxyImage; + } + + static final String REMOVED_VERSION_PROPERTY = "clickhouseVersion"; + + /** + * Fails the run when the removed {@code clickhouseVersion} system property is set. + * Image selection is {@code TEST_CLICKHOUSE_IMAGE_VERSION}. + */ + static void rejectRemovedOptions(Properties properties) { + if (properties == null) { + return; + } + String version = properties.getProperty(REMOVED_VERSION_PROPERTY); + if (version != null && !version.trim().isEmpty()) { + throw new IllegalArgumentException("System property clickhouseVersion is no longer supported" + + " (was '" + version.trim() + "'). Set TEST_CLICKHOUSE_IMAGE_VERSION to select the" + + " container image."); + } + } + + static ClickHouseTestEnvironment from(Map env) { + Map source = new HashMap(); + if (env != null) { + source.putAll(env); + } + + ContainerMode containerMode = parseMode(value(source, CONTAINER)); + + String imageName = value(source, IMAGE); + if (imageName == null) { + imageName = DEFAULT_IMAGE; + } + String requestedVersion = value(source, IMAGE_VERSION); + String clickHouseVersion; + String imageRef; + int tagIndex = imageName.indexOf(':'); + int digestIndex = imageName.indexOf('@'); + if (digestIndex > 0 && (tagIndex < 0 || digestIndex < tagIndex)) { + clickHouseVersion = ""; + imageRef = imageName; + } else if (tagIndex > 0) { + clickHouseVersion = digestIndex > tagIndex ? imageName.substring(tagIndex + 1, digestIndex) + : imageName.substring(tagIndex + 1); + imageRef = imageName; + } else if (requestedVersion == null) { + clickHouseVersion = ""; + imageRef = imageName; + } else { + clickHouseVersion = ClickHouseVersionUtils.of(requestedVersion).getYear() == 0 ? "" : requestedVersion; + imageRef = imageName + ":" + requestedVersion; + } + + String additionalPackages = value(source, ADDITIONAL_PACKAGES); + if (ClickHouseVersionUtils.check(clickHouseVersion, "(,21.3]")) { + if (additionalPackages == null) { + additionalPackages = "tzdata"; + } else if (!additionalPackages.contains("tzdata")) { + additionalPackages = additionalPackages + " tzdata"; + } + } + + String externalDatabase = value(source, DATABASE); + final String database; + final boolean localDatabase; + if (externalDatabase != null) { + if (!externalDatabase.startsWith("clickhouse_java_test_")) { + throw new RuntimeException("external database for tests should start with 'clickhouse_java_test_'"); + } + localDatabase = false; + database = externalDatabase; + } else { + localDatabase = true; + database = "clickhouse_java_" + UUID.randomUUID().toString().substring(0, 8) + "_test_" + + System.currentTimeMillis(); + } + + String proxy = value(source, PROXY_ADDRESS); + final String proxyHost; + final int proxyPort; + final String proxyImage; + if (proxy != null) { + int index = proxy.indexOf(':'); + if (index > 0) { + proxyHost = proxy.substring(0, index); + proxyPort = Integer.parseInt(proxy.substring(index + 1)); + } else { + proxyHost = proxy; + proxyPort = 8666; + } + proxyImage = ""; + } else { + proxyHost = ""; + proxyPort = -1; + String image = value(source, PROXY_IMAGE); + proxyImage = image == null ? DEFAULT_PROXY_IMAGE : image; + } + + String host = value(source, HOST); + String user = value(source, USER); + String password = value(source, PASSWORD); + String timezone = value(source, TIMEZONE); + + return new ClickHouseTestEnvironment(Collections.unmodifiableMap(source), containerMode, imageRef, + clickHouseVersion, additionalPackages, + host == null ? DEFAULT_HOST : host, + user == null ? DEFAULT_USER : user, + password == null ? DEFAULT_PASSWORD : password, + parseSecure(value(source, SECURE)), + timezone == null ? DEFAULT_TIMEZONE : timezone, + value(source, CONTAINER_ID), + database, localDatabase, proxyHost, proxyPort, proxyImage); + } + + String portOverride(ClickHouseProtocol protocol) { + return value(env, "TEST_CLICKHOUSE_" + protocol.name() + "_PORT"); + } + + ContainerMode getContainerMode() { + return containerMode; + } + + String getImageRef() { + return imageRef; + } + + String getClickHouseVersion() { + return clickHouseVersion; + } + + String getAdditionalPackages() { + return additionalPackages; + } + + String getHost() { + return host; + } + + String getUser() { + return user; + } + + String getPassword() { + return password; + } + + boolean isSecure() { + return secure; + } + + String getTimezone() { + return timezone; + } + + String getContainerName() { + return containerName; + } + + String getDatabase() { + return database; + } + + boolean isLocalDatabase() { + return localDatabase; + } + + String getProxyHost() { + return proxyHost; + } + + int getProxyPort() { + return proxyPort; + } + + String getProxyImage() { + return proxyImage; + } + + private static ContainerMode parseMode(String raw) { + if (raw == null) { + return ContainerMode.SINGLE; + } + if ("single".equalsIgnoreCase(raw)) { + return ContainerMode.SINGLE; + } + if ("cluster".equalsIgnoreCase(raw)) { + return ContainerMode.CLUSTER; + } + if ("none".equalsIgnoreCase(raw)) { + return ContainerMode.NONE; + } + throw new IllegalArgumentException( + "TEST_CLICKHOUSE_CONTAINER must be single, cluster, or none, but was '" + raw + "'"); + } + + private static boolean parseSecure(String raw) { + if (raw == null) { + return false; + } + if ("true".equalsIgnoreCase(raw) || "1".equals(raw)) { + return true; + } + if ("false".equalsIgnoreCase(raw) || "0".equals(raw)) { + return false; + } + throw new IllegalArgumentException( + "TEST_CLICKHOUSE_SECURE must be true or false, but was '" + raw + "'"); + } + + private static String value(Map env, String key) { + String raw = env.get(key); + if (raw == null) { + return null; + } + String trimmed = raw.trim(); + return trimmed.isEmpty() ? null : trimmed; + } +} diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironmentTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironmentTest.java new file mode 100644 index 000000000..44a041cd5 --- /dev/null +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironmentTest.java @@ -0,0 +1,161 @@ +package com.clickhouse.client; + +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +public class ClickHouseTestEnvironmentTest { + @DataProvider(name = "containerModes") + public static Object[][] containerModes() { + return new Object[][] { + { null, ClickHouseTestEnvironment.ContainerMode.SINGLE }, + { "", ClickHouseTestEnvironment.ContainerMode.SINGLE }, + { "single", ClickHouseTestEnvironment.ContainerMode.SINGLE }, + { "SINGLE", ClickHouseTestEnvironment.ContainerMode.SINGLE }, + { "cluster", ClickHouseTestEnvironment.ContainerMode.CLUSTER }, + { " none ", ClickHouseTestEnvironment.ContainerMode.NONE } + }; + } + + @Test(dataProvider = "containerModes", groups = { "unit" }) + public void testContainerMode(String raw, ClickHouseTestEnvironment.ContainerMode expected) { + ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(env(ClickHouseTestEnvironment.CONTAINER, raw)); + Assert.assertEquals(environment.getContainerMode(), expected); + } + + @Test(groups = { "unit" }) + public void testClickHouseVersionSystemPropertyIsRejected() { + Properties properties = new Properties(); + properties.setProperty(ClickHouseTestEnvironment.REMOVED_VERSION_PROPERTY, "24.8"); + try { + ClickHouseTestEnvironment.rejectRemovedOptions(properties); + Assert.fail("clickhouseVersion must be rejected"); + } catch (IllegalArgumentException expected) { + Assert.assertTrue(expected.getMessage().contains("clickhouseVersion")); + Assert.assertTrue(expected.getMessage().contains("TEST_CLICKHOUSE_IMAGE_VERSION")); + } + } + + @Test(groups = { "unit" }) + public void testAbsentClickHouseVersionPropertyIsAllowed() { + ClickHouseTestEnvironment.rejectRemovedOptions(new Properties()); + ClickHouseTestEnvironment.rejectRemovedOptions(null); + } + + @Test(groups = { "unit" }) + public void testRejectsUnknownContainerMode() { + try { + ClickHouseTestEnvironment.from(env(ClickHouseTestEnvironment.CONTAINER, "cloud")); + Assert.fail("cloud is not a container mode"); + } catch (IllegalArgumentException expected) { + Assert.assertTrue(expected.getMessage().contains("single, cluster, or none")); + } + } + + @DataProvider(name = "images") + public static Object[][] images() { + return new Object[][] { + { null, null, "clickhouse/clickhouse-server", "" }, + { null, "24.8", "clickhouse/clickhouse-server:24.8", "24.8" }, + { null, "latest", "clickhouse/clickhouse-server:latest", "" }, + { "repo/clickhouse:24.3", "25.8", "repo/clickhouse:24.3", "24.3" }, + { "repo/clickhouse:24.3@sha256:abc", null, "repo/clickhouse:24.3@sha256:abc", "24.3" }, + { "repo/clickhouse@sha256:abc", null, "repo/clickhouse@sha256:abc", "" } + }; + } + + @Test(dataProvider = "images", groups = { "unit" }) + public void testImageRef(String image, String version, String expectedRef, String expectedVersion) { + Map values = new HashMap(); + if (image != null) { + values.put(ClickHouseTestEnvironment.IMAGE, image); + } + if (version != null) { + values.put(ClickHouseTestEnvironment.IMAGE_VERSION, version); + } + ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(values); + Assert.assertEquals(environment.getImageRef(), expectedRef); + Assert.assertEquals(environment.getClickHouseVersion(), expectedVersion); + } + + @Test(groups = { "unit" }) + public void testOldClickHouseImageInstallsTzdata() { + ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from( + env(ClickHouseTestEnvironment.IMAGE_VERSION, "21.3")); + Assert.assertEquals(environment.getAdditionalPackages(), "tzdata"); + + Map values = env(ClickHouseTestEnvironment.IMAGE_VERSION, "21.3"); + values.put(ClickHouseTestEnvironment.ADDITIONAL_PACKAGES, "ca-certificates"); + Assert.assertEquals(ClickHouseTestEnvironment.from(values).getAdditionalPackages(), + "ca-certificates tzdata"); + } + + @Test(groups = { "unit" }) + public void testCurrentImageDoesNotInstallTzdata() { + ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from( + env(ClickHouseTestEnvironment.IMAGE_VERSION, "24.8")); + Assert.assertNull(environment.getAdditionalPackages()); + } + + @Test(groups = { "unit" }) + public void testConnectionDefaults() { + ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(Collections.emptyMap()); + Assert.assertEquals(environment.getHost(), "localhost"); + Assert.assertEquals(environment.getUser(), "default"); + Assert.assertEquals(environment.getPassword(), "test_default_password"); + Assert.assertFalse(environment.isSecure()); + Assert.assertEquals(environment.getTimezone(), "UTC"); + Assert.assertTrue(environment.isLocalDatabase()); + Assert.assertTrue(environment.getDatabase().startsWith("clickhouse_java_")); + } + + @Test(groups = { "unit" }) + public void testConnectionOverrides() { + Map values = new HashMap(); + values.put(ClickHouseTestEnvironment.HOST, "cloud.example"); + values.put(ClickHouseTestEnvironment.USER, "demo"); + values.put(ClickHouseTestEnvironment.PASSWORD, "secret"); + values.put(ClickHouseTestEnvironment.SECURE, "true"); + values.put(ClickHouseTestEnvironment.CONTAINER, "none"); + values.put("TEST_CLICKHOUSE_HTTP_PORT", "9440"); + ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(values); + + Assert.assertEquals(environment.getHost(), "cloud.example"); + Assert.assertEquals(environment.getUser(), "demo"); + Assert.assertEquals(environment.getPassword(), "secret"); + Assert.assertTrue(environment.isSecure()); + Assert.assertEquals(environment.getContainerMode(), ClickHouseTestEnvironment.ContainerMode.NONE); + Assert.assertEquals(environment.portOverride(ClickHouseProtocol.HTTP), "9440"); + } + + @Test(groups = { "unit" }) + public void testExternalDatabaseMustUseTestPrefix() { + try { + ClickHouseTestEnvironment.from(env(ClickHouseTestEnvironment.DATABASE, "default")); + Assert.fail("external database name must be rejected"); + } catch (RuntimeException expected) { + Assert.assertTrue(expected.getMessage().contains("clickhouse_java_test_")); + } + } + + @Test(groups = { "unit" }) + public void testExternalDatabase() { + ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from( + env(ClickHouseTestEnvironment.DATABASE, "clickhouse_java_test_ci")); + Assert.assertFalse(environment.isLocalDatabase()); + Assert.assertEquals(environment.getDatabase(), "clickhouse_java_test_ci"); + } + + private static Map env(String key, String value) { + Map values = new HashMap(); + if (value != null) { + values.put(key, value); + } + return values; + } +} diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java new file mode 100644 index 000000000..4e9cf11a2 --- /dev/null +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java @@ -0,0 +1,128 @@ +package com.clickhouse.client; + +import org.testcontainers.containers.BindMode; +import org.testcontainers.containers.Container; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.wait.strategy.Wait; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; + +import static java.time.temporal.ChronoUnit.SECONDS; + +/** + * Three ClickHouse replicas of one shard, with a shared Keeper and nginx in front. + */ +final class ClusterClickHouseContainerStarter extends ClickHouseContainerStarter { + static final String CLUSTER_NAME = "test_cluster"; + static final int NODE_COUNT = 3; + private static final String NGINX_CONFIG = "containers/nginx/nginx.conf"; + private static final String KEEPER_CONFIG = "containers/clickhouse-keeper/keeper_config.xml"; + private static final int KEEPER_PORT = 9181; + + private final GenericContainer keeper; + private final List> nodes; + private final GenericContainer nginx; + + ClusterClickHouseContainerStarter(ClickHouseTestEnvironment environment, Network network) { + super(environment, network); + String baseName = environment.getContainerName(); + this.keeper = new GenericContainer<>(environment.getImageRef()) + .withCreateContainerCmdModifier(command -> { + if (baseName != null) { + command.withName(baseName + "-keeper"); + } + }) + .withNetwork(network) + .withNetworkAliases("clickhouse-keeper") + .withCommand("clickhouse-keeper", "--config-file=/etc/clickhouse-keeper/keeper_config.xml") + .withClasspathResourceMapping(KEEPER_CONFIG, "/etc/clickhouse-keeper/keeper_config.xml", + BindMode.READ_ONLY) + .withExposedPorts(KEEPER_PORT) + .waitingFor(Wait.forListeningPort().withStartupTimeout(Duration.of(120, SECONDS))); + + List> created = new ArrayList>(NODE_COUNT); + for (int index = 1; index <= NODE_COUNT; index++) { + String name = baseName == null ? null : baseName + "-" + index; + created.add(newClickHouseServer("clickhouse-" + index, name, "r" + index)); + } + this.nodes = created; + + String nginxName = baseName == null ? null : baseName + "-nginx"; + this.nginx = newNginx(nginxName, NGINX_CONFIG); + } + + @Override + public String replicatedClusterName() { + return CLUSTER_NAME; + } + + @Override + public void start() { + List> started = new ArrayList>(); + try { + keeper.start(); + for (GenericContainer node : nodes) { + node.start(); + started.add(node); + } + nginx.start(); + } catch (RuntimeException failure) { + stopQuietly(nginx); + for (int index = started.size() - 1; index >= 0; index--) { + stopQuietly(started.get(index)); + } + stopQuietly(keeper); + throw failure; + } + } + + @Override + public void stop() { + stopQuietly(nginx); + for (int index = nodes.size() - 1; index >= 0; index--) { + stopQuietly(nodes.get(index)); + } + stopQuietly(keeper); + } + + @Override + public boolean isRunning() { + if (!keeper.isRunning() || !nginx.isRunning()) { + return false; + } + for (GenericContainer node : nodes) { + if (!node.isRunning()) { + return false; + } + } + return true; + } + + @Override + public String getHost() { + return nginx.getHost(); + } + + @Override + public int getMappedPort(int port) { + return nginx.getMappedPort(port); + } + + @Override + public Container.ExecResult execInContainer(String... command) throws Exception { + return nodes.get(0).execInContainer(command); + } + + @Override + public GenericContainer getEndpointContainer() { + return nginx; + } + + @Override + protected List> clickHouseServers() { + return nodes; + } +} diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/SingleClickHouseContainerStarter.java b/clickhouse-client/src/test/java/com/clickhouse/client/SingleClickHouseContainerStarter.java new file mode 100644 index 000000000..c996ec62a --- /dev/null +++ b/clickhouse-client/src/test/java/com/clickhouse/client/SingleClickHouseContainerStarter.java @@ -0,0 +1,60 @@ +package com.clickhouse.client; + +import org.testcontainers.containers.Container; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; + +import java.util.Collections; +import java.util.List; + +/** + * One ClickHouse server, published on the Docker host. + */ +final class SingleClickHouseContainerStarter extends ClickHouseContainerStarter { + private final GenericContainer container; + + SingleClickHouseContainerStarter(ClickHouseTestEnvironment environment, Network network) { + super(environment, network); + this.container = newClickHouseServer(FRONTEND_ALIAS, environment.getContainerName()); + } + + @Override + public void start() { + container.start(); + } + + @Override + public void stop() { + stopQuietly(container); + } + + @Override + public boolean isRunning() { + return container.isRunning(); + } + + @Override + public String getHost() { + return container.getHost(); + } + + @Override + public int getMappedPort(int port) { + return container.getMappedPort(port); + } + + @Override + public Container.ExecResult execInContainer(String... command) throws Exception { + return container.execInContainer(command); + } + + @Override + public GenericContainer getEndpointContainer() { + return container; + } + + @Override + protected List> clickHouseServers() { + return Collections.singletonList(container); + } +} diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-cluster/config.d/custom_config.xml b/clickhouse-client/src/test/resources/containers/clickhouse-cluster/config.d/custom_config.xml new file mode 100644 index 000000000..bf30cb5d1 --- /dev/null +++ b/clickhouse-client/src/test/resources/containers/clickhouse-cluster/config.d/custom_config.xml @@ -0,0 +1,87 @@ + + 8123 + 8443 + 9000 + 9440 + 9004 + 9005 + 9009 + + 9100 + + + + /etc/clickhouse-server/certs/localhost.crt + /etc/clickhouse-server/certs/localhost.key + relaxed + /etc/clickhouse-server/certs/marsnet_ca.crt + true + sslv2,sslv3 + true + + + false + /etc/clickhouse-server/certs/marsnet_ca.crt + true + sslv2,sslv3 + true + relaxed + + RejectCertificateHandler + + + + + custom_ + + + + + + true + + clickhouse-1 + 9000 + default + test_default_password + + + clickhouse-2 + 9000 + default + test_default_password + + + clickhouse-3 + 9000 + default + test_default_password + + + + + + + /clickhouse/task_queue/ddl + + + /var/lib/clickhouse/format_schemas/ + + + test_cluster + s1 + + + + /clickhouse/databases/{uuid} + {replica} + + + + clickhouse-keeper + 9181 + + + + 42 + diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-cluster/users.d/cluster_quorum.xml b/clickhouse-client/src/test/resources/containers/clickhouse-cluster/users.d/cluster_quorum.xml new file mode 100644 index 000000000..ac328ea1c --- /dev/null +++ b/clickhouse-client/src/test/resources/containers/clickhouse-cluster/users.d/cluster_quorum.xml @@ -0,0 +1,9 @@ + + + + + 3 + 600000 + + + diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml b/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml new file mode 100644 index 000000000..9f1018598 --- /dev/null +++ b/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml @@ -0,0 +1,23 @@ + + + warning + true + + + 9181 + 1 + /var/lib/clickhouse/coordination/log + /var/lib/clickhouse/coordination/snapshots + + 10000 + 30000 + + + + 1 + clickhouse-keeper + 9234 + + + + diff --git a/clickhouse-client/src/test/resources/containers/nginx/nginx.conf b/clickhouse-client/src/test/resources/containers/nginx/nginx.conf new file mode 100644 index 000000000..d4ac8b61f --- /dev/null +++ b/clickhouse-client/src/test/resources/containers/nginx/nginx.conf @@ -0,0 +1,79 @@ +worker_processes 1; +error_log stderr notice; +pid /tmp/nginx.pid; + +events { + worker_connections 1024; +} + +# TCP passthrough to clickhouse-1, clickhouse-2, and clickhouse-3. +# Those servers are replicas of one shard, so round-robin can land on any of them. +stream { + proxy_connect_timeout 60s; + proxy_timeout 24h; + + upstream clickhouse_http { + server clickhouse-1:8123; + server clickhouse-2:8123; + server clickhouse-3:8123; + } + upstream clickhouse_https { + server clickhouse-1:8443; + server clickhouse-2:8443; + server clickhouse-3:8443; + } + upstream clickhouse_tcp { + server clickhouse-1:9000; + server clickhouse-2:9000; + server clickhouse-3:9000; + } + upstream clickhouse_tcp_secure { + server clickhouse-1:9440; + server clickhouse-2:9440; + server clickhouse-3:9440; + } + upstream clickhouse_mysql { + server clickhouse-1:9004; + server clickhouse-2:9004; + server clickhouse-3:9004; + } + upstream clickhouse_postgresql { + server clickhouse-1:9005; + server clickhouse-2:9005; + server clickhouse-3:9005; + } + upstream clickhouse_grpc { + server clickhouse-1:9100; + server clickhouse-2:9100; + server clickhouse-3:9100; + } + + server { + listen 8123; + proxy_pass clickhouse_http; + } + server { + listen 8443; + proxy_pass clickhouse_https; + } + server { + listen 9000; + proxy_pass clickhouse_tcp; + } + server { + listen 9440; + proxy_pass clickhouse_tcp_secure; + } + server { + listen 9004; + proxy_pass clickhouse_mysql; + } + server { + listen 9005; + proxy_pass clickhouse_postgresql; + } + server { + listen 9100; + proxy_pass clickhouse_grpc; + } +} From 4114c09d2e6887281b0908ea7fcd87b9f736c93c Mon Sep 17 00:00:00 2001 From: Sergey Chernov Date: Mon, 5 Oct 2026 16:53:34 -0700 Subject: [PATCH 2/7] Fixed keeper config to start cluster in github runner --- .../resources/containers/clickhouse-keeper/keeper_config.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml b/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml index 9f1018598..9889db185 100644 --- a/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml +++ b/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml @@ -1,8 +1,10 @@ warning - true + 1 + + 0.0.0.0 9181 1 From d16ec2dc950de2bc70e85b8aac58437af4f7e372 Mon Sep 17 00:00:00 2001 From: Sergey Chernov Date: Tue, 6 Oct 2026 18:29:07 -0700 Subject: [PATCH 3/7] Fixed selecting database and user --- .gitignore | 3 ++ CONTRIBUTING.md | 4 +- .../client/ClickHouseContainerStarter.java | 42 ++++++++++------ .../client/ClickHouseServerForTest.java | 49 +++++++++++-------- .../client/ClickHouseTestEnvironment.java | 4 ++ .../client/ClickHouseTestEnvironmentTest.java | 15 ++++++ .../ClusterClickHouseContainerStarter.java | 8 ++- .../config.d/custom_config.xml | 13 ++++- .../clickhouse-keeper/keeper_config.xml | 2 +- .../config.d/custom_config.xml | 2 +- .../resources/containers/nginx/nginx.conf | 36 ++++++++++---- .../com/clickhouse/client/ProxyTests.java | 4 +- .../AbstractJSONEachRowFormatReaderTests.java | 3 ++ .../internal/BaseReaderTests.java | 5 +- .../client/datatypes/DataTypeTests.java | 4 +- .../clickhouse/client/query/QueryTests.java | 13 ++--- pom.xml | 4 +- 17 files changed, 145 insertions(+), 66 deletions(-) diff --git a/.gitignore b/.gitignore index 234381faa..b6dd9374c 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ # Eclipse TestNG plugin test-output/ +**/.apt_generated/ +**/.apt_generated_tests/ + # Intellij .idea/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5ba6ca6c4..80ab28bdc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -144,7 +144,7 @@ Integration tests usually require [Docker](https://docs.docker.com/engine/instal | Variable | Default | Purpose | | --- | --- | --- | | `TEST_CLICKHOUSE_CONTAINER` | `single` | `single` starts one server, `cluster` starts three servers behind nginx, `none` starts nothing | -| `TEST_CLICKHOUSE_IMAGE_VERSION` | | Image tag used when a container is started, for example `24.8` | +| `TEST_CLICKHOUSE_IMAGE_VERSION` | | Image tag used when a container is started, for example `24.8` (`TEST_CLICKHOUSE_VERSION` is also accepted) | | `TEST_CLICKHOUSE_IMAGE` | `clickhouse/clickhouse-server` | Image repository | | `TEST_CLICKHOUSE_HOST` | `localhost` | Host used when no container is started | | `TEST_CLICKHOUSE_USER` | `default` | User name | @@ -162,7 +162,7 @@ To test against a specific ClickHouse version: TEST_CLICKHOUSE_IMAGE_VERSION=24.8 mvn -pl test ``` -To use an existing server instead of Docker, set `TEST_CLICKHOUSE_CONTAINER=none` and point `TEST_CLICKHOUSE_HOST` at that server. The server must accept `TEST_CLICKHOUSE_USER` / `TEST_CLICKHOUSE_PASSWORD` (defaults: `default` / `test_default_password`) with DDL and DML privileges. For ClickHouse Cloud also set `TEST_CLICKHOUSE_SECURE=true`. +To use an existing server instead of Docker, set `TEST_CLICKHOUSE_CONTAINER=none` and point `TEST_CLICKHOUSE_HOST` at that server (defaults to port `8123`). The server must accept `TEST_CLICKHOUSE_USER` / `TEST_CLICKHOUSE_PASSWORD` (defaults: `default` / `test_default_password`) with DDL and DML privileges. When containers are started by tests, ClickHouse HTTP port is `18123` to avoid colliding with any locally running ClickHouse instance. For ClickHouse Cloud also set `TEST_CLICKHOUSE_SECURE=true`. ```bash TEST_CLICKHOUSE_CONTAINER=none \ diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java index b719597c1..b26710ce9 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java @@ -23,6 +23,8 @@ public abstract class ClickHouseContainerStarter { private static final Logger LOGGER = LoggerFactory.getLogger(ClickHouseContainerStarter.class); + public static final int HTTP_PORT = 18123; + static final String FRONTEND_ALIAS = "clickhouse"; static final String CONTAINER_TMP_DIR = "/tmp"; private static final String CUSTOM_DIRECTORY = "/custom"; @@ -72,19 +74,29 @@ public String replicatedClusterName() { } /** - * Runs a query inside every ClickHouse server. + * Creates the test database. A cluster creates one Replicated database, with each + * node joining as its own replica of shard {@code s1}. */ - public final boolean execQueryOnServers(String sql, String user, String password) throws Exception { - boolean succeeded = true; - for (GenericContainer server : clickHouseServers()) { - Container.ExecResult result = server.execInContainer("clickhouse-client", - "-u", user, "--password", password, "--query", sql); - if (result.getExitCode() != 0) { - LOGGER.error("query failed: stderr={}, stdout={}", result.getStderr(), result.getStdout()); - succeeded = false; - } + public final void createDatabase(String database, String user, String password) throws Exception { + if (replicatedClusterName() == null) { + execQuery("CREATE DATABASE IF NOT EXISTS `" + database + "`", user, password, clickHouseServers().get(0)); + return; + } + List> servers = clickHouseServers(); + for (int index = 0; index < servers.size(); index++) { + String sql = "CREATE DATABASE IF NOT EXISTS `" + database + "` ENGINE = Replicated(" + + "'/clickhouse/databases/" + database + "', 's1', 'r" + (index + 1) + "')"; + execQuery(sql, user, password, servers.get(index)); + } + } + + private static void execQuery(String sql, String user, String password, GenericContainer server) throws Exception { + Container.ExecResult result = server.execInContainer("clickhouse-client", + "-u", user, "--password", password, "--query", sql); + if (result.getExitCode() != 0) { + throw new IllegalStateException("Failed to execute [" + sql + "]: " + result.getStderr() + + result.getStdout()); } - return succeeded; } protected abstract List> clickHouseServers(); @@ -121,7 +133,7 @@ protected final GenericContainer newClickHouseServer(String networkAlias, Str .withEnv("TZ", environment.getTimezone()) .withExposedPorts( ClickHouseProtocol.GRPC.getDefaultPort(), - ClickHouseProtocol.HTTP.getDefaultPort(), + HTTP_PORT, ClickHouseProtocol.HTTP.getDefaultSecurePort(), ClickHouseProtocol.MYSQL.getDefaultPort(), ClickHouseProtocol.TCP.getDefaultPort(), @@ -142,7 +154,7 @@ protected final GenericContainer newClickHouseServer(String networkAlias, Str .withClasspathResourceMapping("containers/clickhouse-cluster/users.d/cluster_quorum.xml", CUSTOM_DIRECTORY + "/users.d/cluster_quorum.xml", BindMode.READ_ONLY); } - return container.waitingFor(Wait.forHttp("/ping").forPort(ClickHouseProtocol.HTTP.getDefaultPort()) + return container.waitingFor(Wait.forHttp("/ping").forPort(HTTP_PORT) .forStatusCode(200).withStartupTimeout(Duration.of(600, SECONDS))); } @@ -158,13 +170,13 @@ protected final GenericContainer newNginx(String containerName, String config .withClasspathResourceMapping(configResource, "/etc/nginx/nginx.conf", BindMode.READ_ONLY) .withExposedPorts( ClickHouseProtocol.GRPC.getDefaultPort(), - ClickHouseProtocol.HTTP.getDefaultPort(), + HTTP_PORT, ClickHouseProtocol.HTTP.getDefaultSecurePort(), ClickHouseProtocol.MYSQL.getDefaultPort(), ClickHouseProtocol.TCP.getDefaultPort(), ClickHouseProtocol.TCP.getDefaultSecurePort(), ClickHouseProtocol.POSTGRESQL.getDefaultPort()) - .waitingFor(Wait.forHttp("/ping").forPort(ClickHouseProtocol.HTTP.getDefaultPort()) + .waitingFor(Wait.forHttp("/ping").forPort(HTTP_PORT) .forStatusCode(200).withStartupTimeout(Duration.of(600, SECONDS))); } diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java index 399ca0e30..bd8bd0871 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java @@ -2,12 +2,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.Container; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; +import com.clickhouse.client.ClickHouseTestEnvironment.ContainerMode; + import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.InetSocketAddress; @@ -170,6 +171,10 @@ public static boolean isCloud() { return environment.isSecure(); } + public static boolean isCluster() { + return environment.getContainerMode() == ContainerMode.CLUSTER; + } + @BeforeSuite(groups = {"integration"}) public static void beforeSuite() { if (starter != null) { @@ -185,8 +190,8 @@ public static void beforeSuite() { .toString(), e); } } - if (starter.isRunning() && !createDatabaseOnServers()) { - throw new RuntimeException("Failed to create database"); + if (starter.isRunning()) { + createDatabaseOnServers(); } return; } @@ -215,26 +220,25 @@ public static String getDatabase() { return environment.getDatabase(); } - private static boolean createDatabaseOnServers() { + private static void createDatabaseOnServers() { String database = getDatabase(); - String cluster = starter.replicatedClusterName(); - try { - if (cluster == null) { - return starter.execQueryOnServers("CREATE DATABASE IF NOT EXISTS `" + database + "`", - getUsername(), getPassword()); - } - String sql = "CREATE DATABASE IF NOT EXISTS `" + database + "` ON CLUSTER " + cluster - + " ENGINE = Replicated('/clickhouse/databases/" + database + "', '{shard}', '{replica}')"; - Container.ExecResult result = starter.execInContainer("clickhouse-client", - "-u", getUsername(), "--password", getPassword(), "--query", sql); - if (result.getExitCode() != 0) { - LOGGER.error("query failed: stderr={}, stdout={}", result.getStderr(), result.getStdout()); - return false; + Exception lastFailure = null; + for (int attempt = 1; attempt <= 10; attempt++) { + try { + starter.createDatabase(database, getUsername(), getPassword()); + return; + } catch (Exception e) { + lastFailure = e; + LOGGER.warn("Creating database {} failed on attempt {}", database, attempt); + try { + Thread.sleep(2000L); + } catch (InterruptedException interrupted) { + Thread.currentThread().interrupt(); + break; + } } - return true; - } catch (Exception e) { - throw new RuntimeException("Failed to create database", e); } + throw new RuntimeException("Failed to create database " + database, lastFailure); } public static boolean runQuery(String sql) { @@ -277,7 +281,10 @@ public static boolean runQuery(String sql) { private static Endpoint resolve(ClickHouseProtocol protocol, int port, boolean applyOverride) { if (starter != null) { - return new Endpoint(starter.getHost(), starter.getMappedPort(port)); + int containerPort = (port == ClickHouseProtocol.HTTP.getDefaultPort()) + ? ClickHouseContainerStarter.HTTP_PORT + : port; + return new Endpoint(starter.getHost(), starter.getMappedPort(containerPort)); } if (applyOverride) { String override = environment.portOverride(protocol); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironment.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironment.java index bef09c5aa..4029ace5e 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironment.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironment.java @@ -13,6 +13,7 @@ final class ClickHouseTestEnvironment { static final String CONTAINER = "TEST_CLICKHOUSE_CONTAINER"; static final String IMAGE = "TEST_CLICKHOUSE_IMAGE"; static final String IMAGE_VERSION = "TEST_CLICKHOUSE_IMAGE_VERSION"; + static final String VERSION = "TEST_CLICKHOUSE_VERSION"; static final String HOST = "TEST_CLICKHOUSE_HOST"; static final String USER = "TEST_CLICKHOUSE_USER"; static final String PASSWORD = "TEST_CLICKHOUSE_PASSWORD"; @@ -105,6 +106,9 @@ static ClickHouseTestEnvironment from(Map env) { imageName = DEFAULT_IMAGE; } String requestedVersion = value(source, IMAGE_VERSION); + if (requestedVersion == null) { + requestedVersion = value(source, VERSION); + } String clickHouseVersion; String imageRef; int tagIndex = imageName.indexOf(':'); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironmentTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironmentTest.java index 44a041cd5..d3eddcfeb 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironmentTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironmentTest.java @@ -83,6 +83,21 @@ public void testImageRef(String image, String version, String expectedRef, Strin Assert.assertEquals(environment.getClickHouseVersion(), expectedVersion); } + @Test(groups = { "unit" }) + public void testVersionFallback() { + Map values = new HashMap(); + values.put(ClickHouseTestEnvironment.VERSION, "26.9"); + ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(values); + Assert.assertEquals(environment.getImageRef(), "clickhouse/clickhouse-server:26.9"); + Assert.assertEquals(environment.getClickHouseVersion(), "26.9"); + + // IMAGE_VERSION takes precedence over VERSION + values.put(ClickHouseTestEnvironment.IMAGE_VERSION, "25.8"); + environment = ClickHouseTestEnvironment.from(values); + Assert.assertEquals(environment.getImageRef(), "clickhouse/clickhouse-server:25.8"); + Assert.assertEquals(environment.getClickHouseVersion(), "25.8"); + } + @Test(groups = { "unit" }) public void testOldClickHouseImageInstallsTzdata() { ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from( diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java index 4e9cf11a2..9cd96dd7f 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java @@ -31,17 +31,21 @@ final class ClusterClickHouseContainerStarter extends ClickHouseContainerStarter String baseName = environment.getContainerName(); this.keeper = new GenericContainer<>(environment.getImageRef()) .withCreateContainerCmdModifier(command -> { + command.withEntrypoint("/bin/sh"); if (baseName != null) { command.withName(baseName + "-keeper"); } }) .withNetwork(network) .withNetworkAliases("clickhouse-keeper") - .withCommand("clickhouse-keeper", "--config-file=/etc/clickhouse-keeper/keeper_config.xml") + .withCommand("-c", "mkdir -p /var/lib/clickhouse/coordination/log" + + " /var/lib/clickhouse/coordination/snapshots" + + " && exec clickhouse-keeper --config-file=/etc/clickhouse-keeper/keeper_config.xml") .withClasspathResourceMapping(KEEPER_CONFIG, "/etc/clickhouse-keeper/keeper_config.xml", BindMode.READ_ONLY) .withExposedPorts(KEEPER_PORT) - .waitingFor(Wait.forListeningPort().withStartupTimeout(Duration.of(120, SECONDS))); + .waitingFor(Wait.forLogMessage(".*Listening for.*", 1) + .withStartupTimeout(Duration.of(120, SECONDS))); List> created = new ArrayList>(NODE_COUNT); for (int index = 1; index <= NODE_COUNT; index++) { diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-cluster/config.d/custom_config.xml b/clickhouse-client/src/test/resources/containers/clickhouse-cluster/config.d/custom_config.xml index bf30cb5d1..db7774164 100644 --- a/clickhouse-client/src/test/resources/containers/clickhouse-cluster/config.d/custom_config.xml +++ b/clickhouse-client/src/test/resources/containers/clickhouse-cluster/config.d/custom_config.xml @@ -1,5 +1,5 @@ - 8123 + 18123 8443 9000 9440 @@ -73,7 +73,7 @@ - /clickhouse/databases/{uuid} + /clickhouse/tables/{uuid}/{shard} {replica} @@ -83,5 +83,14 @@ + + + /etc/clickhouse-server/users.xml + + + /clickhouse/access/ + + + 42 diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml b/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml index 9889db185..fd66e5634 100644 --- a/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml +++ b/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml @@ -1,6 +1,6 @@ - warning + information 1 diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-server/config.d/custom_config.xml b/clickhouse-client/src/test/resources/containers/clickhouse-server/config.d/custom_config.xml index 6d6b60d3c..ac0897704 100644 --- a/clickhouse-client/src/test/resources/containers/clickhouse-server/config.d/custom_config.xml +++ b/clickhouse-client/src/test/resources/containers/clickhouse-server/config.d/custom_config.xml @@ -1,5 +1,5 @@ - 8123 + 18123 8443 9000 9440 diff --git a/clickhouse-client/src/test/resources/containers/nginx/nginx.conf b/clickhouse-client/src/test/resources/containers/nginx/nginx.conf index d4ac8b61f..d735f7e30 100644 --- a/clickhouse-client/src/test/resources/containers/nginx/nginx.conf +++ b/clickhouse-client/src/test/resources/containers/nginx/nginx.conf @@ -6,17 +6,37 @@ events { worker_connections 1024; } +http { + upstream clickhouse_http { + hash $http_x_clickhouse_replica_tag consistent; + server clickhouse-1:18123; + server clickhouse-2:18123; + server clickhouse-3:18123; + } + + server { + listen 18123; + client_max_body_size 0; + + location / { + proxy_pass http://clickhouse_http; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_http_version 1.1; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + proxy_request_buffering off; + proxy_buffering off; + } + } +} + # TCP passthrough to clickhouse-1, clickhouse-2, and clickhouse-3. -# Those servers are replicas of one shard, so round-robin can land on any of them. stream { proxy_connect_timeout 60s; proxy_timeout 24h; - upstream clickhouse_http { - server clickhouse-1:8123; - server clickhouse-2:8123; - server clickhouse-3:8123; - } upstream clickhouse_https { server clickhouse-1:8443; server clickhouse-2:8443; @@ -48,10 +68,6 @@ stream { server clickhouse-3:9100; } - server { - listen 8123; - proxy_pass clickhouse_http; - } server { listen 8443; proxy_pass clickhouse_https; diff --git a/client-v2/src/test/java/com/clickhouse/client/ProxyTests.java b/client-v2/src/test/java/com/clickhouse/client/ProxyTests.java index 288be2c01..42acb103d 100644 --- a/client-v2/src/test/java/com/clickhouse/client/ProxyTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/ProxyTests.java @@ -77,8 +77,9 @@ public void testInsert() throws Exception { client.set(clientBuilder(initProxy(), false).build()); addProxyStub(); + client.get().execute("DROP TABLE IF EXISTS " + tableName).get(); client.get().execute(createSQL).get(); - client.get().register(SamplePOJO.class, client.get().getTableSchema(tableName, "default")); + client.get().register(SamplePOJO.class, client.get().getTableSchema(tableName)); List simplePOJOs = new ArrayList<>(); for (int i = 0; i < 1000; i++) { @@ -217,6 +218,7 @@ private Client.Builder clientBuilder(int proxyPort, boolean onlyNewImplementatio .addEndpoint(Protocol.HTTP, "clickhouse", 8123, false) .setUsername("default") .setPassword(ClickHouseServerForTest.getPassword()) + .setDefaultDatabase(ClickHouseServerForTest.getDatabase()) .addProxy(ProxyType.HTTP, "localhost", proxyPort); } diff --git a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/AbstractJSONEachRowFormatReaderTests.java b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/AbstractJSONEachRowFormatReaderTests.java index b5225eb7b..11feae549 100644 --- a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/AbstractJSONEachRowFormatReaderTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/AbstractJSONEachRowFormatReaderTests.java @@ -64,6 +64,7 @@ public void setUpPrimitivesTable() throws Exception { .addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud()) .setUsername("default") .setPassword(ClickHouseServerForTest.getPassword()) + .setDefaultDatabase(ClickHouseServerForTest.getDatabase()) .build()) { setupClient.execute("DROP TABLE IF EXISTS " + primitivesTable).get().close(); @@ -103,6 +104,7 @@ public void tearDownPrimitivesTable() throws Exception { .addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud()) .setUsername("default") .setPassword(ClickHouseServerForTest.getPassword()) + .setDefaultDatabase(ClickHouseServerForTest.getDatabase()) .build()) { teardownClient.execute("DROP TABLE IF EXISTS " + primitivesTable).get().close(); } @@ -115,6 +117,7 @@ public void setUp() { .addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud()) .setUsername("default") .setPassword(ClickHouseServerForTest.getPassword()) + .setDefaultDatabase(ClickHouseServerForTest.getDatabase()) .build(); } diff --git a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BaseReaderTests.java b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BaseReaderTests.java index 2cfea137d..78e5b0c18 100644 --- a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BaseReaderTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BaseReaderTests.java @@ -571,8 +571,9 @@ private Client.Builder newClient() { ClickHouseNode node = getServer(ClickHouseProtocol.HTTP); return new Client.Builder() .addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud()) - .setUsername("default") - .setPassword(ClickHouseServerForTest.getPassword()); + .setUsername(ClickHouseServerForTest.getUsername()) + .setPassword(ClickHouseServerForTest.getPassword()) + .setDefaultDatabase(ClickHouseServerForTest.getDatabase()); } @Test(groups = {"integration"}) diff --git a/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java b/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java index 70ba11b23..5ecbf7a3d 100644 --- a/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java @@ -82,8 +82,9 @@ public void setUp() throws IOException { ClickHouseNode node = getServer(ClickHouseProtocol.HTTP); client = new Client.Builder() .addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud()) - .setUsername("default") + .setUsername(ClickHouseServerForTest.getUsername()) .setPassword(ClickHouseServerForTest.getPassword()) + .setDefaultDatabase(ClickHouseServerForTest.getDatabase()) .compressClientRequest(useClientCompression) .useHttpCompression(useHttpCompression) .build(); @@ -3231,6 +3232,7 @@ private Client.Builder newClient() { .addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud()) .setUsername("default") .setPassword(ClickHouseServerForTest.getPassword()) + .setDefaultDatabase(ClickHouseServerForTest.getDatabase()) .compressClientRequest(useClientCompression) .useHttpCompression(useHttpCompression); } 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 86181bc21..7020468ac 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 @@ -1474,7 +1474,7 @@ void testDataTypes(List columns, List> valueGenerators, testDataTypes(columns, valueGenerators, verifiers, Collections.emptyMap()); } void testDataTypes(List columns, List> valueGenerators, List> verifiers, Map serverSettings) { - final String table = "data_types_test_table"; + final String table = "data_types_test_table"; try { // Drop table @@ -1491,7 +1491,7 @@ void testDataTypes(List columns, List> valueGenerators, createStmtBuilder.append(column).append(", "); } createStmtBuilder.setLength(createStmtBuilder.length() - 2); - createStmtBuilder.append(") ENGINE = MergeTree ORDER BY tuple()"); + createStmtBuilder.append(") ENGINE = ").append(ClickHouseServerForTest.isCluster() ? "ReplicatedMergeTree" : "MergeTree").append(" ORDER BY tuple()"); client.execute(createStmtBuilder.toString(), commandSettings).get(10, TimeUnit.SECONDS); @@ -1523,10 +1523,10 @@ void testDataTypes(List columns, List> valueGenerators, Future response = client.query(selectStmtBuilder.toString(), settings); TableSchema schema = client.getTableSchema(table); - try { - QueryResponse queryResponse = response.get(); + try (QueryResponse queryResponse = response.get()) { + ClickHouseBinaryFormatReader reader = client.newBinaryFormatReader(queryResponse, schema); - Assert.assertNotNull(reader.next()); + Assert.assertNotNull(reader.next(), "Result is empty but should not"); Assert.assertEquals(verifiers.size(), columns.size(), "Number of verifiers should match number of columns"); int colIndex = 0; for (Consumer verifier : verifiers) { @@ -1686,7 +1686,8 @@ protected List> prepareDataSet(String table, List co createStmtBuilder.append(column).append(", "); } createStmtBuilder.setLength(createStmtBuilder.length() - 2); - createStmtBuilder.append(") ENGINE = MergeTree ORDER BY tuple()"); + final String engine = ClickHouseServerForTest.isCluster() ? "ReplicatedMergeTree" : "MergeTree"; + createStmtBuilder.append(") ENGINE = ").append(engine).append(" ORDER BY tuple()"); client.execute(createStmtBuilder.toString(), settings).get(10, TimeUnit.SECONDS); // Insert data diff --git a/pom.xml b/pom.xml index 1c7cd7e48..13d0ac041 100644 --- a/pom.xml +++ b/pom.xml @@ -148,7 +148,7 @@ 2.22.0 2.22 - 17 + 1.8 1.8 1.8 false @@ -551,7 +551,7 @@ maven-compiler-plugin ${minSourceJdk} - ${minSourceJdk} + ${minTargetJdk} true -Xlint:all From 555048bdd3460dcb3a163f038cf6733892b41c4b Mon Sep 17 00:00:00 2001 From: Sergey Chernov Date: Wed, 7 Oct 2026 09:09:37 -0700 Subject: [PATCH 4/7] made ReplicatedMergeTree as default engine on cluster setup --- .../clickhouse-cluster/users.d/cluster_quorum.xml | 1 + .../test/java/com/clickhouse/client/query/QueryTests.java | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-cluster/users.d/cluster_quorum.xml b/clickhouse-client/src/test/resources/containers/clickhouse-cluster/users.d/cluster_quorum.xml index ac328ea1c..29528d8e5 100644 --- a/clickhouse-client/src/test/resources/containers/clickhouse-cluster/users.d/cluster_quorum.xml +++ b/clickhouse-client/src/test/resources/containers/clickhouse-cluster/users.d/cluster_quorum.xml @@ -4,6 +4,7 @@ 3 600000 + ReplicatedMergeTree 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 7020468ac..93da8da20 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 @@ -2208,7 +2208,7 @@ public void testReadingJSONValues() throws Exception { CommandSettings commandSettings = new CommandSettings(); commandSettings.serverSetting("allow_experimental_json_type", "1"); client.execute("DROP TABLE IF EXISTS test_json_values", commandSettings).get(1, TimeUnit.SECONDS); - client.execute("CREATE TABLE test_json_values (json JSON) ENGINE = MergeTree ORDER BY ()", commandSettings).get(1, TimeUnit.SECONDS); + client.execute("CREATE TABLE test_json_values (json JSON)", commandSettings).get(1, TimeUnit.SECONDS); client.execute("INSERT INTO test_json_values VALUES ('{\"a\" : {\"b\" : 42}, \"c\" : [1, 2, 3]}')", commandSettings).get(1, TimeUnit.SECONDS); @@ -2258,9 +2258,10 @@ protected Client.Builder newClient() { public void testReadingSimpleAggregateFunction() throws Exception { final String tableName = "simple_aggregate_function_test_table"; client.execute("DROP TABLE IF EXISTS " + tableName).get(); + final String tableEngine = ClickHouseServerForTest.isCluster() ? "ReplicatedMergeTree" : "MergeTree"; client.execute("CREATE TABLE `" + tableName + "` " + "(idx UInt8, lowest_value SimpleAggregateFunction(min, UInt8), count SimpleAggregateFunction(sum, Int64), mp SimpleAggregateFunction(maxMap, Map(UInt8, UInt8))) " + - "ENGINE MergeTree ORDER BY ();").get(); + "ENGINE " + tableEngine + " ORDER BY ();").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)) { @@ -2282,10 +2283,11 @@ public void testReadingSimpleAggregateFunction() throws Exception { @Test(groups = {"integration"}) public void testReadingSimpleAggregateFunction2() throws Exception { final String tableName = "simple_aggregate_function_test_table"; + final String tableEngine = ClickHouseServerForTest.isCluster() ? "ReplicatedMergeTree" : "MergeTree"; client.execute("DROP TABLE IF EXISTS " + tableName).get(); client.execute("CREATE TABLE `" + tableName + "` " + "(idx UInt8, lowest_value SimpleAggregateFunction(min, UInt8), count SimpleAggregateFunction(sum, Int64), date SimpleAggregateFunction(anyLast, DateTime32)) " + - "ENGINE Memory;").get(); + "ENGINE " + tableEngine + " ORDER BY ()").get(); try (InsertResponse response = client.insert(tableName, new ByteArrayInputStream("1\t2\t3\t2024-12-22T12:00:00".getBytes(StandardCharsets.UTF_8)), ClickHouseFormat.TSV).get(30, TimeUnit.SECONDS)) { From 96eb6b4118b86bea8bb4caac11e55e98e2b37471 Mon Sep 17 00:00:00 2001 From: Sergey Chernov Date: Wed, 7 Oct 2026 10:17:58 -0700 Subject: [PATCH 5/7] removed using specific table engine to make tests rely on default engine - fixes issues with cluster env --- .../clickhouse/client/ClickHouseNodeTest.java | 2 +- .../clickhouse/client/ClientFailoverTest.java | 2 +- .../com/clickhouse/client/ClientTests.java | 2 +- .../clickhouse/client/HttpTransportTests.java | 4 +- .../client/ParameterizedQueryTest.java | 4 +- .../AbstractJSONEachRowFormatReaderTests.java | 2 +- .../GsonJSONEachRowFormatReaderTests.java | 2 +- .../api/data_formats/RowBinaryTest.java | 13 ++- .../internal/BaseReaderTests.java | 6 +- .../BinaryReaderBackedRecordTest.java | 4 +- .../api/transport/TransportBaseTests.java | 2 +- .../client/datatypes/DataTypeTests.java | 14 +-- .../datatypes/DataTypesTestingPOJO.java | 2 +- .../datatypes/RowBinaryFormatWriterTest.java | 60 ++++++------ .../InsertClientHttpCompressionTests.java | 2 +- .../clickhouse/client/insert/InsertTests.java | 24 ++--- .../client/insert/NoSettersPOJO.java | 2 +- .../client/insert/PojoWithJSON.java | 2 +- .../clickhouse/client/insert/SamplePOJO.java | 2 +- .../clickhouse/client/insert/SimplePOJO.java | 2 +- .../client/metadata/MetadataTests.java | 2 +- .../observability/MetricsRecorderTest.java | 2 +- .../observability/SpanRecorderTest.java | 2 +- .../MicrometerMetricsRecorderTest.java | 2 +- .../otel/OpenTelemetrySpanRecorderTest.java | 2 +- .../client/query/AggregateFuncDTO.java | 2 +- .../client/query/NoGettersPOJO.java | 2 +- .../client/query/QuerySamplePOJO.java | 2 +- .../clickhouse/client/query/QueryTests.java | 35 +++---- .../com/clickhouse/jdbc/BaseSQLTests.java | 2 +- .../com/clickhouse/jdbc/ConnectionTest.java | 4 +- .../jdbc/DetachedResultSetTest.java | 4 +- .../clickhouse/jdbc/JDBCDateTimeTests.java | 10 +- .../clickhouse/jdbc/JdbcDataTypeTests.java | 98 +++++++++---------- .../jdbc/PreparedStatementTest.java | 44 ++++----- .../clickhouse/jdbc/ResultSetImplTest.java | 2 +- .../com/clickhouse/jdbc/StatementTest.java | 46 ++++----- .../jdbc/WriterStatementImplTest.java | 16 +-- .../jdbc/metadata/DatabaseMetaDataTest.java | 16 +-- .../metadata/ResultSetMetaDataImplTest.java | 4 +- .../ShowStatementDatabaseMetaDataTest.java | 12 +-- 41 files changed, 228 insertions(+), 234 deletions(-) diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodeTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodeTest.java index bb81e939d..94318ae8f 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodeTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodeTest.java @@ -396,7 +396,7 @@ public void testQueryWithSlash() throws URISyntaxException { public void testProbe() { // FIXME does not support ClickHouseProtocol.POSTGRESQL for now ClickHouseProtocol[] protocols = null; - if ( isCloud() ) { + if ( isCloud() || ClickHouseServerForTest.isCluster()) { protocols = new ClickHouseProtocol[]{ ClickHouseProtocol.HTTP }; diff --git a/client-v2/src/test/java/com/clickhouse/client/ClientFailoverTest.java b/client-v2/src/test/java/com/clickhouse/client/ClientFailoverTest.java index 6a724151d..0392c9fae 100644 --- a/client-v2/src/test/java/com/clickhouse/client/ClientFailoverTest.java +++ b/client-v2/src/test/java/com/clickhouse/client/ClientFailoverTest.java @@ -96,7 +96,7 @@ public void testInsertFailoverToBackupNode() throws Exception { .setDefaultDatabase(ClickHouseServerForTest.getDatabase()) .build()) { adminClient.execute("DROP TABLE IF EXISTS failover_insert_test").get(10, TimeUnit.SECONDS).close(); - adminClient.execute("CREATE TABLE failover_insert_test (val UInt32) ENGINE MergeTree ORDER BY ()").get(10, TimeUnit.SECONDS).close(); + adminClient.execute("CREATE TABLE failover_insert_test (val UInt32) ORDER BY ()").get(10, TimeUnit.SECONDS).close(); } try (Client client = new Client.Builder() diff --git a/client-v2/src/test/java/com/clickhouse/client/ClientTests.java b/client-v2/src/test/java/com/clickhouse/client/ClientTests.java index 30e96cf4c..12214c7f5 100644 --- a/client-v2/src/test/java/com/clickhouse/client/ClientTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/ClientTests.java @@ -552,7 +552,7 @@ public void testLogComment() throws Exception { public void testServerSettings() throws Exception { try (Client client = newClient().build()) { client.execute("DROP TABLE IF EXISTS server_settings_test_table"); - client.execute("CREATE TABLE server_settings_test_table (v Float) Engine MergeTree ORDER BY ()"); + client.execute("CREATE TABLE server_settings_test_table (v Float) ORDER BY ()"); final String queryId = UUID.randomUUID().toString(); InsertSettings insertSettings = new InsertSettings() diff --git a/client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java b/client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java index d05e0ac68..1d28ed5c9 100644 --- a/client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java @@ -618,7 +618,7 @@ public void testServerErrorHandling(ClickHouseFormat format, boolean serverCompr } - try (QueryResponse response = client.query("CREATE TABLE table_from_csv ENGINE MergeTree ORDER BY () AS SELECT * FROM file('empty.csv') ", querySettings) + try (QueryResponse response = client.query("CREATE TABLE table_from_csv ORDER BY () AS SELECT * FROM file('empty.csv') ", querySettings) .get(1, TimeUnit.SECONDS)) { Assert.fail("Expected exception"); } catch (ServerException e) { @@ -1144,7 +1144,7 @@ public void testErrorWithSendProgressHeaders() throws Exception { try (CommandResponse resp = client.execute("DROP TABLE IF EXISTS test_omm_table").get()) { } - try (CommandResponse resp = client.execute("CREATE TABLE test_omm_table ( val String) Engine = MergeTree ORDER BY () ").get()) { + try (CommandResponse resp = client.execute("CREATE TABLE test_omm_table ( val String) ORDER BY () ").get()) { } QuerySettings settings = new QuerySettings() diff --git a/client-v2/src/test/java/com/clickhouse/client/ParameterizedQueryTest.java b/client-v2/src/test/java/com/clickhouse/client/ParameterizedQueryTest.java index 8b1d32035..f56c43ab6 100644 --- a/client-v2/src/test/java/com/clickhouse/client/ParameterizedQueryTest.java +++ b/client-v2/src/test/java/com/clickhouse/client/ParameterizedQueryTest.java @@ -233,7 +233,7 @@ void testStringParams(String paramValue) throws Exception { String column = "val"; client.execute("DROP TABLE IF EXISTS " + table).get(); client.execute("CREATE TABLE " + table + "(" + column + " String) " - + "ENGINE = MergeTree ORDER BY tuple()").get(); + + "ORDER BY tuple()").get(); client.query( "INSERT INTO " + table + "(" + column + ") VALUES ('" + paramValue + "')").get(); try (QueryResponse r = client.query( @@ -301,7 +301,7 @@ private void prepareDataSet(String table, List columns, List { // Endless input stream so the insert stays active on the server until the request is cancelled. try (InsertResponse response = client.insert(table, endlessTsvStream(), ClickHouseFormat.TSV, diff --git a/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java b/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java index 5ecbf7a3d..06a6da63c 100644 --- a/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java @@ -609,7 +609,7 @@ public void testBFloat16ReadFromServerWrittenValues() throws Exception { final int batchSize = 4096; // keep each INSERT well under max_query_size client.execute("DROP TABLE IF EXISTS " + table).get(); client.execute("CREATE TABLE " + table - + " (rowId Int32, v BFloat16, vNull Nullable(BFloat16)) ENGINE = MergeTree ORDER BY rowId").get(); + + " (rowId Int32, v BFloat16, vNull Nullable(BFloat16)) ORDER BY rowId").get(); for (int start = 0; start < count; start += batchSize) { int end = Math.min(start + batchSize, count); @@ -840,7 +840,7 @@ public void testVariantWithSimpleDataTypes() throws Exception { continue dataTypesLoop; } - b.append(")) Engine = MergeTree ORDER BY ()"); + b.append(")) ORDER BY ()"); client.execute(b.toString(), (CommandSettings) new CommandSettings().serverSetting("allow_experimental_variant_type", "1")); @@ -1237,7 +1237,7 @@ public void testDynamicWithPrimitives() throws Exception { client.execute("DROP TABLE IF EXISTS " + table).get(); String createTableStatement = " CREATE TABLE " + table + "( rowId Int64, field Dynamic ) " + - "Engine = MergeTree ORDER BY ()"; + "ORDER BY ()"; client.execute(createTableStatement, (CommandSettings) new CommandSettings().serverSetting("allow_experimental_dynamic_type", "1")); client.register(DTOForDynamicPrimitivesTests.class, client.getTableSchema(table)); @@ -2657,7 +2657,7 @@ public void testGetObjectArrayMethods() throws Exception { "int_arr Array(Int32), " + "arr2d Array(Array(Int64)), " + "arr3d Array(Array(Array(Int32)))" + - ") Engine = MergeTree ORDER BY rowId").get(); + ") ORDER BY rowId").get(); client.execute("INSERT INTO " + table + " VALUES " + "(1, " + @@ -2839,7 +2839,7 @@ public void testGetStringArrayAndGetObjectArrayWhenValueIsList() throws Exceptio "rowId Int32, " + "str_arr Array(String), " + "arr2d Array(Array(Int32))" + - ") Engine = MergeTree ORDER BY rowId").get(); + ") ORDER BY rowId").get(); client.execute("INSERT INTO " + table + " VALUES " + "(1, ['hello', 'world'], [[1, 2], [3]])").get(); @@ -2935,7 +2935,7 @@ public void testJSONSubPathAccess(String query, Object[] expectedValues) throws CommandSettings jsonSettings = (CommandSettings) new CommandSettings() .serverSetting("enable_json_type", "1") .serverSetting("allow_experimental_json_type", "1"); - client.execute("CREATE TABLE " + table + " (`i` Int64, `j` JSON) ENGINE = MergeTree ORDER BY i", + client.execute("CREATE TABLE " + table + " (`i` Int64, `j` JSON) ORDER BY i", jsonSettings).get().close(); client.execute("INSERT INTO " + table + " VALUES " + "(1, '{\"m\":{\"a\":[{\"d\": 9000}]}}'), " + @@ -3200,7 +3200,7 @@ public static String tableDefinition(String table, String... columns) { sb.append(s).append(", "); }); sb.setLength(sb.length() - 2); - sb.append(") Engine = MergeTree ORDER BY ()"); + sb.append(") ORDER BY ()"); return sb.toString(); } diff --git a/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypesTestingPOJO.java b/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypesTestingPOJO.java index bc8a431d0..cfb9915c9 100644 --- a/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypesTestingPOJO.java +++ b/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypesTestingPOJO.java @@ -332,7 +332,7 @@ public static String generateTableCreateSQL(String tableName) { "intervalMillisecond IntervalNanosecond, " + "intervalMicrosecond IntervalNanosecond, " + "intervalNanosecond IntervalNanosecond " + - ") ENGINE = MergeTree ORDER BY ()"; + ") ORDER BY ()"; } public enum SmallEnum { diff --git a/client-v2/src/test/java/com/clickhouse/client/datatypes/RowBinaryFormatWriterTest.java b/client-v2/src/test/java/com/clickhouse/client/datatypes/RowBinaryFormatWriterTest.java index 78ed3f698..a59c1e40c 100644 --- a/client-v2/src/test/java/com/clickhouse/client/datatypes/RowBinaryFormatWriterTest.java +++ b/client-v2/src/test/java/com/clickhouse/client/datatypes/RowBinaryFormatWriterTest.java @@ -253,7 +253,7 @@ public void writeMissingFieldsTest() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " int8 Int8, int8_nullable Nullable(Int8), int8_default Int8 DEFAULT 3 " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -277,7 +277,7 @@ public void writeEnumZeroLikeValuesTest() throws Exception { " e8 Enum8('' = 0, 'a' = 1, 'neg' = -5), " + " e16 Enum16('zero' = 0, 'big' = 30000, 'nb' = -20000), " + " tail Float64" + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; Field[][] rows = new Field[][] { // Zero-like written by enum name: an empty-string name and a named zero both map to 0. @@ -314,7 +314,7 @@ private Object[][] nullEnumContainers() { public void writeNullEnumInContainerThrowsTest(String columnType, Object valueWithNullEnum) throws Exception { String tableName = "rowBinaryFormatWriterTest_enumContainerNull_" + UUID.randomUUID().toString().replace('-', '_'); initTable(tableName, - "CREATE TABLE \"" + tableName + "\" (id Int32, c " + columnType + ") Engine = MergeTree ORDER BY id", + "CREATE TABLE \"" + tableName + "\" (id Int32, c " + columnType + ") ORDER BY id", new CommandSettings()); TableSchema schema = client.getTableSchema(tableName); ClickHouseFormat format = ClickHouseFormat.RowBinaryWithDefaults; @@ -360,7 +360,7 @@ private Object[][] rowBinaryWriterFormats() { public void writeNullIntoNonNullableArrayThrowsTest(ClickHouseFormat format) throws Exception { String tableName = "rowBinaryFormatWriterTest_nonNullableArrayNull_" + UUID.randomUUID().toString().replace('-', '_'); initTable(tableName, - "CREATE TABLE \"" + tableName + "\" (id Int32, arr Array(Int32), tail Int32) Engine = MergeTree ORDER BY id", + "CREATE TABLE \"" + tableName + "\" (id Int32, arr Array(Int32), tail Int32) ORDER BY id", new CommandSettings()); TableSchema schema = client.getTableSchema(tableName); @@ -391,7 +391,7 @@ public void writeNullIntoNonNullableArrayThrowsTest(ClickHouseFormat format) thr public void writeNonNullableArrayRoundTripsTest(ClickHouseFormat format) throws Exception { String tableName = "rowBinaryFormatWriterTest_nonNullableArrayRoundTrip_" + UUID.randomUUID().toString().replace('-', '_'); initTable(tableName, - "CREATE TABLE \"" + tableName + "\" (id Int32, arr Array(Int32), tail Int32) Engine = MergeTree ORDER BY id", + "CREATE TABLE \"" + tableName + "\" (id Int32, arr Array(Int32), tail Int32) ORDER BY id", new CommandSettings()); TableSchema schema = client.getTableSchema(tableName); @@ -429,7 +429,7 @@ public void writeNonNullableArrayRoundTripsTest(ClickHouseFormat format) throws public void writeNullIntoDefaultedArrayUsesDefaultTest() throws Exception { String tableName = "rowBinaryFormatWriterTest_defaultedArrayNull_" + UUID.randomUUID().toString().replace('-', '_'); initTable(tableName, - "CREATE TABLE \"" + tableName + "\" (id Int32, arr Array(Int32) DEFAULT [1, 2], tail Int32) Engine = MergeTree ORDER BY id", + "CREATE TABLE \"" + tableName + "\" (id Int32, arr Array(Int32) DEFAULT [1, 2], tail Int32) ORDER BY id", new CommandSettings()); TableSchema schema = client.getTableSchema(tableName); ClickHouseFormat format = ClickHouseFormat.RowBinaryWithDefaults; @@ -474,7 +474,7 @@ public void writeNumbersTest() throws Exception { " float32 Float32, float32_nullable Nullable(Float32), float32_default Float32 DEFAULT 3, " + " float64 Float64, float64_nullable Nullable(Float64), float64_default Float64 DEFAULT 3, " + // " bfloat16 BFloat16, bfloat16_nullable Nullable(BFloat16), bfloat16_default BFloat16 DEFAULT 3, " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -514,7 +514,7 @@ public void writeDecimalsTest() throws Exception { " decimal64 Decimal(18, 6), decimal64_nullable Nullable(Decimal(18, 6)), decimal64_default Decimal(18, 6) DEFAULT 3, " + " decimal128 Decimal(36, 8), decimal128_nullable Nullable(Decimal(36, 8)), decimal128_default Decimal(36, 8) DEFAULT 3, " + " decimal256 Decimal(74, 10), decimal256_nullable Nullable(Decimal(74, 10)), decimal256_default Decimal(74, 10) DEFAULT 3" + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -551,7 +551,7 @@ public void writeStringsTest() throws Exception { " enum Enum('a' = 1, 'b' = 2), enum_nullable Nullable(Enum('a' = 1, 'b' = 2)), enum_default Enum('a' = 1, 'b' = 2) DEFAULT 'a', " + " enum8 Enum8('a' = 1, 'b' = 2), enum8_nullable Nullable(Enum8('a' = 1, 'b' = 2)), enum8_default Enum8('a' = 1, 'b' = 2) DEFAULT 'a', " + " enum16 Enum16('a' = 1, 'b' = 2), enum16_nullable Nullable(Enum16('a' = 1, 'b' = 2)), enum16_default Enum16('a' = 1, 'b' = 2) DEFAULT 'a', " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values Field[][] rows = new Field[][] {{ @@ -594,7 +594,7 @@ private Object[][] stringValuesForUInt64AndUUID() { public void writeStringIntoUInt64AndUUIDTest(String columnType, Object value, String expected) throws Exception { String tableName = "rowBinaryFormatWriterTest_stringUInt64UUID_" + UUID.randomUUID().toString().replace('-', '_'); initTable(tableName, - "CREATE TABLE \"" + tableName + "\" (id Int32, c " + columnType + ", tail Float64) Engine = MergeTree ORDER BY id", + "CREATE TABLE \"" + tableName + "\" (id Int32, c " + columnType + ", tail Float64) ORDER BY id", new CommandSettings()); TableSchema schema = client.getTableSchema(tableName); ClickHouseFormat format = ClickHouseFormat.RowBinaryWithDefaults; @@ -625,7 +625,7 @@ public void writeBinaryStringsTest() throws Exception { " string String, " + " fixed_string FixedString(5), " + " fixed_string_one FixedString(1) " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Row 1 is written via setValue(byte[]), row 2 via setString(byte[]); use distinct // payloads per row so the rows are not identical (identical rows would be collapsed @@ -691,7 +691,7 @@ public void writeAndReadImageTest() throws Exception { String tableName = "rowBinaryFormatWriterTest_writeAndReadImageTest_" + UUID.randomUUID().toString().replace('-', '_'); String tableCreate = "CREATE TABLE \"" + tableName + "\" " + - " (id Int32, image String) Engine = MergeTree ORDER BY id"; + " (id Int32, image String) ORDER BY id"; initTable(tableName, tableCreate, new CommandSettings()); TableSchema schema = client.getTableSchema(tableName); @@ -761,7 +761,7 @@ public void writeDatetimeTests() throws Exception { " datetime64 DateTime64, datetime64_nullable Nullable(DateTime64), datetime64_default DateTime64 DEFAULT '2025-01-01 00:00:00', " + " date Date, date_nullable Nullable(Date), date_default Date DEFAULT '2020-01-01', " + " date32 Date32, date32_nullable Nullable(Date32), date32_default Date32 DEFAULT '2025-01-01', " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values Field[][] rows = new Field[][] {{ @@ -783,7 +783,7 @@ public void writeTupleTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " tuple Tuple(Int8, Int16), tuple_default Tuple(Int8, Int16) DEFAULT (3, 4), " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values Field[][] rows = new Field[][] {{ @@ -802,7 +802,7 @@ public void writeIpAddressTests() throws Exception { " (id Int32, " + " ipv4 IPv4, ipv4_nullable Nullable(IPv4), ipv4_default IPv4 DEFAULT '127.0.0.1', " + " ipv6 IPv6, ipv6_nullable Nullable(IPv6), ipv6_default IPv6 DEFAULT '::1', " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values Field[][] rows = new Field[][] {{ @@ -820,7 +820,7 @@ public void writeArrayTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " array Array(Int8), array_default Array(Int8) DEFAULT [3], " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values Field[][] rows = new Field[][] {{ @@ -848,7 +848,7 @@ public void writeGeometryTests() throws Exception { " multilinestring MultiLineString, multilinestring_default MultiLineString DEFAULT [[(0, 0), (10, 0), (10, 10), (0, 10)]], " + " polygon Polygon, polygon_default Polygon DEFAULT [[(0, 0), (10, 0), (10, 10), (0, 10)]], " + " multipolygon MultiPolygon, multipolygon_default MultiPolygon DEFAULT [[[(0, 0), (10, 0), (10, 10), (0, 10)]]], " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values Field[][] rows = new Field[][] {{ @@ -873,7 +873,7 @@ public void writeMapTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " map Map(String, Int16) " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; Map tmpMap = new HashMap<>(); tmpMap.put("a", 1); @@ -895,7 +895,7 @@ public void writeNestedTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " nested Nested(n1 Int8, n2 Int16) " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values Field[][] rows = new Field[][] {{ @@ -917,7 +917,7 @@ public void writeNestedTypeTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " n Nested(a UInt32, b Nullable(String)) " + - " ) Engine = MergeTree ORDER BY id SETTINGS flatten_nested = 0"; + " ) ORDER BY id SETTINGS flatten_nested = 0"; List nested = Arrays.asList(Arrays.asList(10L, "x"), Arrays.asList(20L, null)); Field[][] rows = new Field[][] {{ @@ -939,7 +939,7 @@ public void writeNestedWithArrayAndComplexFieldsTests() throws Exception { " (id Int32, " + " n Nested(a UInt32, tags Array(String), matrix Array(Array(Int32)), " + " pair Tuple(Int8, String), score Nullable(Float64), tail Float64) " + - " ) Engine = MergeTree ORDER BY id SETTINGS flatten_nested = 0"; + " ) ORDER BY id SETTINGS flatten_nested = 0"; List nestedMulti = Arrays.asList( Arrays.asList(10L, Arrays.asList("x", "y"), Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3)), @@ -968,7 +968,7 @@ public void writeNestedWithVariedScalarTypesTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " n Nested(u UInt64, when Date, guid UUID, lc LowCardinality(String), flag Bool, tail Float64) " + - " ) Engine = MergeTree ORDER BY id SETTINGS flatten_nested = 0"; + " ) ORDER BY id SETTINGS flatten_nested = 0"; UUID g1 = UUID.fromString("00112233-4455-6677-8899-aabbccddeeff"); UUID g2 = UUID.fromString("ffeeddcc-bbaa-9988-7766-554433221100"); @@ -990,7 +990,7 @@ public void writeNullableTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " nullable Nullable(Int8), nullable_default Nullable(Int8) DEFAULT 3, " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values Field[][] rows = new Field[][] {{ @@ -1008,7 +1008,7 @@ public void writeLowCardinalityTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " lowcardinality LowCardinality(String), lowcardinality_default LowCardinality(String) DEFAULT '3', " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; String randomString = RandomStringUtils.randomAlphabetic(1024); @@ -1028,7 +1028,7 @@ public void writeBooleanTypeTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " boolean Bool, boolean_default Bool DEFAULT 1, " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values Field[][] rows = new Field[][] {{ @@ -1048,7 +1048,7 @@ public void writeAggregateFunctionTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " aggregate_function AggregateFunction(count, Int8), " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values Field[][] rows = new Field[][] {{ @@ -1069,7 +1069,7 @@ public void writeSimpleAggregateFunctionTests() throws Exception { " saf_sum SimpleAggregateFunction(sum, UInt64), " + " saf_str SimpleAggregateFunction(anyLast, Nullable(String)), " + " tail Int32 " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // The SimpleAggregateFunction columns sit between id and a trailing Int32 so a byte // dropped/added while writing them misaligns "tail" and is detected. @@ -1097,7 +1097,7 @@ public void writeDynamicTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " dynamic Dynamic " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values Field[][] rows = new Field[][] {{ @@ -1123,7 +1123,7 @@ public void writeJsonTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " json JSON, json_default JSON DEFAULT '{\"a\": 1}' " + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; Map tmpMap = new HashMap<>(); tmpMap.put("a", 1); @@ -1150,7 +1150,7 @@ public void writeVariantTests() throws Exception { String tableCreate = "CREATE TABLE \"" + tableName + "\" " + " (id Int32, " + " variant Variant(String, Int8)," + - " ) Engine = MergeTree ORDER BY id"; + " ) ORDER BY id"; // Insert random (valid) values Field[][] rows = new Field[][] {{ diff --git a/client-v2/src/test/java/com/clickhouse/client/insert/InsertClientHttpCompressionTests.java b/client-v2/src/test/java/com/clickhouse/client/insert/InsertClientHttpCompressionTests.java index f272b5ee4..d028fb7c0 100644 --- a/client-v2/src/test/java/com/clickhouse/client/insert/InsertClientHttpCompressionTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/insert/InsertClientHttpCompressionTests.java @@ -29,7 +29,7 @@ public InsertClientHttpCompressionTests() { public void insertRawDataCompressed(String compressionAlgo) throws Exception { final String tableName = "raw_data_table"; final String createSQL = "CREATE TABLE " + tableName + - " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ENGINE = MergeTree() ORDER BY ()"; + " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ORDER BY ()"; initTable(tableName, createSQL); diff --git a/client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java b/client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java index b08ef5587..ce6ef0b43 100644 --- a/client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java @@ -279,7 +279,7 @@ public void testInsertingPOJOWithNullValueForNonNullableColumn() throws Exceptio public void insertRawData() throws Exception { final String tableName = "raw_data_table"; final String createSQL = "CREATE TABLE " + tableName + - " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ENGINE = MergeTree() ORDER BY ()"; + " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ORDER BY ()"; initTable(tableName, createSQL); @@ -311,7 +311,7 @@ public void insertRawData() throws Exception { public void insertRawDataAsync(boolean async) throws Exception { final String tableName = "raw_data_table_async"; final String createSQL = "CREATE TABLE " + tableName + - " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ENGINE = MergeTree() ORDER BY ()"; + " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ORDER BY ()"; initTable(tableName, createSQL); @@ -345,7 +345,7 @@ public static Object[][] insertRawDataAsyncProvider(){ public void insertRawDataSimple(String tableName) throws Exception { // final String tableName = "raw_data_table"; final String createSql = String.format("CREATE TABLE IF NOT EXISTS %s " + - " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ENGINE = MergeTree() ORDER BY ()", tableName); + " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ORDER BY ()", tableName); initTable(tableName, createSql); @@ -370,7 +370,7 @@ public void insertRawDataSimple(String tableName) throws Exception { public void insertRawDataFewerColumns() throws Exception { final String tableName = "raw_data_select_columns_table"; final String createSQL = "CREATE TABLE " + tableName + - " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String, p3 String, p4 Int8) ENGINE = MergeTree() ORDER BY ()"; + " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String, p3 String, p4 Int8) ORDER BY ()"; List columnNames = Arrays.asList("Id", "event_ts", "name", "p1", "p2"); initTable(tableName, createSQL); @@ -404,7 +404,7 @@ public static Object[][] insertRawDataSimpleDataProvider() { public void testInsertMetricsOperationId() throws Exception { final String tableName = "insert_metrics_test"; final String createSQL = "CREATE TABLE " + tableName + - " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ENGINE = MergeTree() ORDER BY ()"; + " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ORDER BY ()"; initTable(tableName, createSQL); @@ -433,7 +433,7 @@ public void testInsertSettingsAddDatabase() throws Exception { final String new_database = client.getDefaultDatabase() + "_new_database"; final String createDatabaseSQL = "CREATE DATABASE IF NOT EXISTS " + new_database; final String createTableSQL = "CREATE TABLE " + new_database + "." + tableName + - " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ENGINE = MergeTree() ORDER BY ()"; + " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ORDER BY ()"; final String dropDatabaseSQL = "DROP DATABASE IF EXISTS " + new_database; try { @@ -494,7 +494,7 @@ public void testLogComment(String logComment) throws Exception { @Test(groups = { "integration" }) public void testInsertSettingsDeduplicationToken() throws Exception { final String tableName = "insert_settings_database_test"; - final String createTableSQL = "CREATE TABLE " + tableName + " ( A Int64 ) ENGINE = MergeTree ORDER BY A SETTINGS " + + final String createTableSQL = "CREATE TABLE " + tableName + " ( A Int64 ) ORDER BY A SETTINGS " + "non_replicated_deduplication_window = 100"; final String deduplicationToken = RandomStringUtils.randomAlphabetic(36); @@ -540,7 +540,7 @@ public void testWriter() throws Exception { " attrs Nullable(String), " + " corrected_time DateTime('UTC') DEFAULT now()," + " special_attr Nullable(Int8) DEFAULT -1)" + - " Engine = MergeTree ORDER by ()"; + " ORDER by ()"; initTable(tableName, tableCreate); @@ -597,7 +597,7 @@ public void testAdvancedWriter() throws Exception { " attrs Nullable(String), " + " corrected_time DateTime('UTC') DEFAULT now()," + " special_attr Nullable(Int8) DEFAULT -1)" + - " Engine = MergeTree ORDER by ()"; + " ORDER by ()"; initTable(tableName, tableCreate); @@ -645,7 +645,7 @@ public void testWriterWithMaterialize() throws Exception { " name_lower_alias String ALIAS lower(name)," + " unhexed String EPHEMERAL," + " hexed FixedString(4) DEFAULT unhex(unhexed)" + - " ) Engine = MergeTree ORDER by (name)"; + " ) ORDER by (name)"; initTable(tableName, tableCreate); @@ -689,7 +689,7 @@ public void testCollectionInsert() throws Exception { " attrs Nullable(String), " + " corrected_time DateTime('UTC') DEFAULT now()," + " special_attr Nullable(Int8) DEFAULT -1)" + - " Engine = MergeTree ORDER by ()"; + " ORDER by ()"; initTable(tableName, tableCreate); @@ -726,7 +726,7 @@ public void testAppCompression(String algo) throws Exception { " attrs Nullable(String), " + " corrected_time DateTime('UTC') DEFAULT now()," + " special_attr Nullable(Int8) DEFAULT -1)" + - " Engine = MergeTree ORDER by ()"; + " ORDER by ()"; initTable(tableName, tableCreate); diff --git a/client-v2/src/test/java/com/clickhouse/client/insert/NoSettersPOJO.java b/client-v2/src/test/java/com/clickhouse/client/insert/NoSettersPOJO.java index a957bb073..251fcc266 100644 --- a/client-v2/src/test/java/com/clickhouse/client/insert/NoSettersPOJO.java +++ b/client-v2/src/test/java/com/clickhouse/client/insert/NoSettersPOJO.java @@ -16,6 +16,6 @@ public int sum() { } public static String generateTableCreateSQL(String tableName) { - return "CREATE TABLE " + tableName + " (p1 Int32, p2 Int32) ENGINE = MergeTree() ORDER BY ()"; + return "CREATE TABLE " + tableName + " (p1 Int32, p2 Int32) ORDER BY ()"; } } diff --git a/client-v2/src/test/java/com/clickhouse/client/insert/PojoWithJSON.java b/client-v2/src/test/java/com/clickhouse/client/insert/PojoWithJSON.java index aa2672021..f6dd1bedc 100644 --- a/client-v2/src/test/java/com/clickhouse/client/insert/PojoWithJSON.java +++ b/client-v2/src/test/java/com/clickhouse/client/insert/PojoWithJSON.java @@ -36,6 +36,6 @@ public String toString() { } public static String createTable(String tableName) { - return "CREATE TABLE " + tableName + " (eventPayload JSON) ENGINE = MergeTree() ORDER BY tuple()"; + return "CREATE TABLE " + tableName + " (eventPayload JSON) ORDER BY tuple()"; } } diff --git a/client-v2/src/test/java/com/clickhouse/client/insert/SamplePOJO.java b/client-v2/src/test/java/com/clickhouse/client/insert/SamplePOJO.java index 6661b94bc..fd3b53844 100644 --- a/client-v2/src/test/java/com/clickhouse/client/insert/SamplePOJO.java +++ b/client-v2/src/test/java/com/clickhouse/client/insert/SamplePOJO.java @@ -331,6 +331,6 @@ public static String generateTableCreateSQL(String tableName) { "groupBitmapUint32 AggregateFunction(groupBitmap, UInt32), " + "groupBitmapUint64 AggregateFunction(groupBitmap, UInt64), " + "keyword LowCardinality(String) " + - ") ENGINE = MergeTree ORDER BY ()"; + ") ORDER BY ()"; } } diff --git a/client-v2/src/test/java/com/clickhouse/client/insert/SimplePOJO.java b/client-v2/src/test/java/com/clickhouse/client/insert/SimplePOJO.java index 843ee94f5..7e6385eeb 100644 --- a/client-v2/src/test/java/com/clickhouse/client/insert/SimplePOJO.java +++ b/client-v2/src/test/java/com/clickhouse/client/insert/SimplePOJO.java @@ -34,7 +34,7 @@ public static String generateTableCreateSQL(String tableName) { "str_lower String ALIAS lower(str), " + "unhexed String EPHEMERAL, " + "hexed FixedString(4) DEFAULT unhex(unhexed), " + - ") ENGINE = MergeTree ORDER BY ()"; + ") ORDER BY ()"; } } diff --git a/client-v2/src/test/java/com/clickhouse/client/metadata/MetadataTests.java b/client-v2/src/test/java/com/clickhouse/client/metadata/MetadataTests.java index 6364c4344..52bd6a15b 100644 --- a/client-v2/src/test/java/com/clickhouse/client/metadata/MetadataTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/metadata/MetadataTests.java @@ -60,7 +60,7 @@ public void testGetTableSchemaDifferentDb() throws Exception { client.execute("DROP DATABASE IF EXISTS " + db).get().close(); client.execute("CREATE DATABASE " + db).get().close(); client.query("DROP TABLE IF EXISTS " + table, settings).get().close(); - client.query("CREATE TABLE " + table + " (rowId Int32) Engine=MergeTree ORDER BY ()", settings).get().close(); + client.query("CREATE TABLE " + table + " (rowId Int32) ORDER BY ()", settings).get().close(); TableSchema tableSchema = client.getTableSchema(table, db); Assert.assertEquals(tableSchema.getColumnByName("rowId").getDataType(), ClickHouseDataType.Int32); } finally { diff --git a/client-v2/src/test/java/com/clickhouse/client/observability/MetricsRecorderTest.java b/client-v2/src/test/java/com/clickhouse/client/observability/MetricsRecorderTest.java index 944a7d9e8..1ee003c83 100644 --- a/client-v2/src/test/java/com/clickhouse/client/observability/MetricsRecorderTest.java +++ b/client-v2/src/test/java/com/clickhouse/client/observability/MetricsRecorderTest.java @@ -42,7 +42,7 @@ void setUp() throws Exception { .setMetricsRecorder(recorder) .build(); client.execute("DROP TABLE IF EXISTS " + TABLE).get(); - client.execute("CREATE TABLE " + TABLE + " (value String) ENGINE = MergeTree ORDER BY value").get(); + client.execute("CREATE TABLE " + TABLE + " (value String) ORDER BY value").get(); recorder.clear(); } diff --git a/client-v2/src/test/java/com/clickhouse/client/observability/SpanRecorderTest.java b/client-v2/src/test/java/com/clickhouse/client/observability/SpanRecorderTest.java index be58ebad8..8b3321a0e 100644 --- a/client-v2/src/test/java/com/clickhouse/client/observability/SpanRecorderTest.java +++ b/client-v2/src/test/java/com/clickhouse/client/observability/SpanRecorderTest.java @@ -42,7 +42,7 @@ void setUp() throws Exception { .setSpanRecorder(recorder) .build(); client.execute("DROP TABLE IF EXISTS " + TABLE).get(); - client.execute("CREATE TABLE " + TABLE + " (id Int32, name String) ENGINE = MergeTree ORDER BY id").get(); + client.execute("CREATE TABLE " + TABLE + " (id Int32, name String) ORDER BY id").get(); client.execute("INSERT INTO " + TABLE + " VALUES (1, 'a'), (2, 'b'), (3, 'c')").get(); recorder.clear(); } diff --git a/client-v2/src/test/java/com/clickhouse/client/observability/micrometer/MicrometerMetricsRecorderTest.java b/client-v2/src/test/java/com/clickhouse/client/observability/micrometer/MicrometerMetricsRecorderTest.java index 630db6015..37cbae991 100644 --- a/client-v2/src/test/java/com/clickhouse/client/observability/micrometer/MicrometerMetricsRecorderTest.java +++ b/client-v2/src/test/java/com/clickhouse/client/observability/micrometer/MicrometerMetricsRecorderTest.java @@ -44,7 +44,7 @@ void setUp() throws Exception { .setMetricsRecorder(new MicrometerMetricsRecorder(registry)) .build(); client.execute("DROP TABLE IF EXISTS " + TABLE).get(); - client.execute("CREATE TABLE " + TABLE + " (value String) ENGINE = MergeTree ORDER BY value").get(); + client.execute("CREATE TABLE " + TABLE + " (value String) ORDER BY value").get(); registry.clear(); } diff --git a/client-v2/src/test/java/com/clickhouse/client/observability/otel/OpenTelemetrySpanRecorderTest.java b/client-v2/src/test/java/com/clickhouse/client/observability/otel/OpenTelemetrySpanRecorderTest.java index 804589075..f317652d2 100644 --- a/client-v2/src/test/java/com/clickhouse/client/observability/otel/OpenTelemetrySpanRecorderTest.java +++ b/client-v2/src/test/java/com/clickhouse/client/observability/otel/OpenTelemetrySpanRecorderTest.java @@ -59,7 +59,7 @@ void setUp() throws Exception { .setSpanRecorder(new OpenTelemetrySpanRecorder(openTelemetry)) .build(); client.execute("DROP TABLE IF EXISTS " + TABLE).get(); - client.execute("CREATE TABLE " + TABLE + " (id Int32, name String) ENGINE = MergeTree ORDER BY id").get(); + client.execute("CREATE TABLE " + TABLE + " (id Int32, name String) ORDER BY id").get(); client.execute("INSERT INTO " + TABLE + " VALUES (1, 'a'), (2, 'b'), (3, 'c')").get(); exporter.reset(); } diff --git a/client-v2/src/test/java/com/clickhouse/client/query/AggregateFuncDTO.java b/client-v2/src/test/java/com/clickhouse/client/query/AggregateFuncDTO.java index 84ba5e4d1..ddd5e0096 100644 --- a/client-v2/src/test/java/com/clickhouse/client/query/AggregateFuncDTO.java +++ b/client-v2/src/test/java/com/clickhouse/client/query/AggregateFuncDTO.java @@ -49,6 +49,6 @@ public static String generateTableCreateSQL(String tableName) { return "CREATE TABLE " + tableName + " (" + "groupBitmapUint32 AggregateFunction(groupBitmap, UInt32), " + "groupBitmapUint64 AggregateFunction(groupBitmap, UInt64) " + - ") ENGINE = MergeTree() ORDER BY tuple()"; + ") ORDER BY tuple()"; } } diff --git a/client-v2/src/test/java/com/clickhouse/client/query/NoGettersPOJO.java b/client-v2/src/test/java/com/clickhouse/client/query/NoGettersPOJO.java index 4c9b56dfd..d4d346ffc 100644 --- a/client-v2/src/test/java/com/clickhouse/client/query/NoGettersPOJO.java +++ b/client-v2/src/test/java/com/clickhouse/client/query/NoGettersPOJO.java @@ -16,6 +16,6 @@ public int sum() { } public static String generateTableCreateSQL(String tableName) { - return "CREATE TABLE " + tableName + " (p1 Int32, p2 Int32) ENGINE = MergeTree() ORDER BY ()"; + return "CREATE TABLE " + tableName + " (p1 Int32, p2 Int32) ORDER BY ()"; } } diff --git a/client-v2/src/test/java/com/clickhouse/client/query/QuerySamplePOJO.java b/client-v2/src/test/java/com/clickhouse/client/query/QuerySamplePOJO.java index 8129137b9..69708542b 100644 --- a/client-v2/src/test/java/com/clickhouse/client/query/QuerySamplePOJO.java +++ b/client-v2/src/test/java/com/clickhouse/client/query/QuerySamplePOJO.java @@ -575,6 +575,6 @@ public static String generateTableCreateSQL(String tableName) { "tupleArray Tuple(Int32, Float64, String, String), " + "map Map(String, Int32), " + "nested Nested (innerInt Int32, innerString String)" + - ") ENGINE = MergeTree ORDER BY ()"; + ") ORDER BY ()"; } } 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 93da8da20..aa7809ca1 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 @@ -242,7 +242,7 @@ public void testReadRecordsWithStreamAPI() throws Exception { final String tableName = "a_" + i; expectedTableNames.add(tableName); client.execute("DROP TABLE IF EXISTS " + tableName); - client.execute("CREATE TABLE " + tableName +" (x UInt32) ENGINE = MergeTree ORDER BY ()"); + client.execute("CREATE TABLE " + tableName +" (x UInt32) ORDER BY ()"); } Records records = client.queryRecords("SHOW TABLES").get(3, TimeUnit.SECONDS); @@ -342,7 +342,7 @@ public void testQueryAllTableNames() { final String tableName = "a_" + i; expectedTableNames.add(tableName); client.execute("DROP TABLE IF EXISTS " + tableName); - client.execute("CREATE TABLE " + tableName +" (x UInt32) ENGINE = MergeTree ORDER BY ()"); + client.execute("CREATE TABLE " + tableName +" (x UInt32) ORDER BY ()"); } List records = client.queryAll("SHOW TABLES"); @@ -354,7 +354,7 @@ public void testQueryAllTableNames() { @Test(groups = {"integration"}) public void testQueryAllInsertSelect() { - client.queryAll("CREATE TABLE IF NOT EXISTS nums (number Int16) ENGINE = MergeTree() ORDER BY number;"); + client.queryAll("CREATE TABLE IF NOT EXISTS nums (number Int16) ORDER BY number;"); String sql = "INSERT INTO nums SELECT * FROM system.numbers LIMIT 100"; List records = client.queryAll(sql); Assert.assertTrue(records.isEmpty()); @@ -1491,7 +1491,7 @@ void testDataTypes(List columns, List> valueGenerators, createStmtBuilder.append(column).append(", "); } createStmtBuilder.setLength(createStmtBuilder.length() - 2); - createStmtBuilder.append(") ENGINE = ").append(ClickHouseServerForTest.isCluster() ? "ReplicatedMergeTree" : "MergeTree").append(" ORDER BY tuple()"); + createStmtBuilder.append(") ORDER BY tuple()"); client.execute(createStmtBuilder.toString(), commandSettings).get(10, TimeUnit.SECONDS); @@ -1686,8 +1686,7 @@ protected List> prepareDataSet(String table, List co createStmtBuilder.append(column).append(", "); } createStmtBuilder.setLength(createStmtBuilder.length() - 2); - final String engine = ClickHouseServerForTest.isCluster() ? "ReplicatedMergeTree" : "MergeTree"; - createStmtBuilder.append(") ENGINE = ").append(engine).append(" ORDER BY tuple()"); + createStmtBuilder.append(") ORDER BY tuple()"); client.execute(createStmtBuilder.toString(), settings).get(10, TimeUnit.SECONDS); // Insert data @@ -1779,7 +1778,7 @@ public void testQueryParams() throws Exception { final String table = "query_params_test_table"; client.execute("DROP TABLE IF EXISTS " + table).get(); - client.execute("CREATE TABLE " + table + " (col1 UInt32, col2 String) ENGINE = MergeTree ORDER BY tuple()").get(); + client.execute("CREATE TABLE " + table + " (col1 UInt32, col2 String) ORDER BY tuple()").get(); ByteArrayOutputStream insertData = new ByteArrayOutputStream(); try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(insertData))) { @@ -1905,9 +1904,8 @@ public void testExecuteQueryParam() throws ExecutionException, InterruptedExcept final String table = "execute_query_test"; Map query_param = new HashMap<>(); query_param.put("table_name",table); - query_param.put("engine","MergeTree"); client.execute("DROP TABLE IF EXISTS " + table).get(10, TimeUnit.SECONDS); - client.execute("CREATE TABLE {table_name:Identifier} ( id UInt32, name String, created_at DateTime) ENGINE = MergeTree ORDER BY tuple()", query_param) + client.execute("CREATE TABLE {table_name:Identifier} ( id UInt32, name String, created_at DateTime) ORDER BY tuple()", query_param) .get(10, TimeUnit.SECONDS); TableSchema schema = client.getTableSchema(table); @@ -1921,9 +1919,8 @@ public void testExecuteQueryParamCommandSettings() throws ExecutionException, In String q1Id = UUID.randomUUID().toString(); Map query_param = new HashMap<>(); query_param.put("table_name",table); - query_param.put("engine","MergeTree"); client.execute("DROP TABLE IF EXISTS " + table).get(10, TimeUnit.SECONDS); - client.execute("CREATE TABLE {table_name:Identifier} ( id UInt32, name String, created_at DateTime) ENGINE = MergeTree ORDER BY tuple()", + client.execute("CREATE TABLE {table_name:Identifier} ( id UInt32, name String, created_at DateTime) ORDER BY tuple()", query_param, (CommandSettings) new CommandSettings().setQueryId(q1Id)) .get(10, TimeUnit.SECONDS); @@ -1937,7 +1934,7 @@ public void testGetTableSchema() throws Exception { final String table = "table_schema_test"; client.execute("DROP TABLE IF EXISTS " + table).get(10, TimeUnit.SECONDS); client.execute("CREATE TABLE " + table + - " (col1 UInt32, col2 String) ENGINE = MergeTree ORDER BY tuple()").get(10, TimeUnit.SECONDS); + " (col1 UInt32, col2 String) ORDER BY tuple()").get(10, TimeUnit.SECONDS); TableSchema schema = client.getTableSchema(table); Assert.assertNotNull(schema); @@ -2258,10 +2255,9 @@ protected Client.Builder newClient() { public void testReadingSimpleAggregateFunction() throws Exception { final String tableName = "simple_aggregate_function_test_table"; client.execute("DROP TABLE IF EXISTS " + tableName).get(); - final String tableEngine = ClickHouseServerForTest.isCluster() ? "ReplicatedMergeTree" : "MergeTree"; client.execute("CREATE TABLE `" + tableName + "` " + "(idx UInt8, lowest_value SimpleAggregateFunction(min, UInt8), count SimpleAggregateFunction(sum, Int64), mp SimpleAggregateFunction(maxMap, Map(UInt8, UInt8))) " + - "ENGINE " + tableEngine + " ORDER BY ();").get(); + "ORDER BY ();").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)) { @@ -2283,11 +2279,10 @@ public void testReadingSimpleAggregateFunction() throws Exception { @Test(groups = {"integration"}) public void testReadingSimpleAggregateFunction2() throws Exception { final String tableName = "simple_aggregate_function_test_table"; - final String tableEngine = ClickHouseServerForTest.isCluster() ? "ReplicatedMergeTree" : "MergeTree"; client.execute("DROP TABLE IF EXISTS " + tableName).get(); client.execute("CREATE TABLE `" + tableName + "` " + "(idx UInt8, lowest_value SimpleAggregateFunction(min, UInt8), count SimpleAggregateFunction(sum, Int64), date SimpleAggregateFunction(anyLast, DateTime32)) " + - "ENGINE " + tableEngine + " ORDER BY ()").get(); + "ORDER BY ()").get(); try (InsertResponse response = client.insert(tableName, new ByteArrayInputStream("1\t2\t3\t2024-12-22T12:00:00".getBytes(StandardCharsets.UTF_8)), ClickHouseFormat.TSV).get(30, TimeUnit.SECONDS)) { @@ -2312,7 +2307,7 @@ public void testReadingEnumsAsStrings() throws Exception { client.execute("DROP TABLE IF EXISTS " + tableName).get(); client.execute("CREATE TABLE `" + tableName + "` " + "(idx UInt8, enum1 Enum8('a' = 1, 'b' = 2, 'c' = 3), enum2 Enum16('atch' = 1, 'batch' = 2, 'catch' = 3)) " + - "ENGINE MergeTree ORDER BY ()").get(); + "ORDER BY ()").get(); try (InsertResponse response = client.insert(tableName, new ByteArrayInputStream("1\ta\t2".getBytes(StandardCharsets.UTF_8)), ClickHouseFormat.TSV).get(30, TimeUnit.SECONDS)) { Assert.assertEquals(response.getWrittenRows(), 1); @@ -2350,7 +2345,7 @@ public void testServerTimezone() throws Exception { @Test(groups = {"integration"}) public void testLowCardinalityValues() throws Exception { final String table = "test_low_cardinality_values"; - final String tableCreate = "CREATE TABLE " + table + "(rowID Int32, keyword LowCardinality(String)) Engine = MergeTree ORDER BY ()"; + final String tableCreate = "CREATE TABLE " + table + "(rowID Int32, keyword LowCardinality(String)) ORDER BY ()"; client.execute("DROP TABLE IF EXISTS " + table); client.execute(tableCreate); @@ -2522,9 +2517,9 @@ public void testDuplicateColumnNames() throws Exception { { client.execute("DROP TABLE IF EXISTS test_duplicate_column_names1").get().close(); client.execute("DROP TABLE IF EXISTS test_duplicate_column_names2").get().close(); - client.execute("CREATE TABLE test_duplicate_column_names1 (name String ) ENGINE = MergeTree ORDER BY ()").get().close(); + client.execute("CREATE TABLE test_duplicate_column_names1 (name String ) ORDER BY ()").get().close(); client.execute("INSERT INTO test_duplicate_column_names1 VALUES ('some name')").get().close(); - client.execute("CREATE TABLE test_duplicate_column_names2 (name String ) ENGINE = MergeTree ORDER BY ()").get().close(); + client.execute("CREATE TABLE test_duplicate_column_names2 (name String ) ORDER BY ()").get().close(); client.execute("INSERT INTO test_duplicate_column_names2 VALUES ('another name')").get().close(); List records = client.queryAll("SELECT * FROM test_duplicate_column_names1, test_duplicate_column_names2"); diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/BaseSQLTests.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/BaseSQLTests.java index 580a12995..d590e2a27 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/BaseSQLTests.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/BaseSQLTests.java @@ -120,7 +120,7 @@ protected void setupTables(Map tables, Connection connectio } createTableQuery.append(columns[i]); } - createTableQuery.append(") ENGINE = MergeTree() ORDER BY tuple()"); + createTableQuery.append(") ORDER BY tuple()"); statement.execute(createTableQuery.toString()); 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 a2af2ae6f..04ef247ca 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java @@ -413,7 +413,7 @@ public void testCreateArray() throws SQLException { final String tableName = "array_create_test"; final String arrayType = "Array(" + baseType + ")"; try (Statement stmt = conn.createStatement()) { - stmt.executeUpdate("CREATE TABLE " +tableName + " (v1 " + arrayType + ") ENGINE MergeTree ORDER BY ()"); + stmt.executeUpdate("CREATE TABLE " +tableName + " (v1 " + arrayType + ") ORDER BY ()"); Struct tuple1 = conn.createStruct(baseType, new Object[]{"v1", (byte)10}); @@ -614,7 +614,7 @@ public void testCreateStruct() throws SQLException { final String tableName = "test_struct_tuple"; final String tupleType = "Tuple(Int8, String, DateTime64)"; try (Statement stmt = conn.createStatement()) { - stmt.executeUpdate("CREATE TABLE " + tableName +" (v1 " + tupleType + ") ENGINE MergeTree ORDER BY ()"); + stmt.executeUpdate("CREATE TABLE " + tableName +" (v1 " + tupleType + ") ORDER BY ()"); final java.sql.Timestamp timePart = Timestamp.valueOf(LocalDateTime.now(ZoneId.of("America/Los_Angeles"))); timePart.setNanos(333000000); diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/DetachedResultSetTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/DetachedResultSetTest.java index 0751afdee..1ae7875ea 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/DetachedResultSetTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/DetachedResultSetTest.java @@ -43,7 +43,7 @@ public class DetachedResultSetTest extends JdbcIntegrationTest { @Test(groups = "integration") public void shouldReturnColumnIndex() throws SQLException { - runQuery("CREATE TABLE detached_rs_test_data (id UInt32, val UInt8) ENGINE = MergeTree ORDER BY (id)"); + runQuery("CREATE TABLE detached_rs_test_data (id UInt32, val UInt8) ORDER BY (id)"); runQuery("INSERT INTO detached_rs_test_data VALUES (1, 10), (2, 20)"); try (Connection conn = getJdbcConnection()) { @@ -361,7 +361,7 @@ public void testDateTimeTypes() throws SQLException { + "date Date, date32 Date32, " + "dateTime DateTime, dateTime32 DateTime32, " + "dateTime643 DateTime64(3), dateTime646 DateTime64(6), dateTime649 DateTime64(9)" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert minimum values insertData("INSERT INTO detached_rs_test_dates VALUES ( 1, '1970-01-01', '1970-01-01', " + diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/JDBCDateTimeTests.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/JDBCDateTimeTests.java index 1c74cb4bb..d8376b3a8 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/JDBCDateTimeTests.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/JDBCDateTimeTests.java @@ -52,7 +52,7 @@ void testDaysBeforeBirthdayParty() throws SQLException { props.put(ClientConfigProperties.serverSetting("session_timezone"), "Asia/Tokyo"); try (Connection conn = getJdbcConnection(props); Statement stmt = conn.createStatement()) { - stmt.executeUpdate("CREATE TABLE test_days_before_birthday_party (id Int32, birthdate Date32) Engine MergeTree ORDER BY()"); + stmt.executeUpdate("CREATE TABLE test_days_before_birthday_party (id Int32, birthdate Date32) ORDER BY ()"); try (PreparedStatement ps = conn.prepareStatement("INSERT INTO test_days_before_birthday_party VALUES (?, ?)")) { @@ -132,7 +132,7 @@ void testWalkTime() throws Exception { try (Connection conn = getJdbcConnection(props); Statement stmt = conn.createStatement()) { - stmt.executeUpdate("CREATE TABLE test_walk_time (id Int32, walk_time Time64(3)) Engine MergeTree ORDER BY()"); + stmt.executeUpdate("CREATE TABLE test_walk_time (id Int32, walk_time Time64(3)) ORDER BY ()"); final String walkTimeStr = DataTypeUtils.durationToTimeString(walkTime, 3); stmt.executeUpdate("INSERT INTO test_walk_time VALUES (1, '" + walkTimeStr + "')"); @@ -176,7 +176,7 @@ void testLapsTime() throws Exception { try (Connection conn = getJdbcConnection(props); Statement stmt = conn.createStatement()) { - stmt.executeUpdate("CREATE TABLE test_laps_time (racerId Int32, lapId Int32, lapTime Time64(3)) Engine MergeTree ORDER BY()"); + stmt.executeUpdate("CREATE TABLE test_laps_time (racerId Int32, lapId Int32, lapTime Time64(3)) ORDER BY ()"); Object[][] dataset = new Object[][]{ { @@ -236,7 +236,7 @@ void testDateInRange() throws Exception { Statement stmt = conn.createStatement()) { stmt.executeUpdate("DROP TABLE IF EXISTS test_date_in_range"); - stmt.executeUpdate("CREATE TABLE test_date_in_range ( id UInt32, d Date) Engine MergeTree ORDER BY()"); + stmt.executeUpdate("CREATE TABLE test_date_in_range ( id UInt32, d Date) ORDER BY ()"); stmt.executeUpdate("INSERT INTO test_date_in_range VALUES (1, '2025-01-01') , (2, '2025-02-01') , (3, '2025-02-03')"); try (PreparedStatement pStmt = conn.prepareStatement("SELECT * FROM test_date_in_range WHERE d IN (?) ORDER BY id")){ @@ -274,7 +274,7 @@ void testTimestampInRange() throws Exception { Statement stmt = conn.createStatement()) { stmt.executeUpdate("DROP TABLE IF EXISTS test_timestamp_in_range"); - stmt.executeUpdate("CREATE TABLE test_timestamp_in_range (id UInt32, ts DateTime) Engine MergeTree ORDER BY()"); + stmt.executeUpdate("CREATE TABLE test_timestamp_in_range (id UInt32, ts DateTime) ORDER BY ()"); stmt.executeUpdate("INSERT INTO test_timestamp_in_range VALUES " + "(1, '2025-01-01 08:00:00'), (2, '2025-01-01 12:00:00'), (3, '2025-01-01 18:00:00'), (4, '2025-01-02 00:00:00')"); diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/JdbcDataTypeTests.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/JdbcDataTypeTests.java index f00057bf5..1c4a67b3d 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/JdbcDataTypeTests.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/JdbcDataTypeTests.java @@ -93,7 +93,7 @@ public void testIntegerTypes() throws SQLException { runQuery("CREATE TABLE test_integers (order Int8, " + "int8 Int8, int16 Int16, int32 Int32, int64 Int64, int128 Int128, int256 Int256, " + "uint8 UInt8, uint16 UInt16, uint32 UInt32, uint64 UInt64, uint128 UInt128, uint256 UInt256" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert minimum values insertData("INSERT INTO test_integers VALUES ( 1, " @@ -263,7 +263,7 @@ public void testBigIntegerTypesMapping() throws SQLException { + "uint64_null Nullable(UInt64), " + "uint128_null Nullable(UInt128), " + "uint256_null Nullable(UInt256)" - + ") ENGINE = MergeTree ORDER BY id"); + + ") ORDER BY id"); // Test values BigInteger int128Min = new BigInteger("-170141183460469231731687303715884105728"); // -2^127 @@ -439,7 +439,7 @@ public void testUnsignedIntegerTypes() throws Exception { + "uint64 Nullable(UInt64), " + "uint128 Nullable(UInt128), " + "uint256 Nullable(UInt256)" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert null values insertData("INSERT INTO test_unsigned_integers VALUES ( 1, " @@ -522,7 +522,7 @@ public void testBFloat16() throws SQLException { final int batchSize = 4096; // keep each INSERT well under max_query_size runQuery("DROP TABLE IF EXISTS " + table); runQuery("CREATE TABLE " + table - + " (rowId Int32, v BFloat16, vNull Nullable(BFloat16)) ENGINE = MergeTree ORDER BY rowId"); + + " (rowId Int32, v BFloat16, vNull Nullable(BFloat16)) ORDER BY rowId"); try (Connection conn = getJdbcConnection(); Statement stmt = conn.createStatement()) { @@ -594,7 +594,7 @@ public void testQBit() throws SQLException { properties.setProperty(ClientConfigProperties.serverSetting("allow_experimental_qbit_type"), "1"); runQuery("DROP TABLE IF EXISTS " + table); runQuery("CREATE TABLE " + table - + " (rowId Int32, vec QBit(Float32, 8)) ENGINE = MergeTree ORDER BY rowId", properties); + + " (rowId Int32, vec QBit(Float32, 8)) ORDER BY rowId", properties); final float[] expected = { 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f }; @@ -643,7 +643,7 @@ public void testBFloat16WriteAsFloat() throws SQLException { final String table = "test_bfloat16_write"; runQuery("DROP TABLE IF EXISTS " + table); runQuery("CREATE TABLE " + table - + " (rowId Int32, v BFloat16, vNull Nullable(BFloat16)) ENGINE = MergeTree ORDER BY rowId"); + + " (rowId Int32, v BFloat16, vNull Nullable(BFloat16)) ORDER BY rowId"); float[] inputs = { 0f, 0.5f, 1.5f, -2.5f, 3.14f, 128.0f }; try (Connection conn = getJdbcConnection(); @@ -732,7 +732,7 @@ public void testUUIDTypes() throws Exception { Random rand = new Random(); runQuery("CREATE TABLE test_uuids (order Int8, " + "uuid Nullable(UUID) " - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert null values insertData("INSERT INTO test_uuids VALUES ( 1, NULL)"); @@ -780,7 +780,7 @@ public void testArrayOfUUID() throws Exception { public void testDecimalTypes() throws SQLException { runQuery("CREATE TABLE test_decimals (order Int8, " + "dec Decimal(9, 2), dec32 Decimal32(4), dec64 Decimal64(8), dec128 Decimal128(18), dec256 Decimal256(18)" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert minimum values insertData("INSERT INTO test_decimals VALUES ( 1, -9999999.99, -99999.9999, -9999999999.99999999, -99999999999999999999.999999999999999999, " + @@ -880,7 +880,7 @@ public void testDecimalTypesTruncateOnWriteAndRead() throws SQLException { runQuery("DROP TABLE IF EXISTS " + tableName); runQuery("CREATE TABLE " + tableName + " (order Int8, " + "dec Decimal(9, 2), dec32 Decimal32(4), dec64 Decimal64(8), dec128 Decimal128(18), dec256 Decimal256(18)" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); BigDecimal[] positiveWritten = new BigDecimal[] { new BigDecimal("1234567.899"), @@ -990,7 +990,7 @@ public void testDecimalTypesWithFractionalFloatParameters() throws SQLException runQuery("DROP TABLE IF EXISTS " + tableName); runQuery("CREATE TABLE " + tableName + " (order Int8, " + "dec Decimal(9, 4), dec32 Decimal32(4), dec64 Decimal64(8)" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); try (Connection conn = getJdbcConnection(); PreparedStatement stmt = conn.prepareStatement("INSERT INTO " + tableName + " VALUES (?, ?, ?, ?)")) { @@ -1034,7 +1034,7 @@ public void testDateTimeTypes() throws SQLException { runQuery("CREATE TABLE test_datetimes (order Int8, " + "dateTime DateTime, dateTime32 DateTime32, " + "dateTime643 DateTime64(3), dateTime646 DateTime64(6), dateTime649 DateTime64(9)" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert minimum values insertData("INSERT INTO test_datetimes VALUES ( 1, " + @@ -1186,7 +1186,7 @@ public void testDateTimeTypes() throws SQLException { public void testDateTypes() throws SQLException { runQuery("CREATE TABLE test_dates (order Int8, " + "date Date, date32 Date32" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert minimum values insertData("INSERT INTO test_dates VALUES ( 1, '1970-01-01', '1970-01-01')"); @@ -1285,7 +1285,7 @@ public void testTimeTypes() throws SQLException { createProperties.put(ClientConfigProperties.serverSetting("allow_experimental_time_time64_type"), "1"); runQuery("CREATE TABLE test_time64 (order Int8, " + "time Time, time64 Time64(9) " - + ") ENGINE = MergeTree ORDER BY ()", + + ") ORDER BY ()", createProperties); runQuery("INSERT INTO test_time64 (order, time, time64) VALUES " + @@ -1346,7 +1346,7 @@ public void testStringTypes() throws SQLException { + "str String, fixed FixedString(6), " + "enum Enum8('a' = 6, 'b' = 7, 'c' = 8), enum8 Enum8('a' = 1, 'b' = 2, 'c' = 3), enum16 Enum16('a' = 1, 'b' = 2, 'c' = 3), " + "uuid UUID, escaped String " - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -1415,7 +1415,7 @@ public void testEnumZeroLikeValues() throws SQLException { runQuery("DROP TABLE IF EXISTS test_enum_zero_like"); runQuery("CREATE TABLE test_enum_zero_like (order Int8, " + "e8 Enum8('' = 0, 'a' = 1, 'neg' = -5), e16 Enum16('zero' = 0, 'big' = 30000, 'nb' = -20000)" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); try (Connection conn = getJdbcConnection()) { try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO test_enum_zero_like VALUES ( ?, ?, ? )")) { @@ -1476,7 +1476,7 @@ public void testEnumZeroLikeValues() throws SQLException { public void testIpAddressTypes() throws SQLException, UnknownHostException { runQuery("CREATE TABLE test_ips (order Int8, " + "ipv4_ip IPv4, ipv4_name IPv4, ipv6 IPv6, ipv4_as_ipv6 IPv6" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -1573,7 +1573,7 @@ public void testArrayOfIpAddress() throws Exception { public void testFloatTypes() throws SQLException { runQuery("CREATE TABLE test_floats (order Int8, " + "float32 Float32, float64 Float64" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert minimum values insertData("INSERT INTO test_floats VALUES ( 1, -3.4028233E38, -1.7976931348623157E308 )"); @@ -1648,7 +1648,7 @@ public void testFloatTypes() throws SQLException { public void testBooleanTypes() throws SQLException { runQuery("CREATE TABLE test_booleans (order Int8, " + "bool Boolean" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -1695,7 +1695,7 @@ public void testArrayTypes() throws SQLException { + "array Array(Int8), arraystr Array(String), " + "arraytuple Array(Tuple(Int8, String)), " + "arraydate Array(Date)" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -1818,7 +1818,7 @@ public void testNestedType() throws SQLException { runQuery("CREATE TABLE test_nested_jdbc (order Int8, " + "n Nested(a Int8, b Nullable(String)), " + "tail Int32" - + ") ENGINE = MergeTree ORDER BY (order) SETTINGS flatten_nested = 0"); + + ") ORDER BY (order) SETTINGS flatten_nested = 0"); // A null in the Nullable field exercises null propagation through every read path. Tuple[] nested = new Tuple[] { @@ -1900,7 +1900,7 @@ private static void assertTupleEquals(Object[] actual, Tuple expected) { @Test(groups = { "integration" }) public void testStringsUsedAsBytes() throws Exception { - runQuery("CREATE TABLE test_strings_as_bytes (order Int8, str String, fixed FixedString(10)) ENGINE = MergeTree ORDER BY ()"); + runQuery("CREATE TABLE test_strings_as_bytes (order Int8, str String, fixed FixedString(10)) ORDER BY ()"); String[][] testData = {{"Hello, World!", "FixedStr"}, {"Test String 123", "ABC"}}; @@ -1949,7 +1949,7 @@ public void testBinaryStringSupportGetBytes() throws Exception { // ch_logo.png is real binary content that is not valid UTF-8, so it must survive a // round-trip through a String column byte-for-byte when binary_string_support is enabled. - runQuery("CREATE TABLE test_binary_string_get_bytes (id Int8, str String) ENGINE = MergeTree ORDER BY ()"); + runQuery("CREATE TABLE test_binary_string_get_bytes (id Int8, str String) ORDER BY ()"); try (Connection conn = getJdbcConnection(); PreparedStatement insert = conn.prepareStatement("INSERT INTO test_binary_string_get_bytes VALUES (?, ?)")) { @@ -1974,7 +1974,7 @@ public void testBinaryStringSupportGetBytes() throws Exception { @Test(groups = { "integration" }) public void testBinaryStringSupportGetBinaryStream() throws Exception { - runQuery("CREATE TABLE test_binary_string_stream (id Int8, str String, nullable_str Nullable(String)) ENGINE = MergeTree ORDER BY ()"); + runQuery("CREATE TABLE test_binary_string_stream (id Int8, str String, nullable_str Nullable(String)) ORDER BY ()"); try (Connection conn = getJdbcConnection(); PreparedStatement insert = conn.prepareStatement("INSERT INTO test_binary_string_stream VALUES (?, ?, ?)")) { @@ -2021,7 +2021,7 @@ public void testBinaryStringSupportGetObject() throws Exception { // With binary_string_support enabled the read path returns an internal StringValue holder for // String/FixedString columns. getObject must never leak that holder: it should return a decoded // String for Object.class and the no-type overload, and exact raw bytes for byte[].class. - runQuery("CREATE TABLE test_binary_string_get_object (id Int8, str String, txt String) ENGINE = MergeTree ORDER BY ()"); + runQuery("CREATE TABLE test_binary_string_get_object (id Int8, str String, txt String) ORDER BY ()"); String text = "Hello, ClickHouse!"; try (Connection conn = getJdbcConnection(); @@ -2165,7 +2165,7 @@ public void testNestedArrayToString() throws SQLException { public void testMapTypes() throws SQLException { runQuery("CREATE TABLE test_maps (order Int8, " + "map Map(String, Int8), mapstr Map(String, String)" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -2220,7 +2220,7 @@ public void testMapTypesWithArrayValues() throws SQLException { runQuery("CREATE TABLE test_maps (order Int8, " + "map Map(String, Array(Int32)), " + "map2 Map(String, Array(Int32))" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -2306,7 +2306,7 @@ public void testArrayOfMapsWithLowCardinalityAndEmptyMaps() throws Exception { runQuery("CREATE TABLE test_array_map_lc_empty (" + "StartedDateTime DateTime, " + "traits Array(Map(LowCardinality(String), String))" - + ") ENGINE = MergeTree ORDER BY StartedDateTime"); + + ") ORDER BY StartedDateTime"); try (Connection conn = getJdbcConnection(); Statement stmt = conn.createStatement()) { @@ -2384,7 +2384,7 @@ public void testNullableTypesSimpleStatement() throws SQLException { + "enum Nullable(Enum8('a' = 6, 'b' = 7, 'c' = 8)), enum8 Nullable(Enum8('a' = 1, 'b' = 2, 'c' = 3)), enum16 Nullable(Enum16('a' = 1, 'b' = 2, 'c' = 3)), " + "uuid Nullable(UUID), ipv4 Nullable(IPv4), ipv6 Nullable(IPv6), " + "float32 Nullable(Float32), float64 Nullable(Float64), " - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert null values insertData("INSERT INTO test_nullable VALUES ( 1, " @@ -2412,7 +2412,7 @@ public void testNullableTypesSimpleStatement() throws SQLException { public void testLowCardinalityTypeSimpleStatement() throws SQLException { runQuery("CREATE TABLE test_low_cardinality (order Int8, " + "lowcardinality LowCardinality(String)" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -2442,7 +2442,7 @@ public void testSimpleAggregateFunction() throws SQLException { runQuery("CREATE TABLE test_aggregate (order Int8," + " int8 Int8," + " val SimpleAggregateFunction(any, Nullable(Int8))" + - ") ENGINE = MergeTree ORDER BY ()"); + ") ORDER BY ()"); // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -2476,7 +2476,7 @@ public void testSimpleAggregateFunction() throws SQLException { public void testNestedTypeSimpleStatement() throws SQLException { runQuery("CREATE TABLE test_nested (order Int8, " + "nested Nested (int8 Int8, int16 Int16, int32 Int32, int64 Int64, int128 Int128, int256 Int256)" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -2524,7 +2524,7 @@ public void testNestedTypeNonFlatten() throws SQLException { stmt.execute("SET flatten_nested = 0"); stmt.execute("CREATE TABLE test_nested_not_flatten (order Int8, " + "nested Nested (int8 Int8, int16 Int16, int32 Int32, int64 Int64, int128 Int128, int256 Int256)" - + ") ENGINE = MergeTree ORDER BY () SETTINGS flatten_nested = 0"); + + ") ORDER BY () SETTINGS flatten_nested = 0"); // Insert random (valid) values long seed = System.currentTimeMillis(); Random rand = new Random(seed); @@ -2579,7 +2579,7 @@ public void testTupleType() throws Exception { public void testTupleTypeSimpleStatement() throws SQLException { runQuery("CREATE TABLE test_tuple (order Int8, " + "tuple Tuple(int8 Int8, int16 Int16, int32 Int32, int64 Int64, int128 Int128, int256 Int256)" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -2627,7 +2627,7 @@ public void testJSONWritingAsString() throws SQLException { createProperties.put(ClientConfigProperties.serverSetting("allow_experimental_json_type"), "1"); runQuery("CREATE TABLE test_json (order Int8, " + "json JSON" - + ") ENGINE = MergeTree ORDER BY ()", createProperties); + + ") ORDER BY ()", createProperties); // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -2687,7 +2687,7 @@ public void testGeometricTypesSimpleStatement() throws SQLException { // TODO: add LineString and MultiLineString support runQuery("CREATE TABLE test_geometric (order Int8, " + "point Point, ring Ring, linestring LineString, multilinestring MultiLineString, polygon Polygon, multipolygon MultiPolygon" - + ") ENGINE = MergeTree ORDER BY ()"); + + ") ORDER BY ()"); // Insert random (valid) values long seed = System.currentTimeMillis(); @@ -2733,7 +2733,7 @@ public void testDynamicTypesSimpleStatement() throws SQLException { properties.setProperty(ClientConfigProperties.serverSetting("allow_experimental_dynamic_type"), "1"); runQuery("CREATE TABLE test_dynamic (order Int8, " + "dynamic Dynamic" - + ") ENGINE = MergeTree ORDER BY ()", + + ") ORDER BY ()", properties); // Insert random (valid) values @@ -2849,7 +2849,7 @@ public void testVariantTypesSimpleStatement() throws SQLException { properties.setProperty(ClientConfigProperties.serverSetting("allow_experimental_variant_type"), "1"); runQuery("CREATE TABLE test_variant (order Int8, " + "v Variant(String, Int32)" - + ") ENGINE = MergeTree ORDER BY ()", + + ") ORDER BY ()", properties); // Insert random (valid) values @@ -2943,7 +2943,7 @@ public void testGeoPoint() throws Exception { try (Connection conn = getJdbcConnection(); Statement stmt = conn.createStatement()) { String table = "test_geo_point"; stmt.executeUpdate("DROP TABLE IF EXISTS " + table); - stmt.executeUpdate("CREATE TABLE " + table + " (geom Point) ENGINE = MergeTree ORDER BY ()"); + stmt.executeUpdate("CREATE TABLE " + table + " (geom Point) ORDER BY ()"); try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + table + " VALUES (?)")) { Double[] rowObj = Arrays.stream(row).boxed().toArray(Double[]::new); @@ -2981,7 +2981,7 @@ public void testGeoRing() throws Exception { try (Connection conn = getJdbcConnection(); Statement stmt = conn.createStatement()) { final String table = "test_geo_ring"; stmt.executeUpdate("DROP TABLE IF EXISTS " + table); - stmt.executeUpdate("CREATE TABLE " + table + " (geom Ring) ENGINE = MergeTree ORDER BY ()"); + stmt.executeUpdate("CREATE TABLE " + table + " (geom Ring) ORDER BY ()"); try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + table + " VALUES (?)")) { pstmt.setObject(1, conn.createArrayOf("Array(Point)", row)); @@ -3018,7 +3018,7 @@ public void testGeoLineString() throws Exception { try (Connection conn = getJdbcConnection(); Statement stmt = conn.createStatement()) { final String table = "test_geo_line_string"; stmt.executeUpdate("DROP TABLE IF EXISTS " + table); - stmt.executeUpdate("CREATE TABLE " + table +" (geom LineString) ENGINE = MergeTree ORDER BY ()"); + stmt.executeUpdate("CREATE TABLE " + table +" (geom LineString) ORDER BY ()"); try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + table + " VALUES (?)")) { pstmt.setObject(1, conn.createArrayOf("Array(Point)", row)); @@ -3067,7 +3067,7 @@ public void testGeoMultiPoint() throws Exception { final String table = "test_geo_multi_point"; stmt.executeUpdate("DROP TABLE IF EXISTS " + table); stmt.executeUpdate("CREATE TABLE " + table - + " (rowId Int32, geom MultiPoint, marker Float64) ENGINE = MergeTree ORDER BY rowId"); + + " (rowId Int32, geom MultiPoint, marker Float64) ORDER BY rowId"); try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + table + " VALUES (?, ?, ?)")) { @@ -3125,7 +3125,7 @@ public void testGeoMultiLineString() throws Exception { try (Connection conn = getJdbcConnection(); Statement stmt = conn.createStatement()) { final String table = "test_geo_multi_line_string"; stmt.executeUpdate("DROP TABLE IF EXISTS " + table); - stmt.executeUpdate("CREATE TABLE " + table +" (geom MultiLineString) ENGINE = MergeTree ORDER BY ()"); + stmt.executeUpdate("CREATE TABLE " + table +" (geom MultiLineString) ORDER BY ()"); try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + table + " VALUES (?)")) { pstmt.setObject(1, conn.createArrayOf("Array(Array(Point))", row)); @@ -3170,7 +3170,7 @@ public void testGeoPolygon() throws Exception { try (Connection conn = getJdbcConnection(); Statement stmt = conn.createStatement()) { final String table = "test_geo_polygon"; stmt.executeUpdate("DROP TABLE IF EXISTS " + table); - stmt.executeUpdate("CREATE TABLE " + table +" (geom Polygon) ENGINE = MergeTree ORDER BY ()"); + stmt.executeUpdate("CREATE TABLE " + table +" (geom Polygon) ORDER BY ()"); try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + table + " VALUES (?)")) { pstmt.setObject(1, conn.createArrayOf("Array(Array(Point))", row)); @@ -3231,7 +3231,7 @@ public void testGeoMultiPolygon() throws Exception { try (Connection conn = getJdbcConnection(); Statement stmt = conn.createStatement()) { final String table = "test_geo_muti_polygon"; stmt.executeUpdate("DROP TABLE IF EXISTS " + table); - stmt.executeUpdate("CREATE TABLE " + table +" (geom MultiPolygon) ENGINE = MergeTree ORDER BY ()"); + stmt.executeUpdate("CREATE TABLE " + table +" (geom MultiPolygon) ORDER BY ()"); try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + table + " VALUES (?)")) { pstmt.setObject(1, conn.createArrayOf("Array(Array(Array(Point)))", row)); @@ -3277,7 +3277,7 @@ public void testGeoGeometry() throws Exception { try (Connection conn = getJdbcConnection(properties); Statement stmt = conn.createStatement()) { stmt.executeUpdate("DROP TABLE IF EXISTS " + table); - stmt.executeUpdate("CREATE TABLE " + table + " (rowId Int32, geom Geometry) ENGINE = MergeTree ORDER BY ()"); + stmt.executeUpdate("CREATE TABLE " + table + " (rowId Int32, geom Geometry) ORDER BY ()"); stmt.executeUpdate("INSERT INTO " + table + " VALUES " + "(0, (1, 2)), " + "(1, [(1, 2), (3, 4), (1, 2)]), " @@ -3331,7 +3331,7 @@ public void testGeoGeometryPreparedStatement() throws Exception { try (Connection conn = getJdbcConnection(properties); Statement stmt = conn.createStatement()) { stmt.executeUpdate("DROP TABLE IF EXISTS " + table); - stmt.executeUpdate("CREATE TABLE " + table + " (rowId Int32, geom Geometry) ENGINE = MergeTree ORDER BY ()"); + stmt.executeUpdate("CREATE TABLE " + table + " (rowId Int32, geom Geometry) ORDER BY ()"); try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + table + " VALUES (?, ?)")) { for (int i = 0; i < expectedValues.length; i++) { @@ -3431,7 +3431,7 @@ public void testJSONRead(String json, Object expected) throws Exception { Properties createProperties = new Properties(); createProperties.put(ClientConfigProperties.serverSetting("allow_experimental_json_type"), "1"); runQuery("DROP TABLE IF EXISTS test_jdbc_json_read"); - runQuery("CREATE TABLE test_jdbc_json_read (data JSON) ENGINE = MergeTree ORDER BY ()", createProperties); + runQuery("CREATE TABLE test_jdbc_json_read (data JSON) ORDER BY ()", createProperties); try (Connection conn = getJdbcConnection(); Statement stmt = conn.createStatement()) { final String sql = "INSERT INTO test_jdbc_json_read (data) VALUES ('%s'), ('{}')"; @@ -3547,10 +3547,10 @@ public void testTimeAndDateTimeCompatibleWithJDBCTime() throws Exception { ? "CREATE TABLE test_time_compat (order Int8, " + "time Time, time64 Time64(3), " + "dateTime DateTime('UTC'), dateTime64 DateTime64(3, 'UTC') " - + ") ENGINE = MergeTree ORDER BY ()" + + ") ORDER BY ()" : "CREATE TABLE test_time_compat (order Int8, " + "dateTime DateTime('UTC'), dateTime64 DateTime64(3, 'UTC') " - + ") ENGINE = MergeTree ORDER BY ()"; + + ") ORDER BY ()"; runQuery(tableDDL, createProperties); diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java index 8bdfccc2b..5dc8d018d 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java @@ -489,7 +489,7 @@ void testWithClauseWithParams() throws Exception { try (Connection conn = getJdbcConnection()) { try (Statement stmt = conn.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); - stmt.execute("CREATE TABLE " + table + " (v1 String) Engine MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE " + table + " (v1 String) ORDER BY ()"); stmt.execute("INSERT INTO " + table + " VALUES ('A'), ('B')"); } final Timestamp target_time = Timestamp.valueOf(LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS)); @@ -647,7 +647,7 @@ void testInsert() throws Exception { void testGetMetadata(String sql, int colCountBeforeExecution, Object[] values, int colCountAfterExecution) throws Exception { String tableName = "test_get_metadata"; - runQuery("CREATE TABLE IF NOT EXISTS " + tableName + " ( a1 String, b2 Float, b3 Float ) Engine=MergeTree ORDER BY ()"); + runQuery("CREATE TABLE IF NOT EXISTS " + tableName + " ( a1 String, b2 Float, b3 Float ) ORDER BY ()"); try (Connection conn = getJdbcConnection(); PreparedStatement stmt = conn.prepareStatement(String.format(sql, tableName))) { @@ -885,7 +885,7 @@ void testInsertWithRewrittenValuesList(String valuesList) throws Exception { try (Connection conn = getJdbcConnection()) { try (Statement stmt = conn.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); - stmt.execute("CREATE TABLE " + table + " (s String, n Int32) Engine MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE " + table + " (s String, n Int32) ORDER BY ()"); } try (PreparedStatement stmt = conn.prepareStatement( "INSERT INTO " + table + " (s, n) VALUES " + valuesList)) { @@ -911,7 +911,7 @@ void testBatchInsertWithRewrittenValuesList() throws Exception { try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) { try (Statement stmt = conn.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); - stmt.execute("CREATE TABLE " + table + " (s DateTime, n Int32) Engine MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE " + table + " (s DateTime, n Int32) ORDER BY ()"); } try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO " + table + " (s, n) VALUES (toDateTime({ts '2024-01-01 00:00:00'}), ?)")) { @@ -940,7 +940,7 @@ void testInsertWithHeredocValue() throws Exception { try (Connection conn = getJdbcConnection()) { try (Statement stmt = conn.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); - stmt.execute("CREATE TABLE " + table + " (s String, n Int32) Engine MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE " + table + " (s String, n Int32) ORDER BY ()"); } try (PreparedStatement stmt = conn.prepareStatement( "INSERT INTO " + table + " (s, n) VALUES ($$a@b$$, ?)")) { @@ -962,8 +962,8 @@ void testStatementSplit() throws Exception { try (Connection conn = getJdbcConnection()) { try (Statement stmt = conn.createStatement()) { stmt.execute("CREATE TABLE IF NOT EXISTS `with_complex_id` (`v?``1` Int32, " + - "\"v?\"\"2\" Int32,`v?\\`3` Int32, \"v?\\\"4\" Int32) ENGINE MergeTree ORDER BY ();"); - stmt.execute("CREATE TABLE IF NOT EXISTS `test_stmt_split2` (v1 Int32, v2 String) ENGINE MergeTree ORDER BY (); "); + "\"v?\"\"2\" Int32,`v?\\`3` Int32, \"v?\\\"4\" Int32) ORDER BY ();"); + stmt.execute("CREATE TABLE IF NOT EXISTS `test_stmt_split2` (v1 Int32, v2 String) ORDER BY (); "); stmt.execute("INSERT INTO `test_stmt_split2` VALUES (1, 'abc'), (2, '?'), (3, '?')"); } String insertQuery = "-- line comment1 ?\n" @@ -1095,7 +1095,7 @@ void testBatchInsertWithRowBinary(String sql, Class implClass) throws Exception try (Statement stmt = conn.createStatement()) { stmt.execute("CREATE TABLE IF NOT EXISTS " + table + - " ( ts DateTime, v1 Int32, v2 Float32, v3 Int32) Engine MergeTree ORDER BY ()"); + " ( ts DateTime, v1 Int32, v2 Float32, v3 Int32) ORDER BY ()"); } final int nBatches = 10; @@ -1152,7 +1152,7 @@ void testBatchInsertTextStatement(String sql) throws Exception { try (Statement stmt = conn.createStatement()) { stmt.execute("CREATE TABLE IF NOT EXISTS " + table + - " ( ts DateTime DEFAULT now(), v1 Int32, v2 Float32, v3 Int32) Engine MergeTree ORDER BY ()"); + " ( ts DateTime DEFAULT now(), v1 Int32, v2 Float32, v3 Int32) ORDER BY ()"); } final int nBatches = 10; @@ -1203,7 +1203,7 @@ void testBatchInsertNoValuesReuse() throws Exception { try (Statement stmt = conn.createStatement()) { stmt.execute("CREATE TABLE IF NOT EXISTS " + table + - " (v1 Int32, v2 Int32) Engine MergeTree ORDER BY tuple()"); + " (v1 Int32, v2 Int32) ORDER BY tuple()"); } final int nBatches = 10; @@ -1258,7 +1258,7 @@ void testBatchInsertValuesReuse() throws Exception { try (Statement stmt = conn.createStatement()) { stmt.execute("CREATE TABLE IF NOT EXISTS " + table + - " (v1 Int32, v2 Int32) Engine MergeTree ORDER BY tuple()"); + " (v1 Int32, v2 Int32) ORDER BY tuple()"); } final int nBatches = 10; @@ -1310,7 +1310,7 @@ void testBatchInsertWithValueOfUnsupportedSyntax(String parserName) throws Excep try (Connection conn = getJdbcConnection(properties)) { try (Statement stmt = conn.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); - stmt.execute("CREATE TABLE " + table + " (v1 Int32, v2 String) Engine MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE " + table + " (v1 Int32, v2 String) ORDER BY ()"); } try (PreparedStatement stmt = conn.prepareStatement( @@ -1505,7 +1505,7 @@ public void testBoundValuesContainingJdbcEscapeSyntax() throws Exception { try (Statement stmt = conn.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); stmt.execute("CREATE TABLE " + table + - "(v1 Int32, v2 Map(String, String), v3 String, v4 Int32) Engine MergeTree ORDER BY (v1)"); + "(v1 Int32, v2 Map(String, String), v3 String, v4 Int32) ORDER BY (v1)"); } Map map1 = new LinkedHashMap<>(); @@ -1564,7 +1564,7 @@ public void testStatementsWithDatabaseInTableIdentifier() throws Exception { stmt.execute("CREATE DATABASE IF NOT EXISTS " + db1Name); stmt.execute("DROP TABLE IF EXISTS " + db1Name + "." + table1Name); stmt.execute("CREATE TABLE " + db1Name + "." + table1Name + - "(v1 Int32, v2 Int32) Engine MergeTree ORDER BY ()"); + "(v1 Int32, v2 Int32) ORDER BY ()"); } String[] tableIdentifier = new String[]{ @@ -1592,7 +1592,7 @@ public void testNullValues() throws Exception { try (Statement stmt = conn.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); stmt.execute("CREATE TABLE " + table + - "(v1 Int32, v2 Nullable(Int32)) Engine MergeTree ORDER BY ()"); + "(v1 Int32, v2 Nullable(Int32)) ORDER BY ()"); } try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO " + table + " VALUES (?, ?)")) { @@ -1653,7 +1653,7 @@ public void testSelectWithTableAliasAsKeyword() throws Exception { try (Statement stmt = conn.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); stmt.execute( -"CREATE TABLE " + table + " (v1 Int32, v2 String) Engine MergeTree ORDER BY ()"); +"CREATE TABLE " + table + " (v1 Int32, v2 String) ORDER BY ()"); stmt.execute("INSERT INTO `" + table + "` VALUES (1000, 'test')"); } @@ -1978,7 +1978,7 @@ void testDateDayShiftWithDifferentTimezones() throws Exception { try (Connection conn = getJdbcConnection()) { try (Statement stmt = conn.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); - stmt.execute("CREATE TABLE " + table + " (id Int32, d Date) Engine MergeTree ORDER BY id"); + stmt.execute("CREATE TABLE " + table + " (id Int32, d Date) ORDER BY id"); } // Test dates that are prone to day shift issues (near year boundaries, month boundaries) @@ -2054,7 +2054,7 @@ void testDateWithAndWithoutCalendar() throws Exception { try (Connection conn = getJdbcConnection()) { try (Statement stmt = conn.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); - stmt.execute("CREATE TABLE " + table + " (id Int32, d Date) Engine MergeTree ORDER BY id"); + stmt.execute("CREATE TABLE " + table + " (id Int32, d Date) ORDER BY id"); } java.sql.Date testDate = java.sql.Date.valueOf("2024-06-15"); @@ -2130,7 +2130,7 @@ public void testUnknownStatement() throws Exception { String tmpTable = "tmp_no_result_" + RandomStringUtils.randomAlphanumeric(8); // PreparedStatement: execute() should return false, executeQuery() should throw try (PreparedStatement stmt = conn.prepareStatement( - "CREATE TABLE " + tmpTable + " (x Int32) Engine MergeTree ORDER BY()")) { + "CREATE TABLE " + tmpTable + " (x Int32) ORDER BY()")) { Assert.assertFalse(stmt.execute(), "DDL should not produce a ResultSet"); Assert.assertNull(stmt.getResultSet(), "ResultSet should be null for DDL"); assertThrows(SQLException.class, stmt::executeQuery); @@ -2139,11 +2139,11 @@ public void testUnknownStatement() throws Exception { String tmpTable2 = "tmp_no_result_" + RandomStringUtils.randomAlphanumeric(8); try (Statement stmt = conn.createStatement()) { Assert.assertFalse( - stmt.execute("CREATE TABLE " + tmpTable2 + " (x Int32) Engine MergeTree ORDER BY()"), + stmt.execute("CREATE TABLE " + tmpTable2 + " (x Int32) ORDER BY()"), "DDL should not produce a ResultSet"); Assert.assertNull(stmt.getResultSet(), "ResultSet should be null for DDL"); assertThrows(SQLException.class, - () -> stmt.executeQuery("CREATE TABLE " + tmpTable2 + " (x Int32) Engine MergeTree ORDER BY()")); + () -> stmt.executeQuery("CREATE TABLE " + tmpTable2 + " (x Int32) ORDER BY()")); } } } @@ -2166,7 +2166,7 @@ public void testInsertWithUnparsableValueExpression(String parserName) throws Ex try (Connection conn = getJdbcConnection(properties)) { try (Statement stmt = conn.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); - stmt.execute("CREATE TABLE " + table + " (v1 String, v2 String) Engine MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE " + table + " (v1 String, v2 String) ORDER BY ()"); } try (PreparedStatement stmt = conn.prepareStatement( diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/ResultSetImplTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/ResultSetImplTest.java index 1f1629faf..f6ad7842f 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/ResultSetImplTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/ResultSetImplTest.java @@ -41,7 +41,7 @@ public class ResultSetImplTest extends JdbcIntegrationTest { @Test(groups = "integration") public void shouldReturnColumnIndex() throws SQLException { - runQuery("CREATE TABLE rs_test_data (id UInt32, val UInt8) ENGINE = MergeTree ORDER BY (id)"); + runQuery("CREATE TABLE rs_test_data (id UInt32, val UInt8) ORDER BY (id)"); runQuery("INSERT INTO rs_test_data VALUES (1, 10), (2, 20)"); try (Connection conn = getJdbcConnection()) { 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 2dba637e9..f083ffbb8 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java @@ -146,7 +146,7 @@ public void testExecuteQueryDates() throws Exception { public void testExecuteUpdateSimpleNumbers() throws Exception { try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) { try (Statement stmt = conn.createStatement()) { - assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".simpleNumbers (num UInt8) ENGINE = MergeTree ORDER BY ()"), 0); + assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".simpleNumbers (num UInt8) ORDER BY ()"), 0); assertEquals(stmt.executeUpdate("INSERT INTO " + getDatabase() + ".simpleNumbers VALUES (1), (2), (3)"), 3); try (ResultSet rs = stmt.executeQuery("SELECT num FROM " + getDatabase() + ".simpleNumbers ORDER BY num")) { assertTrue(rs.next()); @@ -165,7 +165,7 @@ public void testExecuteUpdateSimpleNumbers() throws Exception { public void testExecuteUpdateSimpleFloats() throws Exception { try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) { try (Statement stmt = conn.createStatement()) { - assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".simpleFloats (num Float32) ENGINE = MergeTree ORDER BY ()"), 0); + assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".simpleFloats (num Float32) ORDER BY ()"), 0); assertEquals(stmt.executeUpdate("INSERT INTO " + getDatabase() + ".simpleFloats VALUES (1.1), (2.2), (3.3)"), 3); try (ResultSet rs = stmt.executeQuery("SELECT num FROM " + getDatabase() + ".simpleFloats ORDER BY num")) { assertTrue(rs.next()); @@ -185,7 +185,7 @@ public void testExecuteUpdateSimpleFloats() throws Exception { public void testExecuteUpdateBooleans() throws Exception { try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) { try (Statement stmt = conn.createStatement()) { - assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".booleans (id UInt8, flag Boolean) ENGINE = MergeTree ORDER BY ()"), 0); + assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".booleans (id UInt8, flag Boolean) ORDER BY ()"), 0); assertEquals(stmt.executeUpdate("INSERT INTO " + getDatabase() + ".booleans VALUES (0, true), (1, false), (2, true)"), 3); try (ResultSet rs = stmt.executeQuery("SELECT flag FROM " + getDatabase() + ".booleans ORDER BY id")) { assertTrue(rs.next()); @@ -204,7 +204,7 @@ public void testExecuteUpdateBooleans() throws Exception { public void testExecuteUpdateStrings() throws Exception { try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) { try (Statement stmt = conn.createStatement()) { - assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".strings (id UInt8, words String) ENGINE = MergeTree ORDER BY ()"), 0); + assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".strings (id UInt8, words String) ORDER BY ()"), 0); assertEquals(stmt.executeUpdate("INSERT INTO " + getDatabase() + ".strings VALUES (0, 'Hello'), (1, 'World'), (2, 'ClickHouse')"), 3); try (ResultSet rs = stmt.executeQuery("SELECT words FROM " + getDatabase() + ".strings ORDER BY id")) { assertTrue(rs.next()); @@ -223,7 +223,7 @@ public void testExecuteUpdateStrings() throws Exception { public void testExecuteUpdateNulls() throws Exception { try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) { try (Statement stmt = conn.createStatement()) { - assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".nulls (id UInt8, nothing Nullable(String)) ENGINE = MergeTree ORDER BY ()"), 0); + assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".nulls (id UInt8, nothing Nullable(String)) ORDER BY ()"), 0); assertEquals(stmt.executeUpdate("INSERT INTO " + getDatabase() + ".nulls VALUES (0, 'Hello'), (1, NULL), (2, 'ClickHouse')"), 3); try (ResultSet rs = stmt.executeQuery("SELECT nothing FROM " + getDatabase() + ".nulls ORDER BY id")) { assertTrue(rs.next()); @@ -242,7 +242,7 @@ public void testExecuteUpdateNulls() throws Exception { public void testExecuteUpdateDates() throws Exception { try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) { try (Statement stmt = conn.createStatement()) { - assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".dates (id UInt8, date Nullable(Date), datetime Nullable(DateTime)) ENGINE = MergeTree ORDER BY ()"), 0); + assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".dates (id UInt8, date Nullable(Date), datetime Nullable(DateTime)) ORDER BY ()"), 0); assertEquals(stmt.executeUpdate("INSERT INTO " + getDatabase() + ".dates VALUES (0, '2020-01-01', '2020-01-01 10:11:12'), (1, NULL, '2020-01-01 12:10:07'), (2, '2020-01-01', NULL)"), 3); try (ResultSet rs = stmt.executeQuery("SELECT date, datetime FROM " + getDatabase() + ".dates ORDER BY id")) { assertTrue(rs.next()); @@ -300,7 +300,7 @@ public void testInsertWithAsyncInsert(String asyncInsert, String waitAsyncInsert try (Connection conn = getJdbcConnection(props)) { try (Statement stmt = conn.createStatement()) { - stmt.execute("CREATE TABLE IF NOT EXISTS " + getDatabase() + "." + tableName + " (id UInt32, name String, value Float64, status Int8, timestamp DateTime) ENGINE = MergeTree ORDER BY id"); + stmt.execute("CREATE TABLE IF NOT EXISTS " + getDatabase() + "." + tableName + " (id UInt32, name String, value Float64, status Int8, timestamp DateTime) ORDER BY id"); stmt.execute("TRUNCATE TABLE " + getDatabase() + "." + tableName); int updateCount = stmt.executeUpdate(insertStatement); @@ -336,7 +336,7 @@ public void testInsertWithAsyncInsert(String asyncInsert, String waitAsyncInsert public void testExecuteUpdateBatch() throws Exception { try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) { try (Statement stmt = conn.createStatement()) { - assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".batch (id UInt8, num UInt8) ENGINE = MergeTree ORDER BY ()"), 0); + assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + getDatabase() + ".batch (id UInt8, num UInt8) ORDER BY ()"), 0); stmt.addBatch("INSERT INTO " + getDatabase() + ".batch VALUES (0, 1)"); stmt.addBatch("INSERT INTO " + getDatabase() + ".batch VALUES (1, 2)"); stmt.addBatch("INSERT INTO " + getDatabase() + ".batch VALUES (2, 3), (3, 4)"); @@ -365,7 +365,7 @@ public void testExecuteUpdateBatchReuse() throws Exception { String tableClause = getDatabase() + ".batch_reuse"; try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) { try (Statement stmt = conn.createStatement()) { - assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableClause + " (id UInt8, num UInt8) ENGINE = MergeTree ORDER BY ()"), 0); + assertEquals(stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableClause + " (id UInt8, num UInt8) ORDER BY ()"), 0); // add and execute first invalid batch stmt.addBatch("INSERT INTO " + tableClause + " VALUES (0, 'invalid')"); assertThrows(SQLException.class, stmt::executeBatch); @@ -886,7 +886,7 @@ public void testCancelInsertWithSession() throws Exception { try (Connection conn = getJdbcConnection(properties)) { try (Statement setup = conn.createStatement()) { setup.execute("DROP TABLE IF EXISTS " + tableName); - setup.execute("CREATE TABLE " + tableName + " (num UInt64) ENGINE = MergeTree ORDER BY ()"); + setup.execute("CREATE TABLE " + tableName + " (num UInt64) ORDER BY ()"); } try (StatementImpl stmt = (StatementImpl) conn.createStatement()) { @@ -1055,7 +1055,7 @@ void testWithClause() throws Exception { @Test(groups = {"integration"}) public void testSwitchDatabase() throws Exception { String databaseName = getDatabase() + "_test_switch"; - String createSql = "CREATE TABLE switchDatabaseWithUse (id UInt8, words String) ENGINE = MergeTree ORDER BY ()"; + String createSql = "CREATE TABLE switchDatabaseWithUse (id UInt8, words String) ORDER BY ()"; try (Connection conn = getJdbcConnection()) { try (Statement stmt = conn.createStatement()) { assertEquals(stmt.executeUpdate(createSql), 0); @@ -1553,7 +1553,7 @@ public void testExecute() throws Exception { try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF)); Statement stmt = conn.createStatement()) { // no result set and update count - Assert.assertFalse(stmt.execute("CREATE TABLE test_multi_result (id Int32) Engine MergeTree ORDER BY ()")); + Assert.assertFalse(stmt.execute("CREATE TABLE test_multi_result (id Int32) ORDER BY ()")); Assert.assertNull(stmt.getResultSet()); Assert.assertEquals(stmt.getUpdateCount(), 0); Assert.assertFalse(stmt.getMoreResults()); @@ -1609,18 +1609,18 @@ public void testUnsupportedOperations(Properties props, boolean shouldThrow) thr () -> stmt.execute("SELECT 1", Statement.RETURN_GENERATED_KEYS), () -> stmt.execute("SELECT 1", new int[] {1}), () -> stmt.execute("SELECT 1", new String[] {"1"}), - () -> stmt.executeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_01 (id Int32) Engine MergeTree ORDER BY ()", Statement.RETURN_GENERATED_KEYS), - () -> stmt.executeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_02 (id Int32) Engine MergeTree ORDER BY ()", new int[] {1}), - () -> stmt.executeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_03 (id Int32) Engine MergeTree ORDER BY ()", new String[] {"1"}), - () -> stmt.executeLargeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_01 (id Int32) Engine MergeTree ORDER BY ()", Statement.RETURN_GENERATED_KEYS), - () -> stmt.executeLargeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_02 (id Int32) Engine MergeTree ORDER BY ()", new int[] {1}), - () -> stmt.executeLargeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_03 (id Int32) Engine MergeTree ORDER BY ()", new String[] {"1"}), + () -> stmt.executeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_01 (id Int32) ORDER BY ()", Statement.RETURN_GENERATED_KEYS), + () -> stmt.executeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_02 (id Int32) ORDER BY ()", new int[] {1}), + () -> stmt.executeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_03 (id Int32) ORDER BY ()", new String[] {"1"}), + () -> stmt.executeLargeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_01 (id Int32) ORDER BY ()", Statement.RETURN_GENERATED_KEYS), + () -> stmt.executeLargeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_02 (id Int32) ORDER BY ()", new int[] {1}), + () -> stmt.executeLargeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_03 (id Int32) ORDER BY ()", new String[] {"1"}), () -> stmt.setCursorName("CURSOR_NAME_IGNORED") ); stmt.execute("SELECT 1", Statement.NO_GENERATED_KEYS); // supported - stmt.executeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_04 (id Int32) Engine MergeTree ORDER BY ()", Statement.NO_GENERATED_KEYS); // supported - stmt.executeLargeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_04 (id Int32) Engine MergeTree ORDER BY ()", Statement.NO_GENERATED_KEYS); // supported + stmt.executeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_04 (id Int32) ORDER BY ()", Statement.NO_GENERATED_KEYS); // supported + stmt.executeLargeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_04 (id Int32) ORDER BY ()", Statement.NO_GENERATED_KEYS); // supported assertNull(stmt.getGeneratedKeys()); @@ -1681,9 +1681,9 @@ public void testResponseWithDuplicateColumns() throws Exception { { stmt.execute("DROP TABLE IF EXISTS test_jdbc_duplicate_column_names1"); stmt.execute("DROP TABLE IF EXISTS test_jdbc_duplicate_column_names2"); - stmt.execute("CREATE TABLE test_jdbc_duplicate_column_names1 (name String ) ENGINE = MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE test_jdbc_duplicate_column_names1 (name String ) ORDER BY ()"); stmt.execute("INSERT INTO test_jdbc_duplicate_column_names1 VALUES ('some name')"); - stmt.execute("CREATE TABLE test_jdbc_duplicate_column_names2 (name String ) ENGINE = MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE test_jdbc_duplicate_column_names2 (name String ) ORDER BY ()"); stmt.execute("INSERT INTO test_jdbc_duplicate_column_names2 VALUES ('another name')"); try (ResultSet rs = stmt.executeQuery("SELECT * FROM test_jdbc_duplicate_column_names1, test_jdbc_duplicate_column_names2")) { @@ -1759,7 +1759,7 @@ public void testUnknownStatement(String parserName) throws Exception { stmt.execute("DROP TABLE IF EXISTS test_unknown_statement_test"); - stmt.execute("CREATE TABLE test_unknown_statement_test (v Int32) Engine MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE test_unknown_statement_test (v Int32) ORDER BY ()"); // INSERT via execute(...) must not produce a ResultSet and should return false boolean hasResultSet = stmt.execute("INSERT INTO test_unknown_statement_test VALUES (1);"); diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/WriterStatementImplTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/WriterStatementImplTest.java index 8980653b1..d6c12f96e 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/WriterStatementImplTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/WriterStatementImplTest.java @@ -54,7 +54,7 @@ public static Object[][] nonNullableArrayNullTables() { public void testWriterNullIntoNonNullableArrayThrows(String columns) throws Exception { String table = "writer_stmt_arr_null_" + UUID.randomUUID().toString().replace('-', '_'); runQuery("DROP TABLE IF EXISTS " + table); - runQuery("CREATE TABLE " + table + " (" + columns + ") Engine = MergeTree ORDER BY id"); + runQuery("CREATE TABLE " + table + " (" + columns + ") ORDER BY id"); Properties properties = new Properties(); properties.setProperty(DriverProperties.BETA_ROW_BINARY_WRITER.getKey(), "true"); @@ -83,7 +83,7 @@ public static Object[][] nonNullableArrayRoundTrip() { public void testWriterNonNullableArrayRoundTrips(List arr, int expectedLength, String expectedConcat) throws Exception { String table = "writer_stmt_arr_round_trip_" + UUID.randomUUID().toString().replace('-', '_'); runQuery("DROP TABLE IF EXISTS " + table); - runQuery("CREATE TABLE " + table + " (id Int32, arr Array(Int32), tail Int32) Engine = MergeTree ORDER BY id"); + runQuery("CREATE TABLE " + table + " (id Int32, arr Array(Int32), tail Int32) ORDER BY id"); Properties properties = new Properties(); properties.setProperty(DriverProperties.BETA_ROW_BINARY_WRITER.getKey(), "true"); @@ -111,7 +111,7 @@ public void testWriterNonNullableArrayRoundTrips(List arr, int expected public void testWriterNullIntoDefaultedArrayUsesDefault() throws Exception { String table = "writer_stmt_arr_null_default_" + UUID.randomUUID().toString().replace('-', '_'); runQuery("DROP TABLE IF EXISTS " + table); - runQuery("CREATE TABLE " + table + " (id Int32, arr Array(Int32) DEFAULT [1, 2], tail Int32) Engine = MergeTree ORDER BY id"); + runQuery("CREATE TABLE " + table + " (id Int32, arr Array(Int32) DEFAULT [1, 2], tail Int32) ORDER BY id"); Properties properties = new Properties(); properties.setProperty(DriverProperties.BETA_ROW_BINARY_WRITER.getKey(), "true"); @@ -163,7 +163,7 @@ public void testInsertWithQuotedColumnNames(String sqlTemplate) throws SQLExcept try (Statement stmt = connection.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); stmt.execute("CREATE TABLE " + table + - " (field1 String, field2 Int32, field3 String) Engine MergeTree ORDER BY ()"); + " (field1 String, field2 Int32, field3 String) ORDER BY ()"); } try (PreparedStatement ps = connection.prepareStatement(String.format(sqlTemplate, table))) { @@ -204,7 +204,7 @@ public void testWriterCleanupSwallowsBufferCloseFailure() throws Exception { try (Connection connection = getJdbcConnection(properties)) { try (Statement stmt = connection.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); - stmt.execute("CREATE TABLE " + table + " (field1 Int32) Engine MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE " + table + " (field1 Int32) ORDER BY ()"); } final int[] closeAttempts = {0}; @@ -299,7 +299,7 @@ public void testInsertIntoPlainTableStillUsesWriter(String parser, String sqlTem try (Connection connection = getJdbcConnection(properties)) { try (Statement stmt = connection.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); - stmt.execute("CREATE TABLE " + table + " (id Int32) Engine MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE " + table + " (id Int32) ORDER BY ()"); } try (PreparedStatement ps = connection.prepareStatement(String.format(sqlTemplate, table))) { @@ -333,7 +333,7 @@ public void testInsertWithUnparseableFunctionNotWrittenWithRowBinary(String pars try (Connection connection = getJdbcConnection(properties)) { try (Statement stmt = connection.createStatement()) { stmt.execute("DROP TABLE IF EXISTS " + table); - stmt.execute("CREATE TABLE " + table + " (v1 Int32, v2 String) Engine MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE " + table + " (v1 Int32, v2 String) ORDER BY ()"); } try (PreparedStatement ps = connection.prepareStatement( @@ -397,7 +397,7 @@ public void testInsertUsesWriterOnlyForValuesListOfPlaceholders(String parser, S properties.setProperty(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF); try (Connection connection = getJdbcConnection(properties)) { try (Statement stmt = connection.createStatement()) { - stmt.execute("CREATE TABLE " + table + " (a Int32, b Int32, c Nullable(Int32)) Engine MergeTree ORDER BY ()"); + stmt.execute("CREATE TABLE " + table + " (a Int32, b Int32, c Nullable(Int32)) ORDER BY ()"); } try { 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 54ab62e64..e6a469ff3 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 @@ -64,7 +64,7 @@ public void testGetColumns() throws Exception { stmt.executeUpdate("DROP TABLE IF EXISTS " + tableName); stmt.executeUpdate("" + "CREATE TABLE " + tableName + " (id Int32, name String NOT NULL, v1 Nullable(Int8), v2 Array(Int8)) " + - "ENGINE MergeTree ORDER BY tuple()"); + "ORDER BY tuple()"); } DatabaseMetaData dbmd = conn.getMetaData(); @@ -184,7 +184,7 @@ public void testGetColumnsWithBinaryStringSupport() throws Exception { stmt.executeUpdate("DROP TABLE IF EXISTS " + tableName); stmt.executeUpdate("CREATE TABLE " + tableName + " (id Int32, name String NOT NULL, v1 Nullable(Int8), v2 Array(Int8)) " + - "ENGINE MergeTree ORDER BY tuple()"); + "ORDER BY tuple()"); } DatabaseMetaData dbmd = conn.getMetaData(); @@ -240,7 +240,7 @@ public void testGetColumnsBFloat16() throws Exception { try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("DROP TABLE IF EXISTS " + tableName); stmt.executeUpdate("CREATE TABLE " + tableName - + " (id Int32, v BFloat16, vNull Nullable(BFloat16)) ENGINE MergeTree ORDER BY id"); + + " (id Int32, v BFloat16, vNull Nullable(BFloat16)) ORDER BY id"); } DatabaseMetaData dbmd = conn.getMetaData(); @@ -450,7 +450,7 @@ public void testGetColumnsWithTable() throws Exception { createTableStmt.append(columnNames.get(i)).append(" ").append(columnTypes.get(i)).append(','); } createTableStmt.setLength(createTableStmt.length() - 1); - createTableStmt.append(") ENGINE = MergeTree ORDER BY tuple()"); + createTableStmt.append(") ORDER BY tuple()"); conn.createStatement().execute(createTableStmt.toString()); DatabaseMetaData dbmd = conn.getMetaData(); @@ -695,7 +695,7 @@ private static void createQuotedNameFixture(Connection conn) throws SQLException try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("DROP DATABASE IF EXISTS `mdquotea'b`"); stmt.executeUpdate("CREATE DATABASE `mdquotea'b`"); - stmt.executeUpdate("CREATE TABLE `mdquotea'b`.`t'1` (id Int32, v String) ENGINE MergeTree ORDER BY id"); + stmt.executeUpdate("CREATE TABLE `mdquotea'b`.`t'1` (id Int32, v String) ORDER BY id"); } } @@ -1807,11 +1807,11 @@ public void testTableTypes() throws Exception { // Regular MergeTree table stmt.executeUpdate("DROP TABLE IF EXISTS test_table_types_regular"); - stmt.executeUpdate("CREATE TABLE test_table_types_regular (id Int32) ENGINE = MergeTree ORDER BY id"); + stmt.executeUpdate("CREATE TABLE test_table_types_regular (id Int32) ORDER BY id"); // Source table for views stmt.executeUpdate("DROP TABLE IF EXISTS test_table_types_source"); - stmt.executeUpdate("CREATE TABLE test_table_types_source (id Int32) ENGINE = MergeTree ORDER BY id"); + stmt.executeUpdate("CREATE TABLE test_table_types_source (id Int32) ORDER BY id"); // Normal view stmt.executeUpdate("DROP VIEW IF EXISTS test_table_types_view"); @@ -1819,7 +1819,7 @@ public void testTableTypes() throws Exception { // Materialized view stmt.executeUpdate("DROP VIEW IF EXISTS test_table_types_mat_view"); - stmt.executeUpdate("CREATE MATERIALIZED VIEW test_table_types_mat_view ENGINE = MergeTree ORDER BY id AS SELECT id FROM test_table_types_source"); + stmt.executeUpdate("CREATE MATERIALIZED VIEW test_table_types_mat_view ORDER BY id AS SELECT id FROM test_table_types_source"); // Remote table (URL engine has empty data_paths) stmt.executeUpdate("DROP TABLE IF EXISTS test_table_types_remote"); diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/ResultSetMetaDataImplTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/ResultSetMetaDataImplTest.java index 41313b357..81b50dbb0 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/ResultSetMetaDataImplTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/ResultSetMetaDataImplTest.java @@ -276,8 +276,8 @@ public void testColumnNamesStrippedFromTablePrefix() throws Exception { Statement stmt = conn.createStatement()) { stmt.executeUpdate("DROP TABLE IF EXISTS " + t1); stmt.executeUpdate("DROP TABLE IF EXISTS " + t2); - stmt.executeUpdate("CREATE TABLE " + t1 + " (id Int32, val String) ENGINE = MergeTree ORDER BY id"); - stmt.executeUpdate("CREATE TABLE " + t2 + " (id Int32, name String) ENGINE = MergeTree ORDER BY id"); + stmt.executeUpdate("CREATE TABLE " + t1 + " (id Int32, val String) ORDER BY id"); + stmt.executeUpdate("CREATE TABLE " + t2 + " (id Int32, name String) ORDER BY id"); stmt.executeUpdate("INSERT INTO " + t1 + " VALUES (1, 'test_val')"); stmt.executeUpdate("INSERT INTO " + t2 + " VALUES (1, 'test_name')"); diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/ShowStatementDatabaseMetaDataTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/ShowStatementDatabaseMetaDataTest.java index d0bf8f220..73674f3cb 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/ShowStatementDatabaseMetaDataTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/ShowStatementDatabaseMetaDataTest.java @@ -109,12 +109,12 @@ public void testShowStatementsReturnSameMetadataAsSystemTables(MetadataCall call "sa SimpleAggregateFunction(sum, UInt64), " + "nsa SimpleAggregateFunction(anyLast, Nullable(Decimal(9, 3))), " + "mat Int64 MATERIALIZED id * 2, al String ALIAS toString(id), eph Int32 EPHEMERAL" + - ") ENGINE = MergeTree ORDER BY id COMMENT 'table comment'"); + ") ORDER BY id COMMENT 'table comment'"); stmt.executeUpdate("CREATE VIEW " + SHOW_STATEMENTS_TABLE + "_view AS SELECT id, d FROM " + SHOW_STATEMENTS_TABLE); - stmt.executeUpdate("CREATE MATERIALIZED VIEW " + SHOW_STATEMENTS_TABLE + "_mv ENGINE = MergeTree ORDER BY id " + + stmt.executeUpdate("CREATE MATERIALIZED VIEW " + SHOW_STATEMENTS_TABLE + "_mv ORDER BY id " + "AS SELECT id, s FROM " + SHOW_STATEMENTS_TABLE); stmt.executeUpdate("CREATE TABLE " + quoteIdentifier(SHOW_STATEMENTS_ODD_TABLE) + " (id Int32, " + - quoteIdentifier("odd \"col\"?\\") + " String) ENGINE = MergeTree ORDER BY id"); + quoteIdentifier("odd \"col\"?\\") + " String) ORDER BY id"); } Properties systemTablesProps = new Properties(); @@ -181,7 +181,7 @@ public void testTableRemarksDependOnShowStatementsFlag(String flag, String expec try (Connection conn = flag == null ? getJdbcConnectionWithDefaultFlag() : getJdbcConnection(props)) { try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("DROP TABLE IF EXISTS " + tableName); - stmt.executeUpdate("CREATE TABLE " + tableName + " (id Int32) ENGINE = MergeTree ORDER BY id " + + stmt.executeUpdate("CREATE TABLE " + tableName + " (id Int32) ORDER BY id " + "COMMENT 'flag table comment'"); } try (ResultSet rs = conn.getMetaData().getTables(null, getDatabase(), tableName, null)) { @@ -217,9 +217,9 @@ public void testGetColumnsForReadonlyUserWithColumnGrants(String flag, List Date: Wed, 7 Oct 2026 10:44:38 -0700 Subject: [PATCH 6/7] Fix duplicate plugin problem --- packages/clickhouse-jdbc-all/pom.xml | 5 -- pom.xml | 108 +++++++-------------------- 2 files changed, 27 insertions(+), 86 deletions(-) diff --git a/packages/clickhouse-jdbc-all/pom.xml b/packages/clickhouse-jdbc-all/pom.xml index a8a7f2543..e610e4829 100644 --- a/packages/clickhouse-jdbc-all/pom.xml +++ b/packages/clickhouse-jdbc-all/pom.xml @@ -36,11 +36,6 @@ false - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 javadoc-jar diff --git a/pom.xml b/pom.xml index 13d0ac041..4e569bf91 100644 --- a/pom.xml +++ b/pom.xml @@ -629,6 +629,33 @@ org.apache.maven.plugins maven-resources-plugin + + org.apache.maven.plugins + maven-jar-plugin + + + default-jar + + + false + + true + true + true + + + true + ${project.url} + ClickHouse, Inc. + ${project.groupId} + + ${git.commit.id.full} + + + + + + @@ -859,33 +886,6 @@ io.github.git-commit-id git-commit-id-maven-plugin - - org.apache.maven.plugins - maven-jar-plugin - - - default-jar - - - false - - true - true - true - - - true - ${project.url} - ClickHouse, Inc. - ${project.groupId} - - ${git.commit.id.full} - - - - - - org.apache.maven.plugins maven-source-plugin @@ -1012,33 +1012,6 @@ ${failsafeArgLine} - - org.apache.maven.plugins - maven-jar-plugin - - - default-jar - - - false - - true - true - true - - - true - ${project.url} - ClickHouse, Inc. - ${project.groupId} - - ${git.commit.id.full} - - - - - - @@ -1094,33 +1067,6 @@ io.github.git-commit-id git-commit-id-maven-plugin - - org.apache.maven.plugins - maven-jar-plugin - - - default-jar - - - false - - true - true - true - - - true - ${project.url} - ClickHouse, Inc. - ${project.groupId} - - ${git.commit.id.full} - - - - - - org.apache.maven.plugins maven-javadoc-plugin From 2b635d123ae1609d4f7227aaec72a656951ef23a Mon Sep 17 00:00:00 2001 From: Sergey Chernov Date: Wed, 7 Oct 2026 10:57:01 -0700 Subject: [PATCH 7/7] fixed example build --- examples/client-v2/pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/examples/client-v2/pom.xml b/examples/client-v2/pom.xml index 4172df108..c63f0cdeb 100644 --- a/examples/client-v2/pom.xml +++ b/examples/client-v2/pom.xml @@ -79,7 +79,6 @@ com.fasterxml.jackson.core jackson-databind - test 2.18.11 @@ -121,12 +120,6 @@ 2.0.13 runtime - - com.fasterxml.jackson.core - jackson-databind - 2.18.11 - compile -