Search in sources :

Example 16 with UOE

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UOE(org.apache.druid.java.util.common.UOE)

Example 17 with UOE

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");
                }
            };
        }
    }));
}
Also used : HashMap(java.util.HashMap) BitSet(java.util.BitSet) UOE(org.apache.druid.java.util.common.UOE) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Nullable(javax.annotation.Nullable)

Example 18 with UOE

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());
}
Also used : CancellationException(java.util.concurrent.CancellationException) UOE(org.apache.druid.java.util.common.UOE) ISE(org.apache.druid.java.util.common.ISE) Test(org.junit.Test)

Example 19 with UOE

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);
    }
}
Also used : CharSource(com.google.common.io.CharSource) IndexingServiceFirehoseModule(org.apache.druid.guice.IndexingServiceFirehoseModule) IndexingHadoopModule(org.apache.druid.indexer.IndexingHadoopModule) LocalDataStorageDruidModule(org.apache.druid.guice.LocalDataStorageDruidModule) UOE(org.apache.druid.java.util.common.UOE) Logger(org.apache.druid.java.util.common.logger.Logger) HadoopDruidIndexerConfig(org.apache.druid.indexer.HadoopDruidIndexerConfig) NullWriter(org.apache.commons.io.output.NullWriter) IOException(java.io.IOException) FirehoseModule(org.apache.druid.guice.FirehoseModule) IndexingServiceFirehoseModule(org.apache.druid.guice.IndexingServiceFirehoseModule) IndexingServiceInputSourceModule(org.apache.druid.guice.IndexingServiceInputSourceModule) Injector(com.google.inject.Injector) StringInputRowParser(org.apache.druid.data.input.impl.StringInputRowParser) ExtensionsConfig(org.apache.druid.guice.ExtensionsConfig) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

UOE (org.apache.druid.java.util.common.UOE)19 ArrayList (java.util.ArrayList)7 ISE (org.apache.druid.java.util.common.ISE)7 List (java.util.List)6 Interval (org.joda.time.Interval)6 Map (java.util.Map)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 File (java.io.File)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)3 Nullable (javax.annotation.Nullable)3 DynamicPartitionsSpec (org.apache.druid.indexer.partitions.DynamicPartitionsSpec)3 IAE (org.apache.druid.java.util.common.IAE)3 StringUtils (org.apache.druid.java.util.common.StringUtils)3 Sequence (org.apache.druid.java.util.common.guava.Sequence)3 Optional (com.google.common.base.Optional)2 Preconditions (com.google.common.base.Preconditions)2 ImmutableList (com.google.common.collect.ImmutableList)2 Collections (java.util.Collections)2