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;
}
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);
}
}
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);
}
}
}
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;
}
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());
}
}
Aggregations