Search in sources :

Example 56 with IAE

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);
}
Also used : BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Measurement(org.openjdk.jmh.annotations.Measurement) Blackhole(org.openjdk.jmh.infra.Blackhole) Scope(org.openjdk.jmh.annotations.Scope) Random(java.util.Random) ImmutableBitmap(org.apache.druid.collections.bitmap.ImmutableBitmap) Warmup(org.openjdk.jmh.annotations.Warmup) ArrayList(java.util.ArrayList) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit) BitmapFactory(org.apache.druid.collections.bitmap.BitmapFactory) IAE(org.apache.druid.java.util.common.IAE) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) Setup(org.openjdk.jmh.annotations.Setup) Mode(org.openjdk.jmh.annotations.Mode) Param(org.openjdk.jmh.annotations.Param) IOException(java.io.IOException) State(org.openjdk.jmh.annotations.State) ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) Benchmark(org.openjdk.jmh.annotations.Benchmark) RoaringBitmapFactory(org.apache.druid.collections.bitmap.RoaringBitmapFactory) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) NullHandling(org.apache.druid.common.config.NullHandling) Level(org.openjdk.jmh.annotations.Level) Fork(org.openjdk.jmh.annotations.Fork) ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) IAE(org.apache.druid.java.util.common.IAE) RoaringBitmapFactory(org.apache.druid.collections.bitmap.RoaringBitmapFactory) Setup(org.openjdk.jmh.annotations.Setup)

Example 57 with IAE

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;
}
Also used : Field(java.lang.reflect.Field) Method(java.lang.reflect.Method) IAE(org.apache.druid.java.util.common.IAE) Properties(java.util.Properties)

Example 58 with IAE

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;
}
Also used : Field(java.lang.reflect.Field) Method(java.lang.reflect.Method) IAE(org.apache.druid.java.util.common.IAE) Properties(java.util.Properties)

Example 59 with IAE

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;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) IAE(org.apache.druid.java.util.common.IAE)

Example 60 with IAE

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;
}
Also used : Method(java.lang.reflect.Method) Properties(java.util.Properties) 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