use of org.apache.druid.java.util.common.UOE in project druid by druid-io.
the class LocalDataSegmentPuller method buildFileObject.
public static FileObject buildFileObject(final URI uri) {
final Path path = Paths.get(uri);
final File file = path.toFile();
return new FileObject() {
@Override
public URI toUri() {
return uri;
}
@Override
public String getName() {
return path.getFileName().toString();
}
@Override
public InputStream openInputStream() throws IOException {
return new FileInputStream(file);
}
@Override
public OutputStream openOutputStream() throws IOException {
return new FileOutputStream(file);
}
@Override
public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
return Files.newReader(file, Charset.defaultCharset());
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
throw new UOE("CharSequence not supported");
}
@Override
public Writer openWriter() throws IOException {
return Files.newWriter(file, Charset.defaultCharset());
}
@Override
public long getLastModified() {
return file.lastModified();
}
@Override
public boolean delete() {
return file.delete();
}
};
}
use of org.apache.druid.java.util.common.UOE in project druid by druid-io.
the class NativeQueryMaker method runQuery.
@Override
public Sequence<Object[]> runQuery(final DruidQuery druidQuery) {
final Query<?> query = druidQuery.getQuery();
if (plannerContext.getPlannerConfig().isRequireTimeCondition() && !(druidQuery.getDataSource() instanceof InlineDataSource)) {
if (Intervals.ONLY_ETERNITY.equals(findBaseDataSourceIntervals(query))) {
throw new CannotBuildQueryException("requireTimeCondition is enabled, all queries must include a filter condition on the __time column");
}
}
int numFilters = plannerContext.getPlannerConfig().getMaxNumericInFilters();
// Instead of IN(v1,v2,v3) user should specify IN('v1','v2','v3')
if (numFilters != PlannerConfig.NUM_FILTER_NOT_USED) {
if (query.getFilter() instanceof OrDimFilter) {
OrDimFilter orDimFilter = (OrDimFilter) query.getFilter();
int numBoundFilters = 0;
for (DimFilter filter : orDimFilter.getFields()) {
numBoundFilters += filter instanceof BoundDimFilter ? 1 : 0;
}
if (numBoundFilters > numFilters) {
String dimension = ((BoundDimFilter) (orDimFilter.getFields().get(0))).getDimension();
throw new UOE(StringUtils.format("The number of values in the IN clause for [%s] in query exceeds configured maxNumericFilter limit of [%s] for INs. Cast [%s] values of IN clause to String", dimension, numFilters, orDimFilter.getFields().size()));
}
}
}
final List<String> rowOrder;
if (query instanceof TimeseriesQuery && !druidQuery.getGrouping().getDimensions().isEmpty()) {
// Hack for timeseries queries: when generating them, DruidQuery.toTimeseriesQuery translates a dimension
// based on a timestamp_floor expression into a 'granularity'. This is not reflected in the druidQuery's
// output row signature, so we have to account for it here.
// TODO: We can remove this once https://github.com/apache/druid/issues/9974 is done.
final String timeDimension = Iterables.getOnlyElement(druidQuery.getGrouping().getDimensions()).getOutputName();
rowOrder = druidQuery.getOutputRowSignature().getColumnNames().stream().map(f -> timeDimension.equals(f) ? ColumnHolder.TIME_COLUMN_NAME : f).collect(Collectors.toList());
} else {
rowOrder = druidQuery.getOutputRowSignature().getColumnNames();
}
final List<SqlTypeName> columnTypes = druidQuery.getOutputRowType().getFieldList().stream().map(f -> f.getType().getSqlTypeName()).collect(Collectors.toList());
return execute(query, mapColumnList(rowOrder, fieldMapping), mapColumnList(columnTypes, fieldMapping));
}
use of org.apache.druid.java.util.common.UOE in project druid by druid-io.
the class ScanQueryLimitRowIterator method next.
@Override
public ScanResultValue next() {
if (ScanQuery.ResultFormat.RESULT_FORMAT_VALUE_VECTOR.equals(resultFormat)) {
throw new UOE(ScanQuery.ResultFormat.RESULT_FORMAT_VALUE_VECTOR + " is not supported yet");
}
// inner-level if we are time-ordering
if (query.getTimeOrder() == ScanQuery.Order.NONE || !query.getContextBoolean(ScanQuery.CTX_KEY_OUTERMOST, true)) {
ScanResultValue batch = yielder.get();
List events = (List) batch.getEvents();
if (events.size() <= limit - count) {
count += events.size();
yielder = yielder.next(null);
return batch;
} else {
// last batch
// single batch length is <= Integer.MAX_VALUE, so this should not overflow
int numLeft = (int) (limit - count);
count = limit;
return new ScanResultValue(batch.getSegmentId(), batch.getColumns(), events.subList(0, numLeft));
}
} else {
// Perform single-event ScanResultValue batching at the outer level. Each scan result value from the yielder
// in this case will only have one event so there's no need to iterate through events.
int batchSize = query.getBatchSize();
List<Object> eventsToAdd = new ArrayList<>(batchSize);
List<String> columns = new ArrayList<>();
while (eventsToAdd.size() < batchSize && !yielder.isDone() && count < limit) {
ScanResultValue srv = yielder.get();
// Only replace once using the columns from the first event
columns = columns.isEmpty() ? srv.getColumns() : columns;
eventsToAdd.add(Iterables.getOnlyElement((List<Object>) srv.getEvents()));
yielder = yielder.next(null);
count++;
}
return new ScanResultValue(null, columns, eventsToAdd);
}
}
use of org.apache.druid.java.util.common.UOE in project druid by druid-io.
the class ScanQueryQueryToolChest method resultsAsArrays.
@Override
public Sequence<Object[]> resultsAsArrays(final ScanQuery query, final Sequence<ScanResultValue> resultSequence) {
final List<String> fields = resultArraySignature(query).getColumnNames();
final Function<?, Object[]> mapper;
switch(query.getResultFormat()) {
case RESULT_FORMAT_LIST:
mapper = (Map<String, Object> row) -> {
final Object[] rowArray = new Object[fields.size()];
for (int i = 0; i < fields.size(); i++) {
rowArray[i] = row.get(fields.get(i));
}
return rowArray;
};
break;
case RESULT_FORMAT_COMPACTED_LIST:
mapper = (List<Object> row) -> {
if (row.size() == fields.size()) {
return row.toArray();
} else if (fields.isEmpty()) {
return new Object[0];
} else {
// the result row here.
throw new ISE("Mismatch in expected[%d] vs actual[%s] field count", fields.size(), row.size());
}
};
break;
default:
throw new UOE("Unsupported resultFormat for array-based results: %s", query.getResultFormat());
}
return resultSequence.flatMap(result -> {
// Generics? Where we're going, we don't need generics.
final List rows = (List) result.getEvents();
final Iterable arrays = Iterables.transform(rows, (Function) mapper);
return Sequences.simple(arrays);
});
}
use of org.apache.druid.java.util.common.UOE in project druid by druid-io.
the class ExpressionFilter method makeVectorMatcher.
@Override
public VectorValueMatcher makeVectorMatcher(VectorColumnSelectorFactory factory) {
final Expr theExpr = expr.get();
DruidPredicateFactory predicateFactory = new DruidPredicateFactory() {
@Override
public Predicate<String> makeStringPredicate() {
return Evals::asBoolean;
}
@Override
public DruidLongPredicate makeLongPredicate() {
return Evals::asBoolean;
}
@Override
public DruidFloatPredicate makeFloatPredicate() {
return Evals::asBoolean;
}
@Override
public DruidDoublePredicate makeDoublePredicate() {
return Evals::asBoolean;
}
// The hashcode and equals are to make SubclassesMustOverrideEqualsAndHashCodeTest stop complaining..
// DruidPredicateFactory currently doesn't really need equals or hashcode since 'toString' method that is actually
// called when testing equality of DimensionPredicateFilter, so it's the truly required method, but that seems
// a bit strange. DimensionPredicateFilter should probably be reworked to use equals from DruidPredicateFactory
// instead of using toString.
@Override
public int hashCode() {
return super.hashCode();
}
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}
};
final ExpressionType outputType = theExpr.getOutputType(factory);
// effectively constant
if (outputType == null) {
// false matcher
if (NullHandling.sqlCompatible()) {
return BooleanVectorValueMatcher.of(factory.getReadableVectorInspector(), false);
}
// or not.
return BooleanVectorValueMatcher.of(factory.getReadableVectorInspector(), theExpr.eval(InputBindings.nilBindings()).asBoolean());
}
// if we got here, we really have to evaluate the expressions to match
switch(outputType.getType()) {
case LONG:
return VectorValueMatcherColumnProcessorFactory.instance().makeLongProcessor(ColumnCapabilitiesImpl.createSimpleNumericColumnCapabilities(ColumnType.LONG), ExpressionVectorSelectors.makeVectorValueSelector(factory, theExpr)).makeMatcher(predicateFactory);
case DOUBLE:
return VectorValueMatcherColumnProcessorFactory.instance().makeDoubleProcessor(ColumnCapabilitiesImpl.createSimpleNumericColumnCapabilities(ColumnType.DOUBLE), ExpressionVectorSelectors.makeVectorValueSelector(factory, theExpr)).makeMatcher(predicateFactory);
case STRING:
return VectorValueMatcherColumnProcessorFactory.instance().makeObjectProcessor(ColumnCapabilitiesImpl.createSimpleSingleValueStringColumnCapabilities(), ExpressionVectorSelectors.makeVectorObjectSelector(factory, theExpr)).makeMatcher(predicateFactory);
default:
throw new UOE("Vectorized expression matchers not implemented for type: [%s]", outputType);
}
}
Aggregations