Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Custom properties are lost when using getConnection(username,password) #978

Closed
piotrp opened this issue Jul 3, 2022 · 1 comment
Closed
Labels
Milestone

Comments

@piotrp
Copy link

piotrp commented Jul 3, 2022

Passing of custom properties is broken when using JDBC Driver's DataSource#getConnection(username,password) method (it works when using DataSource#getConnection()).

Verified with test suite pasted below, second test fails - I get ClickHouse Java Client instead of Agent #1. Verified on:

  • 0.3.2-patch10 - test fails
  • 0.3.2-patch9 - test fails
  • 0.3.2-patch5 - test fails
  • 0.3.2 - test fails
package pl.coretech.cdn;

import com.clickhouse.jdbc.ClickHouseConnection;
import com.clickhouse.jdbc.ClickHouseDataSource;
import com.clickhouse.jdbc.ClickHouseDriver;
import org.junit.jupiter.api.Test;

import java.sql.SQLException;
import java.util.Properties;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ConnectionTests {
    private final static String URL = "jdbc:clickhouse://localhost:18123/";
    private final static String USERNAME = "default";
    private final static String PASSWORD = "";
    private final static String CLIENT_NAME = "Agent #1";

    static {
        System.out.println(ClickHouseDriver.class.getPackage().getImplementationVersion());
    }

    @Test
    void testDriver1() throws SQLException {
        var properties = new Properties();
        properties.setProperty("user", USERNAME);
        properties.setProperty("password", PASSWORD);
        properties.setProperty("client_name", CLIENT_NAME);
        var dataSource = new ClickHouseDataSource(URL, properties);
        try (var conn = dataSource.getConnection()) {
            assertEquals(CLIENT_NAME, conn.getClientInfo(ClickHouseConnection.PROP_APPLICATION_NAME));
        }
    }

    @Test
    void testDriver2() throws SQLException {
        var properties = new Properties();
        properties.setProperty("client_name", CLIENT_NAME);
        var dataSource = new ClickHouseDataSource(URL, properties);
        try (var conn = dataSource.getConnection(USERNAME, PASSWORD)) {
            assertEquals(CLIENT_NAME, conn.getClientInfo(ClickHouseConnection.PROP_APPLICATION_NAME));
        }
    }
}
@piotrp piotrp changed the title Custom properties don't work with getConnection(username,password) API Custom properties are lost when using getConnection(username,password) Jul 3, 2022
@zhicwu zhicwu added the bug label Jul 3, 2022
@zhicwu zhicwu added this to the 0.3.3 release milestone Jul 3, 2022
@zhicwu
Copy link
Contributor

zhicwu commented Jul 3, 2022

Thanks for reporting, and providing code to reproduce the issue.

We should change below line to Properties props = new Properties(); props.putAll(connInfo.getProperties());, because we're not setting default properties.

/~https://github.com/ClickHouse/clickhouse-jdbc/blob/ea5aaf579b0612bcf1825eb1ec31bf9b170a7a65/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDataSource.java#L54

Update: above change does not solve all problems. Properties will be cached and additional parsing should be avoided when username and password is same as the one specified in URL / Connection Properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants