use of org.apache.druid.java.util.common.IAE in project druid by druid-io.
the class UniformBitmapBenchmark method setup.
@Setup(Level.Trial)
public void setup() throws IOException {
final int[] knownTrue = new int[minIntersect];
for (int i = 0; i < knownTrue.length; ++i) {
knownTrue[i] = RANDOM.nextInt(bitmapLength);
}
switch(type) {
case "concise":
bitmapFactory = new ConciseBitmapFactory();
break;
case "roaring":
bitmapFactory = new RoaringBitmapFactory();
break;
default:
throw new IAE("Unknown bitmap type[%s]", type);
}
bitmaps = new ArrayList<>(numBitmaps);
for (int i = 0; i < numBitmaps; ++i) {
final MutableBitmap mutableBitmap = bitmapFactory.makeEmptyMutableBitmap();
for (int k = 0; k < bitmapLength; ++k) {
if (RANDOM.nextDouble() < density) {
mutableBitmap.add(k);
}
}
for (int k : knownTrue) {
mutableBitmap.add(k);
}
bitmaps.add(BitmapBenchmarkUtils.toOffheap(bitmapFactory.makeImmutableBitmap(mutableBitmap)));
}
final long totalSizeBytes = bitmaps.stream().mapToLong(bitmap -> bitmap.toBytes().length).sum();
BitmapBenchmarkUtils.printSizeStats(type, density, bitmaps.size(), totalSizeBytes);
}
use of org.apache.druid.java.util.common.IAE in project druid by druid-io.
the class ConnectionUriUtils method tryParseMariaDb2xConnectionUri.
public static Set<String> tryParseMariaDb2xConnectionUri(String connectionUri) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException, InstantiationException {
// these are a bit more complicated
Class<?> urlParserClass = Class.forName("org.mariadb.jdbc.UrlParser");
Class<?> optionsClass = Class.forName("org.mariadb.jdbc.util.Options");
Method parseUrl = urlParserClass.getMethod("parse", String.class);
Method getOptions = urlParserClass.getMethod("getOptions");
Object urlParser = parseUrl.invoke(null, connectionUri);
if (urlParser == null) {
throw new IAE("Invalid URL format for MariaDB: [%s]", connectionUri);
}
Object options = getOptions.invoke(urlParser);
Field nonMappedOptionsField = optionsClass.getField(MARIADB_EXTRAS);
Properties properties = (Properties) nonMappedOptionsField.get(options);
Field[] fields = optionsClass.getDeclaredFields();
Set<String> keys = Sets.newHashSetWithExpectedSize(properties.size() + fields.length);
properties.forEach((k, v) -> keys.add((String) k));
Object defaultOptions = optionsClass.getConstructor().newInstance();
for (Field field : fields) {
if (field.getName().equals(MARIADB_EXTRAS)) {
continue;
}
try {
if (!Objects.equal(field.get(options), field.get(defaultOptions))) {
keys.add(field.getName());
}
} catch (IllegalAccessException ignored) {
// ignore stuff we aren't allowed to read
}
}
return keys;
}
use of org.apache.druid.java.util.common.IAE in project druid by druid-io.
the class ConnectionUriUtils method tryParseMariaDb3xConnectionUri.
public static Set<String> tryParseMariaDb3xConnectionUri(String connectionUri) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
Class<?> configurationClass = Class.forName("org.mariadb.jdbc.Configuration");
Class<?> configurationBuilderClass = Class.forName("org.mariadb.jdbc.Configuration$Builder");
Method parseUrl = configurationClass.getMethod("parse", String.class);
Method buildMethod = configurationBuilderClass.getMethod("build");
Object configuration = parseUrl.invoke(null, connectionUri);
if (configuration == null) {
throw new IAE("Invalid URL format for MariaDB: [%s]", connectionUri);
}
Method nonMappedOptionsGetter = configurationClass.getMethod(MARIADB_EXTRAS);
Properties properties = (Properties) nonMappedOptionsGetter.invoke(configuration);
Field[] fields = configurationClass.getDeclaredFields();
Set<String> keys = Sets.newHashSetWithExpectedSize(properties.size() + fields.length);
properties.forEach((k, v) -> keys.add((String) k));
Object defaultConfiguration = buildMethod.invoke(configurationBuilderClass.getConstructor().newInstance());
for (Field field : fields) {
if (field.getName().equals(MARIADB_EXTRAS)) {
continue;
}
try {
final Method fieldGetter = configurationClass.getMethod(field.getName());
if (!Objects.equal(fieldGetter.invoke(configuration), fieldGetter.invoke(defaultConfiguration))) {
keys.add(field.getName());
}
} catch (IllegalAccessException | NoSuchMethodException ignored) {
// ignore stuff we aren't allowed to read
}
}
return keys;
}
use of org.apache.druid.java.util.common.IAE in project druid by druid-io.
the class Granularity method getDateValues.
// Used by the toDate implementations.
final Integer[] getDateValues(String filePath, Formatter formatter) {
Pattern pattern = DEFAULT_PATH_PATTERN;
switch(formatter) {
case DEFAULT:
case LOWER_DEFAULT:
break;
case HIVE:
pattern = HIVE_PATH_PATTERN;
break;
default:
throw new IAE("Format %s not supported", formatter);
}
Matcher matcher = pattern.matcher(filePath);
// The size is "7" b/c this array contains standard
// datetime field values namely:
// year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute,
// and index 0 is unused.
Integer[] vals = new Integer[7];
if (matcher.matches()) {
for (int i = 1; i <= matcher.groupCount(); i++) {
vals[i] = (matcher.group(i) != null) ? Integer.parseInt(matcher.group(i)) : null;
}
}
return vals;
}
use of org.apache.druid.java.util.common.IAE in project druid by druid-io.
the class ConnectionUriUtils method tryParsePostgresConnectionUri.
public static Set<String> tryParsePostgresConnectionUri(String connectionUri) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class<?> driverClass = Class.forName(POSTGRES_DRIVER);
Method parseUrl = driverClass.getMethod("parseURL", String.class, Properties.class);
Properties properties = (Properties) parseUrl.invoke(null, connectionUri, null);
if (properties == null) {
throw new IAE("Invalid URL format for PostgreSQL: [%s]", connectionUri);
}
Set<String> keys = Sets.newHashSetWithExpectedSize(properties.size());
properties.forEach((k, v) -> keys.add((String) k));
return keys;
}
Aggregations