use of org.apache.druid.java.util.common.UOE in project druid by druid-io.
the class ScanQueryTestHelper method generateScanResultValue.
public static ScanResultValue generateScanResultValue(long timestamp, ScanQuery.ResultFormat resultFormat, int batchSize) {
String segmentId = "some_segment_id";
List<String> columns = new ArrayList<>(Arrays.asList(ColumnHolder.TIME_COLUMN_NAME, "name", "count"));
List<Object> events = new ArrayList<>();
for (int i = 0; i < batchSize; i++) {
Object event;
if (resultFormat.equals(ScanQuery.ResultFormat.RESULT_FORMAT_LIST)) {
Map<String, Object> eventMap = new HashMap<>();
eventMap.put(ColumnHolder.TIME_COLUMN_NAME, timestamp);
eventMap.put("name", "Feridun");
eventMap.put("count", i);
event = eventMap;
} else if (resultFormat.equals(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)) {
event = new ArrayList<>(Arrays.asList(timestamp, "Feridun", i));
} else {
throw new UOE("Result format [%s] not supported yet", resultFormat.toString());
}
events.add(event);
}
return new ScanResultValue(segmentId, columns, events);
}
use of org.apache.druid.java.util.common.UOE in project druid by druid-io.
the class IndexIOTest method constructionFeeder.
@Parameterized.Parameters(name = "{0}, {1}")
public static Iterable<Object[]> constructionFeeder() {
final Map<String, Object> map = ImmutableMap.of();
final Map<String, Object> map00 = ImmutableMap.of("dim0", ImmutableList.of("dim00", "dim01"));
final Map<String, Object> map10 = ImmutableMap.of("dim1", "dim10");
final Map<String, Object> map0null = new HashMap<>();
map0null.put("dim0", null);
final Map<String, Object> map1null = new HashMap<>();
map1null.put("dim1", null);
final Map<String, Object> mapAll = ImmutableMap.of("dim0", ImmutableList.of("dim00", "dim01"), "dim1", "dim10");
final List<Map<String, Object>> maps = ImmutableList.of(map, map00, map10, map0null, map1null, mapAll);
return Iterables.concat(// First iterable tests permutations of the maps which are expected to be equal
Iterables.concat(new Iterable<Iterable<Object[]>>() {
@Override
public Iterator<Iterable<Object[]>> iterator() {
return new Iterator<Iterable<Object[]>>() {
long nextBitset = 1L;
@Override
public boolean hasNext() {
return nextBitset < (1L << maps.size());
}
@Override
public Iterable<Object[]> next() {
final BitSet bitset = BitSet.valueOf(new long[] { nextBitset++ });
final List<Map<String, Object>> myMaps = filterByBitset(maps, bitset);
return Collections2.transform(Collections2.permutations(myMaps), new Function<List<Map<String, Object>>, Object[]>() {
@Nullable
@Override
public Object[] apply(List<Map<String, Object>> input) {
return new Object[] { input, input, null };
}
});
}
@Override
public void remove() {
throw new UOE("Remove not suported");
}
};
}
}), // Second iterable tests combinations of the maps which may or may not be equal
Iterables.concat(new Iterable<Iterable<Object[]>>() {
@Override
public Iterator<Iterable<Object[]>> iterator() {
return new Iterator<Iterable<Object[]>>() {
long nextMap1Bits = 1L;
@Override
public boolean hasNext() {
return nextMap1Bits < (1L << maps.size());
}
@Override
public Iterable<Object[]> next() {
final BitSet bitset1 = BitSet.valueOf(new long[] { nextMap1Bits++ });
final List<Map<String, Object>> maplist1 = filterByBitset(maps, bitset1);
return new Iterable<Object[]>() {
@Override
public Iterator<Object[]> iterator() {
return new Iterator<Object[]>() {
long nextMap2Bits = 1L;
@Override
public boolean hasNext() {
return nextMap2Bits < (1L << maps.size());
}
@Override
public Object[] next() {
final List<Map<String, Object>> maplist2 = filterByBitset(maps, BitSet.valueOf(new long[] { nextMap2Bits++ }));
return new Object[] { maplist1, maplist2, filterNullValues(maplist1).equals(filterNullValues(maplist2)) ? null : SegmentValidationException.class };
}
@Override
public void remove() {
throw new UOE("remove not supported");
}
};
}
};
}
@Override
public void remove() {
throw new UOE("Remove not supported");
}
};
}
}));
}
use of org.apache.druid.java.util.common.UOE in project druid by druid-io.
the class QueryInterruptedExceptionTest method testErrorCode.
@Test
public void testErrorCode() {
Assert.assertEquals("Query cancelled", new QueryInterruptedException(new QueryInterruptedException(new CancellationException())).getErrorCode());
Assert.assertEquals("Query cancelled", new QueryInterruptedException(new CancellationException()).getErrorCode());
Assert.assertEquals("Query interrupted", new QueryInterruptedException(new InterruptedException()).getErrorCode());
Assert.assertEquals("Unsupported operation", new QueryInterruptedException(new UOE("Unsupported")).getErrorCode());
Assert.assertEquals("Unknown exception", new QueryInterruptedException(null).getErrorCode());
Assert.assertEquals("Unknown exception", new QueryInterruptedException(new ISE("Something bad!")).getErrorCode());
Assert.assertEquals("Unknown exception", new QueryInterruptedException(new QueryInterruptedException(new ISE("Something bad!"))).getErrorCode());
}
use of org.apache.druid.java.util.common.UOE in project druid by druid-io.
the class DruidJsonValidator method run.
@Override
public void run() {
File file = new File(jsonFile);
if (!file.exists()) {
LOG.info("File[%s] does not exist.%n", file);
}
final Injector injector = makeInjector();
final ObjectMapper jsonMapper = injector.getInstance(ObjectMapper.class);
registerModules(jsonMapper, Iterables.concat(Initialization.getFromExtensions(injector.getInstance(ExtensionsConfig.class), DruidModule.class), Arrays.asList(new FirehoseModule(), new IndexingHadoopModule(), new IndexingServiceFirehoseModule(), new IndexingServiceInputSourceModule(), new LocalDataStorageDruidModule())));
final ClassLoader loader;
if (Thread.currentThread().getContextClassLoader() != null) {
loader = Thread.currentThread().getContextClassLoader();
} else {
loader = DruidJsonValidator.class.getClassLoader();
}
if (toLogger) {
logWriter = new NullWriter() {
private final Logger logger = new Logger(DruidJsonValidator.class);
@Override
public void write(char[] cbuf, int off, int len) {
logger.info(new String(cbuf, off, len));
}
};
}
try {
if ("query".equalsIgnoreCase(type)) {
jsonMapper.readValue(file, Query.class);
} else if ("hadoopConfig".equalsIgnoreCase(type)) {
jsonMapper.readValue(file, HadoopDruidIndexerConfig.class);
} else if ("task".equalsIgnoreCase(type)) {
jsonMapper.readValue(file, Task.class);
} else if ("parse".equalsIgnoreCase(type)) {
final StringInputRowParser parser;
if (file.isFile()) {
logWriter.write("loading parse spec from file '" + file + "'");
parser = jsonMapper.readValue(file, StringInputRowParser.class);
} else if (loader.getResource(jsonFile) != null) {
logWriter.write("loading parse spec from resource '" + jsonFile + "'");
parser = jsonMapper.readValue(loader.getResource(jsonFile), StringInputRowParser.class);
} else {
logWriter.write("cannot find proper spec from 'file'.. regarding it as a json spec");
parser = jsonMapper.readValue(jsonFile, StringInputRowParser.class);
}
parser.initializeParser();
if (resource != null) {
final CharSource source;
if (new File(resource).isFile()) {
logWriter.write("loading data from file '" + resource + "'");
source = Resources.asByteSource(new File(resource).toURI().toURL()).asCharSource(Charset.forName(parser.getEncoding()));
} else if (loader.getResource(resource) != null) {
logWriter.write("loading data from resource '" + resource + "'");
source = Resources.asByteSource(loader.getResource(resource)).asCharSource(Charset.forName(parser.getEncoding()));
} else {
logWriter.write("cannot find proper data from 'resource'.. regarding it as data string");
source = CharSource.wrap(resource);
}
readData(parser, source);
}
} else {
throw new UOE("Unknown type[%s]", type);
}
} catch (Exception e) {
LOG.error(e, "INVALID JSON!");
Throwables.propagateIfPossible(e);
throw new RuntimeException(e);
}
}
Aggregations