ru.yandex.clickhouse.util.apache.StringUtils Java Examples

The following examples show how to use ru.yandex.clickhouse.util.apache.StringUtils. 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: ClickhouseClientHolder.java    From clickhouse-hdfs-loader with MIT License 5 votes vote down vote up
public static synchronized ClickhouseClient getClickhouseClient(String host, int port, String database, String username, String password) throws SQLException {
    if(StringUtils.isBlank(username) || StringUtils.isBlank(password)){
        return getClickhouseClient(host, port, database);
    }
    String key = "jdbc:clickhouse://"+username+":"+password+"@"+host+":"+port+"/"+database;
    if(!clientHolders.containsKey(key)){
        clientHolders.put(key, new ClickhouseClient(host, port, database, username, password));
    }
    return clientHolders.get(key);
}
 
Example #2
Source File: ClickhouseClientHolder.java    From clickhouse-hdfs-loader with MIT License 5 votes vote down vote up
public static synchronized ClickhouseClient getClickhouseClient(String connectionUrl, String username, String password) throws SQLException {
    log.info("Clickhouse Loader : get clickhouse client["+connectionUrl+"] for user="+username);
    if(StringUtils.isBlank(username) || StringUtils.isBlank(password)){
        return getClickhouseClient(connectionUrl);
    }
    Matcher m = CLICKHOUSE_CONNECT_PATTERN.matcher(connectionUrl);
    if(!m.matches()){
        throw new IllegalArgumentException("Cannot parse jdbc connect : "+connectionUrl);
    }
    String key = "jdbc:clickhouse://"+username+":"+password+"@"+m.group(1)+":"+m.group(2)+"/"+m.group(3);
    if(!clientHolders.containsKey(key)){
        clientHolders.put(key, new ClickhouseClient(connectionUrl, username, password));
    }
    return clientHolders.get(key);
}
 
Example #3
Source File: BalancedClickhouseDataSource.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
private static Properties getFromUrlWithoutDefault(String url) {
    if (StringUtils.isBlank(url))
        return new Properties();

    int index = url.indexOf("?");
    if (index == -1)
        return new Properties();

    return ClickhouseJdbcUrlParser.parseUriQueryPart(url.substring(index + 1), new Properties());
}
 
Example #4
Source File: PreparedStatementParser.java    From clickhouse-jdbc with Apache License 2.0 5 votes vote down vote up
static PreparedStatementParser parse(String sql) {
    if (StringUtils.isBlank(sql)) {
        throw new IllegalArgumentException("SQL may not be blank");
    }
    PreparedStatementParser parser = new PreparedStatementParser();
    parser.parseSQL(sql);
    return parser;
}
 
Example #5
Source File: JdbcBridge.java    From clickhouse-jdbc-bridge with Apache License 2.0 4 votes vote down vote up
public Path getDriverPath() {
    return StringUtils.isBlank(driverPath) ? null : Paths.get(driverPath);
}
 
Example #6
Source File: ClickHouseProperties.java    From clickhouse-jdbc with Apache License 2.0 4 votes vote down vote up
public Map<ClickHouseQueryParam, String> buildQueryParams(boolean ignoreDatabase){
    Map<ClickHouseQueryParam, String> params = new HashMap<ClickHouseQueryParam, String>();

    if (maxParallelReplicas != null) params.put(ClickHouseQueryParam.MAX_PARALLEL_REPLICAS, String.valueOf(maxParallelReplicas));
    if (maxPartitionsPerInsertBlock != null) params.put(ClickHouseQueryParam.MAX_PARTITIONS_PER_INSERT_BLOCK, String.valueOf(maxPartitionsPerInsertBlock));
    if (maxRowsToGroupBy != null) params.put(ClickHouseQueryParam.MAX_ROWS_TO_GROUP_BY, String.valueOf(maxRowsToGroupBy));
    if (totalsMode != null) params.put(ClickHouseQueryParam.TOTALS_MODE, totalsMode);
    if (quotaKey != null) params.put(ClickHouseQueryParam.QUOTA_KEY, quotaKey);
    if (priority != null) params.put(ClickHouseQueryParam.PRIORITY, String.valueOf(priority));

    if (!StringUtils.isBlank(database) && !ignoreDatabase) params.put(ClickHouseQueryParam.DATABASE, getDatabase());

    if (compress) params.put(ClickHouseQueryParam.COMPRESS, "1");
    if (decompress) params.put(ClickHouseQueryParam.DECOMPRESS, "1");


    if (extremes) params.put(ClickHouseQueryParam.EXTREMES, "1");

    if (StringUtils.isBlank(profile)) {
        if (getMaxThreads() != null) {
            params.put(ClickHouseQueryParam.MAX_THREADS, String.valueOf(maxThreads));
        }

        // in seconds there
        if (getMaxExecutionTime() != null) {
            params.put(ClickHouseQueryParam.MAX_EXECUTION_TIME, String.valueOf((maxExecutionTime)));
        }

        if (getMaxBlockSize() != null) {
            params.put(ClickHouseQueryParam.MAX_BLOCK_SIZE, String.valueOf(getMaxBlockSize()));
        }
    } else {
        params.put(ClickHouseQueryParam.PROFILE, profile);
    }

    if (user != null) params.put(ClickHouseQueryParam.USER, user);
    if (password != null) params.put(ClickHouseQueryParam.PASSWORD, password);

    if (distributedAggregationMemoryEfficient) params.put(ClickHouseQueryParam.DISTRIBUTED_AGGREGATION_MEMORY_EFFICIENT, "1");

    if (maxBytesBeforeExternalGroupBy != null) params.put(ClickHouseQueryParam.MAX_BYTES_BEFORE_EXTERNAL_GROUP_BY, String.valueOf(maxBytesBeforeExternalGroupBy));
    if (maxBytesBeforeExternalSort != null) params.put(ClickHouseQueryParam.MAX_BYTES_BEFORE_EXTERNAL_SORT, String.valueOf(maxBytesBeforeExternalSort));
    if (maxMemoryUsage != null) {
        params.put(ClickHouseQueryParam.MAX_MEMORY_USAGE, String.valueOf(maxMemoryUsage));
    }
    if (maxMemoryUsageForUser != null) {
        params.put(ClickHouseQueryParam.MAX_MEMORY_USAGE_FOR_USER, String.valueOf(maxMemoryUsageForUser));
    }
    if (maxMemoryUsageForAllQueries != null) {
        params.put(ClickHouseQueryParam.MAX_MEMORY_USAGE_FOR_ALL_QUERIES, String.valueOf(maxMemoryUsageForAllQueries));
    }
    if (preferredBlockSizeBytes != null) {
        params.put(ClickHouseQueryParam.PREFERRED_BLOCK_SIZE_BYTES, String.valueOf(preferredBlockSizeBytes));
    }
    if (maxQuerySize != null) {
        params.put(ClickHouseQueryParam.MAX_QUERY_SIZE, String.valueOf(maxQuerySize));
    }
    if (maxAstElements != null) {
        params.put(ClickHouseQueryParam.MAX_AST_ELEMENTS, String.valueOf(maxAstElements));
    }

    if (sessionCheck) {
        params.put(ClickHouseQueryParam.SESSION_CHECK, "1");
    }

    if (sessionId != null) {
        params.put(ClickHouseQueryParam.SESSION_ID, String.valueOf(sessionId));
    }

    if (sessionTimeout != null) {
        params.put(ClickHouseQueryParam.SESSION_TIMEOUT, String.valueOf(sessionTimeout));
    }

    addQueryParam(insertQuorum, ClickHouseQueryParam.INSERT_QUORUM, params);
    addQueryParam(insertQuorumTimeout, ClickHouseQueryParam.INSERT_QUORUM_TIMEOUT, params);
    addQueryParam(selectSequentialConsistency, ClickHouseQueryParam.SELECT_SEQUENTIAL_CONSISTENCY, params);
    addQueryParam(maxInsertBlockSize, ClickHouseQueryParam.MAX_INSERT_BLOCK_SIZE, params);
    addQueryParam(insertDeduplicate, ClickHouseQueryParam.INSERT_DEDUPLICATE, params);
    addQueryParam(insertDistributedSync, ClickHouseQueryParam.INSERT_DISTRIBUTED_SYNC, params);
    addQueryParam(anyJoinDistinctRightTableKeys, ClickHouseQueryParam.ANY_JOIN_DISTINCT_RIGHT_TABLE_KEYS, params);

    if (enableOptimizePredicateExpression != null) {
        params.put(ClickHouseQueryParam.ENABLE_OPTIMIZE_PREDICATE_EXPRESSION, enableOptimizePredicateExpression ? "1" : "0");
    }

    return params;
}