Search in sources :

Example 66 with IAE

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

the class ExprEval method ofType.

public static ExprEval ofType(@Nullable ExpressionType type, @Nullable Object value) {
    if (type == null) {
        return bestEffortOf(value);
    }
    switch(type.getType()) {
        case STRING:
            // not all who claim to be "STRING" are always a String, prepare ourselves...
            if (value instanceof String[]) {
                return new ArrayExprEval(ExpressionType.STRING_ARRAY, (String[]) value);
            }
            if (value instanceof Object[]) {
                return new ArrayExprEval(ExpressionType.STRING_ARRAY, (Object[]) value);
            }
            if (value instanceof List) {
                return bestEffortOf(value);
            }
            if (value == null) {
                return of(null);
            }
            return of(String.valueOf(value));
        case LONG:
            if (value instanceof Number) {
                return ofLong((Number) value);
            }
            if (value instanceof String) {
                return ofLong(ExprEval.computeNumber((String) value));
            }
            return ofLong(null);
        case DOUBLE:
            if (value instanceof Number) {
                return ofDouble((Number) value);
            }
            if (value instanceof String) {
                return ofDouble(ExprEval.computeNumber((String) value));
            }
            return ofDouble(null);
        case COMPLEX:
            byte[] bytes = null;
            if (value instanceof String) {
                bytes = StringUtils.decodeBase64String((String) value);
            } else if (value instanceof byte[]) {
                bytes = (byte[]) value;
            }
            if (bytes != null) {
                TypeStrategy<?> strategy = type.getStrategy();
                assert strategy != null;
                ByteBuffer bb = ByteBuffer.wrap(bytes);
                return ofComplex(type, strategy.read(bb));
            }
            return ofComplex(type, value);
        case ARRAY:
            if (value instanceof Object[]) {
                return ofArray(type, (Object[]) value);
            }
            // e.g. we might get a String instead of String[], so just fallback to bestEffortOf
            return bestEffortOf(value);
    }
    throw new IAE("Cannot create type [%s]", type);
}
Also used : List(java.util.List) IAE(org.apache.druid.java.util.common.IAE) ByteBuffer(java.nio.ByteBuffer)

Example 67 with IAE

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

the class MaterializedViewSupervisor method reset.

@Override
public void reset(DataSourceMetadata dataSourceMetadata) {
    if (dataSourceMetadata == null) {
        // if oldMetadata is different from spec, tasks and segments will be removed when reset.
        DataSourceMetadata oldMetadata = metadataStorageCoordinator.retrieveDataSourceMetadata(dataSource);
        if (oldMetadata instanceof DerivativeDataSourceMetadata) {
            if (!((DerivativeDataSourceMetadata) oldMetadata).getBaseDataSource().equals(spec.getBaseDataSource()) || !((DerivativeDataSourceMetadata) oldMetadata).getDimensions().equals(spec.getDimensions()) || !((DerivativeDataSourceMetadata) oldMetadata).getMetrics().equals(spec.getMetrics())) {
                synchronized (taskLock) {
                    clearTasks();
                    clearSegments();
                }
            }
        }
        commitDataSourceMetadata(new DerivativeDataSourceMetadata(spec.getBaseDataSource(), spec.getDimensions(), spec.getMetrics()));
    } else {
        throw new IAE("DerivedDataSourceMetadata is not allowed to reset to a new DerivedDataSourceMetadata");
    }
}
Also used : DataSourceMetadata(org.apache.druid.indexing.overlord.DataSourceMetadata) IAE(org.apache.druid.java.util.common.IAE)

Example 68 with IAE

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

the class RangeBitmapBenchmark method setup.

@Setup(Level.Trial)
public void setup() throws IOException {
    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();
        int k = 0;
        boolean fill = true;
        while (k < bitmapLength) {
            int runLength = (int) (bitmapLength * density) + RANDOM.nextInt((int) (bitmapLength * density));
            for (int j = k; fill && j < bitmapLength && j < k + runLength; ++j) {
                mutableBitmap.add(j);
            }
            k += runLength;
            fill = !fill;
        }
        for (k = bitmapLength / 2; k < bitmapLength / 2 + minIntersect; ++k) {
            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 69 with IAE

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

the class BasicRoleBasedAuthorizer method authorize.

@Override
@SuppressWarnings("unchecked")
public Access authorize(AuthenticationResult authenticationResult, Resource resource, Action action) {
    if (authenticationResult == null) {
        throw new IAE("authenticationResult is null where it should never be.");
    }
    Set<String> roleNames = new HashSet<>(roleProvider.getRoles(name, authenticationResult));
    Map<String, BasicAuthorizerRole> roleMap = roleProvider.getRoleMap(name);
    if (roleNames.isEmpty()) {
        return new Access(false);
    }
    if (roleMap == null) {
        throw new IAE("Could not load roleMap for authorizer [%s]", name);
    }
    for (String roleName : roleNames) {
        BasicAuthorizerRole role = roleMap.get(roleName);
        if (role != null) {
            for (BasicAuthorizerPermission permission : role.getPermissions()) {
                if (permissionCheck(resource, action, permission)) {
                    return new Access(true);
                }
            }
        }
    }
    return new Access(false);
}
Also used : Access(org.apache.druid.server.security.Access) BasicAuthorizerRole(org.apache.druid.security.basic.authorization.entity.BasicAuthorizerRole) IAE(org.apache.druid.java.util.common.IAE) BasicAuthorizerPermission(org.apache.druid.security.basic.authorization.entity.BasicAuthorizerPermission) HashSet(java.util.HashSet)

Example 70 with IAE

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

the class UriCacheGenerator method generateCache.

@Override
@Nullable
public CacheScheduler.VersionedCache generateCache(final UriExtractionNamespace extractionNamespace, final CacheScheduler.EntryImpl<UriExtractionNamespace> entryId, @Nullable final String lastVersion, final CacheScheduler scheduler) throws Exception {
    final boolean doSearch = extractionNamespace.getUriPrefix() != null;
    final URI originalUri = doSearch ? extractionNamespace.getUriPrefix() : extractionNamespace.getUri();
    final SearchableVersionedDataFinder<URI> pullerRaw = pullers.get(originalUri.getScheme());
    if (pullerRaw == null) {
        throw new IAE("Unknown loader type[%s].  Known types are %s", originalUri.getScheme(), pullers.keySet());
    }
    if (!(pullerRaw instanceof URIDataPuller)) {
        throw new IAE("Cannot load data from location [%s]. Data pulling from [%s] not supported", originalUri, originalUri.getScheme());
    }
    final URIDataPuller puller = (URIDataPuller) pullerRaw;
    final URI uri;
    if (doSearch) {
        final Pattern versionRegex;
        if (extractionNamespace.getFileRegex() != null) {
            versionRegex = Pattern.compile(extractionNamespace.getFileRegex());
        } else {
            versionRegex = null;
        }
        uri = pullerRaw.getLatestVersion(extractionNamespace.getUriPrefix(), versionRegex);
        if (uri == null) {
            throw new FileNotFoundException(StringUtils.format("Could not find match for pattern `%s` in [%s] for %s", versionRegex, originalUri, extractionNamespace));
        }
    } else {
        uri = extractionNamespace.getUri();
    }
    return RetryUtils.retry(() -> {
        final String version = puller.getVersion(uri);
        try {
            // Important to call equals() against version because lastVersion could be null
            if (version.equals(lastVersion)) {
                log.debug("URI [%s] for [%s] has the same last modified time [%s] as the last cached. " + "Skipping ", uri.toString(), entryId, version);
                return null;
            }
        } catch (NumberFormatException ex) {
            log.debug(ex, "Failed to get last modified timestamp. Assuming no timestamp");
        }
        final ByteSource source = new ByteSource() {

            @Override
            public InputStream openStream() throws IOException {
                return CompressionUtils.decompress(puller.getInputStream(uri), uri.getPath());
            }
        };
        final CacheScheduler.VersionedCache versionedCache = scheduler.createVersionedCache(entryId, version);
        try {
            final long startNs = System.nanoTime();
            final MapPopulator.PopulateResult populateResult = new MapPopulator<>(extractionNamespace.getNamespaceParseSpec().getParser()).populateAndWarnAtByteLimit(source, versionedCache.getCache(), (long) (MAX_MEMORY * extractionNamespace.getMaxHeapPercentage() / 100.0), null == entryId ? null : entryId.toString());
            final long duration = System.nanoTime() - startNs;
            log.info("Finished loading %,d values (%d bytes) from %,d lines for [%s] in %,d ns", populateResult.getEntries(), populateResult.getBytes(), populateResult.getLines(), entryId, duration);
            return versionedCache;
        } catch (Throwable t) {
            try {
                versionedCache.close();
            } catch (Exception e) {
                t.addSuppressed(e);
            }
            throw t;
        }
    }, puller.shouldRetryPredicate(), DEFAULT_NUM_RETRIES);
}
Also used : Pattern(java.util.regex.Pattern) FileNotFoundException(java.io.FileNotFoundException) IAE(org.apache.druid.java.util.common.IAE) URI(java.net.URI) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) URIDataPuller(org.apache.druid.segment.loading.URIDataPuller) ByteSource(com.google.common.io.ByteSource) CacheScheduler(org.apache.druid.server.lookup.namespace.cache.CacheScheduler) MapPopulator(org.apache.druid.data.input.MapPopulator) Nullable(javax.annotation.Nullable)

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