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