Search in sources :

Example 61 with IAE

use of org.apache.druid.java.util.common.IAE in project druid by druid-io.

the class ConnectionUriUtils method tryParseMySqlConnectionUri.

public static Set<String> tryParseMySqlConnectionUri(String connectionUri) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
    Class<?> driverClass = Class.forName(MYSQL_NON_REGISTERING_DRIVER);
    Method parseUrl = driverClass.getMethod("parseURL", String.class, Properties.class);
    // almost the same as postgres, but is an instance level method
    Properties properties = (Properties) parseUrl.invoke(driverClass.getConstructor().newInstance(), connectionUri, null);
    if (properties == null) {
        throw new IAE("Invalid URL format for MySQL: [%s]", connectionUri);
    }
    Set<String> keys = Sets.newHashSetWithExpectedSize(properties.size());
    properties.forEach((k, v) -> keys.add((String) k));
    return keys;
}
Also used : Method(java.lang.reflect.Method) Properties(java.util.Properties) IAE(org.apache.druid.java.util.common.IAE)

Example 62 with IAE

use of org.apache.druid.java.util.common.IAE in project druid by druid-io.

the class RedisCacheFactory method create.

public static Cache create(final RedisCacheConfig config) {
    if (config.getCluster() != null && StringUtils.isNotBlank(config.getCluster().getNodes())) {
        Set<HostAndPort> nodes = Arrays.stream(config.getCluster().getNodes().split(",")).map(String::trim).filter(StringUtils::isNotBlank).map(hostAndPort -> {
            int index = hostAndPort.indexOf(':');
            if (index <= 0 || index == hostAndPort.length()) {
                throw new IAE("Invalid redis cluster configuration: %s", hostAndPort);
            }
            int port;
            try {
                port = Integer.parseInt(hostAndPort.substring(index + 1));
            } catch (NumberFormatException e) {
                throw new IAE("Invalid port in %s", hostAndPort);
            }
            if (port <= 0 || port > 65535) {
                throw new IAE("Invalid port in %s", hostAndPort);
            }
            return new HostAndPort(hostAndPort.substring(0, index), port);
        }).collect(Collectors.toSet());
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(config.getMaxTotalConnections());
        poolConfig.setMaxIdle(config.getMaxIdleConnections());
        poolConfig.setMinIdle(config.getMinIdleConnections());
        JedisCluster cluster;
        if (config.getPassword() != null) {
            cluster = new JedisCluster(nodes, // connection timeout
            config.getTimeout().getMillisecondsAsInt(), // read timeout
            config.getTimeout().getMillisecondsAsInt(), config.getCluster().getMaxRedirection(), config.getPassword().getPassword(), poolConfig);
        } else {
            cluster = new JedisCluster(nodes, // connection timeout and read timeout
            config.getTimeout().getMillisecondsAsInt(), config.getCluster().getMaxRedirection(), poolConfig);
        }
        return new RedisClusterCache(cluster, config);
    } else {
        if (StringUtils.isBlank(config.getHost())) {
            throw new IAE("Invalid redis configuration. no redis server or cluster configured.");
        }
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(config.getMaxTotalConnections());
        poolConfig.setMaxIdle(config.getMaxIdleConnections());
        poolConfig.setMinIdle(config.getMinIdleConnections());
        return new RedisStandaloneCache(new JedisPool(poolConfig, config.getHost(), config.getPort(), // connection timeout and read timeout
        config.getTimeout().getMillisecondsAsInt(), config.getPassword() == null ? null : config.getPassword().getPassword(), config.getDatabase(), null), config);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) HostAndPort(redis.clients.jedis.HostAndPort) JedisCluster(redis.clients.jedis.JedisCluster) Set(java.util.Set) JedisPool(redis.clients.jedis.JedisPool) IAE(org.apache.druid.java.util.common.IAE) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Collectors(java.util.stream.Collectors) HostAndPort(redis.clients.jedis.HostAndPort) StringUtils(org.apache.commons.lang.StringUtils) JedisCluster(redis.clients.jedis.JedisCluster) JedisPool(redis.clients.jedis.JedisPool) IAE(org.apache.druid.java.util.common.IAE) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Example 63 with IAE

use of org.apache.druid.java.util.common.IAE in project druid by druid-io.

the class IdUtils method validateId.

public static void validateId(String thingToValidate, String stringToValidate) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(stringToValidate), "%s cannot be null or empty. Please provide a %s.", thingToValidate, thingToValidate);
    Preconditions.checkArgument(!stringToValidate.startsWith("."), "%s cannot start with the '.' character.", thingToValidate);
    Preconditions.checkArgument(!stringToValidate.contains("/"), "%s cannot contain the '/' character.", thingToValidate);
    Matcher m = INVALIDCHARS.matcher(stringToValidate);
    Preconditions.checkArgument(!m.matches(), "%s cannot contain whitespace character except space.", thingToValidate);
    for (int i = 0; i < stringToValidate.length(); i++) {
        final char c = stringToValidate.charAt(i);
        // pairs. This means that characters outside the basic multilingual plane, such as emojis, are not allowed. 😢
        if (c > 0 && c < 31 || c > 127 && c < 159 || c > '\ud800' && c < '\uf8ff' || c > '\ufff0' && c < '\uffff') {
            throw new IAE("%s cannot contain character #%d (at position %d).", thingToValidate, (int) c, i);
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) IAE(org.apache.druid.java.util.common.IAE)

Example 64 with IAE

use of org.apache.druid.java.util.common.IAE in project druid by druid-io.

the class ExpressionTypeFactory method getTypeStrategy.

@Override
public <T> TypeStrategy<T> getTypeStrategy(ExpressionType expressionType) {
    final TypeStrategy strategy;
    switch(expressionType.getType()) {
        case LONG:
            strategy = TypeStrategies.LONG;
            break;
        case DOUBLE:
            strategy = TypeStrategies.DOUBLE;
            break;
        case STRING:
            strategy = TypeStrategies.STRING;
            break;
        case ARRAY:
            strategy = new TypeStrategies.ArrayTypeStrategy(expressionType);
            break;
        case COMPLEX:
            TypeStrategy<?> complexStrategy = TypeStrategies.getComplex(expressionType.getComplexTypeName());
            if (complexStrategy == null) {
                throw new IAE("Cannot find strategy for type [%s]", expressionType.asTypeString());
            }
            strategy = complexStrategy;
            break;
        default:
            throw new ISE("Unsupported column type[%s]", expressionType.getType());
    }
    return strategy;
}
Also used : TypeStrategy(org.apache.druid.segment.column.TypeStrategy) TypeStrategies(org.apache.druid.segment.column.TypeStrategies) ISE(org.apache.druid.java.util.common.ISE) IAE(org.apache.druid.java.util.common.IAE)

Example 65 with IAE

use of org.apache.druid.java.util.common.IAE in project druid by druid-io.

the class TDigestSketchBufferAggregator method aggregate.

@Override
public void aggregate(ByteBuffer buffer, int position) {
    Object x = selector.getObject();
    if (x == null) {
        return;
    }
    MergingDigest sketch = sketchCache.get(buffer).get(position);
    if (x instanceof Number) {
        sketch.add(((Number) x).doubleValue());
    } else if (x instanceof MergingDigest) {
        sketch.add((MergingDigest) x);
    } else {
        throw new IAE("Expected a number or an instance of MergingDigest, but received [%s] of type [%s]", x, x.getClass());
    }
}
Also used : MergingDigest(com.tdunning.math.stats.MergingDigest) IAE(org.apache.druid.java.util.common.IAE)

Aggregations

IAE (org.apache.druid.java.util.common.IAE)115 ISE (org.apache.druid.java.util.common.ISE)23 IOException (java.io.IOException)20 ByteBuffer (java.nio.ByteBuffer)19 ArrayList (java.util.ArrayList)16 List (java.util.List)14 Expr (org.apache.druid.math.expr.Expr)14 Nullable (javax.annotation.Nullable)12 ColumnType (org.apache.druid.segment.column.ColumnType)10 HashSet (java.util.HashSet)8 Map (java.util.Map)8 Interval (org.joda.time.Interval)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 HashMap (java.util.HashMap)7 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)7 File (java.io.File)6 Iterables (com.google.common.collect.Iterables)5 Arrays (java.util.Arrays)5 Test (org.junit.Test)5 ImmutableMap (com.google.common.collect.ImmutableMap)4