Java Code Examples for ru.yandex.clickhouse.settings.ClickHouseProperties#setPath()

The following examples show how to use ru.yandex.clickhouse.settings.ClickHouseProperties#setPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClickhouseJdbcUrlParser.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
private static ClickHouseProperties parseClickhouseUrl(String uriString, Properties defaults)
        throws URISyntaxException
{
    URI uri = new URI(uriString);
    Properties urlProperties = parseUriQueryPart(uri.getQuery(), defaults);
    ClickHouseProperties props = new ClickHouseProperties(urlProperties);
    props.setHost(uri.getHost());
    int port = uri.getPort();
    if (port == -1) {
        throw new IllegalArgumentException("port is missed or wrong");
    }
    props.setPort(port);
    String path = uri.getPath();
    String database;
    if (props.isUsePathAsDb()) {
        if (path == null || path.isEmpty() || path.equals("/")) {
            String defaultsDb = defaults.getProperty(ClickHouseQueryParam.DATABASE.getKey());
            database = defaultsDb == null ? DEFAULT_DATABASE : defaultsDb;
        } else {
            Matcher m = DB_PATH_PATTERN.matcher(path);
            if (m.matches()) {
                database = m.group(1);
            } else {
                throw new URISyntaxException("wrong database name path: '" + path + "'", uriString);
            }
        }
        props.setDatabase(database);
    } else {
        if (props.getDatabase() == null || props.getDatabase().isEmpty()) {
            props.setDatabase(DEFAULT_DATABASE);
        }
        if (path == null || path.isEmpty()) {
            props.setPath("/");
        } else {
            props.setPath(path);
        }
    }
    return props;
}
 
Example 2
Source File: ClickhouseJdbcUrlParserTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testParsePathDefaultDb() throws Exception {
    ClickHouseProperties props = new ClickHouseProperties();
    props.setPath("/path");
    ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse(
        "jdbc:clickhouse://foo.yandex:1337/", props.asProperties());
    Assert.assertEquals(chProps.getDatabase(), "default");
    Assert.assertEquals(chProps.getPath(), "/path");
}
 
Example 3
Source File: ClickhouseJdbcUrlParserTest.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testParsePathDefaultDb2() throws Exception {
    ClickHouseProperties props = new ClickHouseProperties();
    props.setPath("/path");
    props.setUsePathAsDb(false);
    ClickHouseProperties chProps = ClickhouseJdbcUrlParser.parse(
        "jdbc:clickhouse://foo.yandex:1337", props.asProperties());
    Assert.assertEquals(chProps.getDatabase(), "default");
    Assert.assertEquals(chProps.getPath(), "/"); //uri takes priority
}