    /**
     * This method will asynchronously fill the set with matches from within the specified bounding FI range.
     *
     * @param boundingFiRange
     * @return the Future
     */
    protected Future<?> fillSet(final Range boundingFiRange) {

        // create runnable
        Runnable runnable = () -> {
            if (log.isDebugEnabled()) {
                log.debug("Starting fillSet(" + boundingFiRange + ')');
            }
            int scanned = 0;
            int matched = 0;
            QuerySpan querySpan = null;
            SortedKeyValueIterator<Key,Value> source = null;
            try {
                source = getSourceCopy(false);
                if (collectTimingDetails && source instanceof SourceTrackingIterator) {
                    querySpan = ((SourceTrackingIterator) source).getQuerySpan();
                }

                // seek the source to a range covering the entire row....the bounding box will dictate the actual scan
                source.seek(boundingFiRange, EMPTY_CFS, false);
                scanned++;
                DatawaveFieldIndexCachingIteratorJexl.this.scannedKeys.incrementAndGet();

                while (source.hasTop()) {
                    checkTiming();

                    // terminate if timed out or cancelled
                    if (DatawaveFieldIndexCachingIteratorJexl.this.setControl.isCancelledQuery()) {
                        break;
                    }

                    if (addKey(source.getTopKey(), source.getTopValue())) {
                        matched++;
                    }

                    source.next();
                    scanned++;
                    DatawaveFieldIndexCachingIteratorJexl.this.scannedKeys.incrementAndGet();
                }
            } catch (Exception e) {
                // throw the exception up which will be available via the Future
                log.error("Failed to complete fillSet(" + boundingFiRange + ")", e);
                throw new RuntimeException(e);
            } finally {
                releaseSource(source);
                if (log.isDebugEnabled()) {
                    StringBuilder builder = new StringBuilder();
                    builder.append("Matched ").append(matched).append(" out of ").append(scanned).append(" for ").append(boundingFiRange).append(": ")
                                    .append(DatawaveFieldIndexCachingIteratorJexl.this);
                    log.debug(builder.toString());
                }
                if (collectTimingDetails && querySpanCollector != null && querySpan != null) {
                    querySpanCollector.addQuerySpan(querySpan);
                }
            }
        };

        return IteratorThreadPoolManager.executeIvarator(runnable, DatawaveFieldIndexCachingIteratorJexl.this.toString() + " in " + boundingFiRange.toString());

    }

    /**
     * This method will asynchronously fill the set with matches from within the specified bounding FI range.
     *
     * @param boundingFiRange
     * @return the Future
     */
    protected Future<?> fillSet(final Range boundingFiRange) {

        // create runnable
        Runnable runnable = new Runnable() {
            public void run() {
                if (log.isDebugEnabled()) {
                    log.debug("Starting fillSet(" + boundingFiRange + ')');
                }
                int scanned = 0;
                int matched = 0;
                QuerySpan querySpan = null;
                SortedKeyValueIterator<Key,Value> source = null;
                try {
                    source = getSourceCopy(false);
                    if (collectTimingDetails && source instanceof SourceTrackingIterator) {
                        querySpan = ((SourceTrackingIterator) source).getQuerySpan();
                    }

                    // seek the source to a range covering the entire row....the bounding box will dictate the actual scan
                    source.seek(boundingFiRange, EMPTY_CFS, false);
                    scanned++;
                    DatawaveFieldIndexCachingIteratorJexl.this.scannedKeys.incrementAndGet();

                    while (source.hasTop()) {
                        checkTiming();

                        // terminate if timed out or cancelled
                        if (DatawaveFieldIndexCachingIteratorJexl.this.setControl.isCancelledQuery()) {
                            break;
                        }

                        if (addKey(source.getTopKey(), source.getTopValue())) {
                            matched++;
                        }

                        source.next();
                        scanned++;
                        DatawaveFieldIndexCachingIteratorJexl.this.scannedKeys.incrementAndGet();
                    }
                } catch (Exception e) {
                    // throw the exception up which will be available via the Future
                    log.error("Failed to complete fillSet(" + boundingFiRange + ")", e);
                    throw new RuntimeException(e);
                } finally {
                    releaseSource(source);
                    if (log.isDebugEnabled()) {
                        StringBuilder builder = new StringBuilder();
                        builder.append("Matched ").append(matched).append(" out of ").append(scanned).append(" for ").append(boundingFiRange).append(": ")
                                        .append(DatawaveFieldIndexCachingIteratorJexl.this);
                        log.debug(builder.toString());
                    }
                    if (collectTimingDetails && querySpanCollector != null && querySpan != null) {
                        querySpanCollector.addQuerySpan(querySpan);
                    }
                }
            }
        };

        return IteratorThreadPoolManager.executeIvarator(runnable, DatawaveFieldIndexCachingIteratorJexl.this.toString() + " in " + boundingFiRange.toString());

    }

Replace Anonymous With Lambda datawave.core.iterators.DatawaveFieldIndexCachingIteratorJexl.fillSet.runnable.new Runnable with () -> {if(log.isDebugEnabled()){log.debug("Starting fillSet(" + boundingFiRange + ')'); in method protected fillSet(boundingFiRange Range) : Future<?> from class datawave.core.iterators.DatawaveFieldIndexCachingIteratorJexl


    private ThreadPoolExecutor createExecutorService(final String prop, final String name) {
        final ThreadPoolExecutor service = createExecutorService(getMaxThreads(prop), name + " (" + instanceId + ')');
        threadPools.put(name, service);
        SimpleTimer.getInstance(AccumuloConfiguration.getDefaultConfiguration()).schedule(() -> {
            try {

                int max = getMaxThreads(prop);
                if (service.getMaximumPoolSize() != max) {
                    log.info("Changing " + prop + " to " + max);
                    service.setCorePoolSize(max);
                    service.setMaximumPoolSize(max);
                }
            } catch (Throwable t) {
                log.error(t, t);
            }
        }, 1000, 10 * 1000);
        return service;
    }

    private ThreadPoolExecutor createExecutorService(final String prop, final String name) {
        final ThreadPoolExecutor service = createExecutorService(getMaxThreads(prop), name + " (" + instanceId + ')');
        threadPools.put(name, service);
        SimpleTimer.getInstance(AccumuloConfiguration.getDefaultConfiguration()).schedule(new Runnable() {
            @Override
            public void run() {
                try {

                    int max = getMaxThreads(prop);
                    if (service.getMaximumPoolSize() != max) {
                        log.info("Changing " + prop + " to " + max);
                        service.setCorePoolSize(max);
                        service.setMaximumPoolSize(max);
                    }
                } catch (Throwable t) {
                    log.error(t, t);
                }
            }

        }, 1000, 10 * 1000);
        return service;
    }

Replace Anonymous With Lambda datawave.core.iterators.IteratorThreadPoolManager.createExecutorService.schedule.new Runnable with () -> {tryint max=getMaxThreads(prop); in method private createExecutorService(prop String, name String) : ThreadPoolExecutor from class datawave.core.iterators.IteratorThreadPoolManager


    private Future<?> execute(String name, final Runnable task, final String taskName) {
        return threadPools.get(name).submit(() -> {
            String oldName = Thread.currentThread().getName();
            Thread.currentThread().setName(oldName + " -> " + taskName);
            try {
                task.run();
            } finally {
                Thread.currentThread().setName(oldName);
            }
        });
    }

    private Future<?> execute(String name, final Runnable task, final String taskName) {
        return threadPools.get(name).submit(new Runnable() {
            @Override
            public void run() {
                String oldName = Thread.currentThread().getName();
                Thread.currentThread().setName(oldName + " -> " + taskName);
                try {
                    task.run();
                } finally {
                    Thread.currentThread().setName(oldName);
                }
            }
        });
    }

Replace Anonymous With Lambda datawave.core.iterators.IteratorThreadPoolManager.execute.submit.new Runnable with () -> {String oldName=Thread.currentThread().getName(); in method private execute(name String, task Runnable, taskName String) : Future<?> from class datawave.core.iterators.IteratorThreadPoolManager


    public void consume() throws IOException {
        Stopwatch consumeSW = null, processResultSW = null, ioWaitSW = null;

        if (log.isTraceEnabled()) {
            consumeSW = new Stopwatch();
            processResultSW = new Stopwatch();
            ioWaitSW = new Stopwatch();
        } else {
            consumeSW = new Stopwatch(zeroTicker);
            processResultSW = new Stopwatch(zeroTicker);
            ioWaitSW = new Stopwatch(zeroTicker);
        }

        consumeSW.start();
        ioWaitSW.start();

        this.count = 0;
        while (getSource().hasTop()) {
            ioWaitSW.stop();
            processResultSW.start();

            if (getSource().getTopKey() != null) {
                final Text cvholder = new Text();

                this.currentTopKey = getSource().getTopKey();
                this.currentTopKey.getColumnVisibility(cvholder);

                // Merge the ColumnVisibilities
                // Do not count the record if we can't parse its ColumnVisibility
                try {
                    ColumnVisibility cv = CV_CACHE.get(cvholder, () -> new ColumnVisibility(cvholder));

                    columnVisibilities.add(cv);
                } catch (Exception e) {
                    log.error("Error parsing ColumnVisibility of key", e);
                    continue;
                }

                this.count++;
            }

            processResultSW.stop();
            ioWaitSW.start();

            try {
                getSource().next();
            } catch (IOException e) {
                log.error("IOException in calling next on the source", e);
                break;
            }
        }

        ioWaitSW.stop();
        consumeSW.stop();

        if (log.isDebugEnabled()) {
            log.debug(threadName + ": Returning a count of " + this.count);
        }

        if (log.isTraceEnabled()) {
            log.trace(threadName + ": Total consume() time: " + consumeSW.elapsedMillis());
            log.trace(threadName + ": Total next()/hasNext() time: " + ioWaitSW.elapsedMillis());
            log.trace(threadName + ": Total internal time: " + processResultSW.elapsedMillis());
        }
    }

    public void consume() throws IOException {
        Stopwatch consumeSW = null, processResultSW = null, ioWaitSW = null;

        if (log.isTraceEnabled()) {
            consumeSW = new Stopwatch();
            processResultSW = new Stopwatch();
            ioWaitSW = new Stopwatch();
        } else {
            consumeSW = new Stopwatch(zeroTicker);
            processResultSW = new Stopwatch(zeroTicker);
            ioWaitSW = new Stopwatch(zeroTicker);
        }

        consumeSW.start();
        ioWaitSW.start();

        this.count = 0;
        while (getSource().hasTop()) {
            ioWaitSW.stop();
            processResultSW.start();

            if (getSource().getTopKey() != null) {
                final Text cvholder = new Text();

                this.currentTopKey = getSource().getTopKey();
                this.currentTopKey.getColumnVisibility(cvholder);

                // Merge the ColumnVisibilities
                // Do not count the record if we can't parse its ColumnVisibility
                try {
                    ColumnVisibility cv = CV_CACHE.get(cvholder, new Callable<ColumnVisibility>() {

                        @Override
                        public ColumnVisibility call() throws Exception {
                            return new ColumnVisibility(cvholder);
                        }

                    });

                    columnVisibilities.add(cv);
                } catch (Exception e) {
                    log.error("Error parsing ColumnVisibility of key", e);
                    continue;
                }

                this.count++;
            }

            processResultSW.stop();
            ioWaitSW.start();

            try {
                getSource().next();
            } catch (IOException e) {
                log.error("IOException in calling next on the source", e);
                break;
            }
        }

        ioWaitSW.stop();
        consumeSW.stop();

        if (log.isDebugEnabled()) {
            log.debug(threadName + ": Returning a count of " + this.count);
        }

        if (log.isTraceEnabled()) {
            log.trace(threadName + ": Total consume() time: " + consumeSW.elapsedMillis());
            log.trace(threadName + ": Total next()/hasNext() time: " + ioWaitSW.elapsedMillis());
            log.trace(threadName + ": Total internal time: " + processResultSW.elapsedMillis());
        }
    }

Replace Anonymous With Lambda datawave.core.iterators.ResultCountingIterator.consume.cv.get.new Callable<ColumnVisibility> with () -> new ColumnVisibility(cvholder) in method public consume() : void from class datawave.core.iterators.ResultCountingIterator


    /**
     * @param topIter
     * @param conf
     * @return
     * @throws ClassNotFoundException
     * @throws IllegalAccessException
     * @throws InstantiationException
     * @throws IOException
     */
    protected SortedKeyValueIterator<Key,Value> buildTopIterators(SortedKeyValueIterator<Key,Value> topIter, Configuration conf) throws ClassNotFoundException,
                    InstantiationException, IllegalAccessException, IOException {

        List<AccumuloIterator> iterators = BulkInputFormat.getIterators(conf);
        List<AccumuloIteratorOption> options = BulkInputFormat.getIteratorOptions(conf);

        Map<String,IteratorSetting> scanIterators = new HashMap<String,IteratorSetting>();
        for (AccumuloIterator iterator : iterators) {
            scanIterators.put(iterator.getIteratorName(), new IteratorSetting(iterator.getPriority(), iterator.getIteratorName(), iterator.getIteratorClass()));
        }
        for (AccumuloIteratorOption option : options) {
            scanIterators.get(option.getIteratorName()).addOption(option.getKey(), option.getValue());
        }

        SortedKeyValueIterator<Key,Value> newIter = topIter;

        BulkIteratorEnvironment myData = new BulkIteratorEnvironment(IteratorScope.scan);
        // ensure we create the iterators in priority order
        Collections.sort(iterators, (o1, o2) -> {
            if (o1.getPriority() < o2.getPriority()) {
                return -1;
            } else if (o1.getPriority() > o2.getPriority()) {
                return 1;
            } else {
                return o1.getIteratorName().compareTo(o2.getIteratorName());
            }
        });
        for (AccumuloIterator iterator : iterators) {

            IteratorSetting settings = scanIterators.get(iterator.getIteratorName());

            Class<? extends SortedKeyValueIterator> iter = Class.forName(settings.getIteratorClass()).asSubclass(SortedKeyValueIterator.class);

            SortedKeyValueIterator<Key,Value> newInstance = iter.newInstance();

            newInstance.init(newIter, settings.getOptions(), myData);

            newIter = newInstance;
        }
        return newIter;
    }

    /**
     * @param topIter
     * @param conf
     * @return
     * @throws ClassNotFoundException
     * @throws IllegalAccessException
     * @throws InstantiationException
     * @throws IOException
     */
    protected SortedKeyValueIterator<Key,Value> buildTopIterators(SortedKeyValueIterator<Key,Value> topIter, Configuration conf) throws ClassNotFoundException,
                    InstantiationException, IllegalAccessException, IOException {

        List<AccumuloIterator> iterators = BulkInputFormat.getIterators(conf);
        List<AccumuloIteratorOption> options = BulkInputFormat.getIteratorOptions(conf);

        Map<String,IteratorSetting> scanIterators = new HashMap<String,IteratorSetting>();
        for (AccumuloIterator iterator : iterators) {
            scanIterators.put(iterator.getIteratorName(), new IteratorSetting(iterator.getPriority(), iterator.getIteratorName(), iterator.getIteratorClass()));
        }
        for (AccumuloIteratorOption option : options) {
            scanIterators.get(option.getIteratorName()).addOption(option.getKey(), option.getValue());
        }

        SortedKeyValueIterator<Key,Value> newIter = topIter;

        BulkIteratorEnvironment myData = new BulkIteratorEnvironment(IteratorScope.scan);
        // ensure we create the iterators in priority order
        Collections.sort(iterators, new Comparator<AccumuloIterator>() {
            @Override
            public int compare(AccumuloIterator o1, AccumuloIterator o2) {
                if (o1.getPriority() < o2.getPriority()) {
                    return -1;
                } else if (o1.getPriority() > o2.getPriority()) {
                    return 1;
                } else {
                    return o1.getIteratorName().compareTo(o2.getIteratorName());
                }
            }
        });
        for (AccumuloIterator iterator : iterators) {

            IteratorSetting settings = scanIterators.get(iterator.getIteratorName());

            Class<? extends SortedKeyValueIterator> iter = Class.forName(settings.getIteratorClass()).asSubclass(SortedKeyValueIterator.class);

            SortedKeyValueIterator<Key,Value> newInstance = iter.newInstance();

            newInstance.init(newIter, settings.getOptions(), myData);

            newIter = newInstance;
        }
        return newIter;
    }

Replace Anonymous With Lambda datawave.mr.bulk.RecordIterator.buildTopIterators.sort.new Comparator<AccumuloIterator> with (o1, o2) -> {if(o1.getPriority() < o2.getPriority()){return -1; in method protected buildTopIterators(topIter SortedKeyValueIterator<Key,Value>, conf Configuration) : SortedKeyValueIterator<Key,Value> from class datawave.mr.bulk.RecordIterator


    protected Future<SortedKeyValueIterator<Key,Value>> iterFromFile(final FileOperations ops, final Path path, final Configuration conf)
                    throws TableNotFoundException, IOException {

        return executor.submit(() -> {

            if (callClosed.get()) {
                throw new IOException("Shutdown in progress");
            }

            final FileSystem fs = FileSystem.newInstance(path.toUri(), conf);

            if (callClosed.get()) {
                fs.close();
                throw new IOException("Shutdown in progress");
            }

            AtomicBoolean isSuccess = new AtomicBoolean(false);

            RfileCloseable closeable = new RfileCloseable();

            FileSKVIterator fileIterator = null;

            try {

                rfileReferences.add(closeable);

                closeable.setFileSystemReference(fs);

                // Path path = new Path(file);

                closeable.setInputStream(fs.open(path));

                long length = fs.getFileStatus(path).getLen();

                closeable.setBlockFile(new Reader(closeable.getInputStream(), length, conf, null, null, acuTableConf));

                fileIterator = new RFile.Reader(closeable.getReader());

                closeable.setIterator(fileIterator);

                fileIterators.add(fileIterator);

                isSuccess.set(true);
            } catch (Exception e) {
                if (null != fileIterator) {
                    fileIterator.close();
                }
                closeable.close();
                throw e;
            } finally {
                if (!isSuccess.get() || Thread.interrupted() || callClosed.get()) {
                    closeable.close();
                }
            }

            return fileIterator;
        });
    }

    protected Future<SortedKeyValueIterator<Key,Value>> iterFromFile(final FileOperations ops, final Path path, final Configuration conf)
                    throws TableNotFoundException, IOException {

        return executor.submit(new Callable<SortedKeyValueIterator<Key,Value>>() {
            public SortedKeyValueIterator<Key,Value> call() throws Exception {

                if (callClosed.get()) {
                    throw new IOException("Shutdown in progress");
                }

                final FileSystem fs = FileSystem.newInstance(path.toUri(), conf);

                if (callClosed.get()) {
                    fs.close();
                    throw new IOException("Shutdown in progress");
                }

                AtomicBoolean isSuccess = new AtomicBoolean(false);

                RfileCloseable closeable = new RfileCloseable();

                FileSKVIterator fileIterator = null;

                try {

                    rfileReferences.add(closeable);

                    closeable.setFileSystemReference(fs);

                    // Path path = new Path(file);

                    closeable.setInputStream(fs.open(path));

                    long length = fs.getFileStatus(path).getLen();

                    closeable.setBlockFile(new CachableBlockFile.Reader(closeable.getInputStream(), length, conf, null, null, acuTableConf));

                    fileIterator = new RFile.Reader(closeable.getReader());

                    closeable.setIterator(fileIterator);

                    fileIterators.add(fileIterator);

                    isSuccess.set(true);
                } catch (Exception e) {
                    if (null != fileIterator) {
                        fileIterator.close();
                    }
                    closeable.close();
                    throw e;
                } finally {
                    if (!isSuccess.get() || Thread.interrupted() || callClosed.get()) {
                        closeable.close();
                    }
                }

                return fileIterator;
            }
        });
    }

Replace Anonymous With Lambda datawave.mr.bulk.RecordIterator.iterFromFile.submit.new Callable<SortedKeyValueIterator<Key,Value>> with () -> {if(callClosed.get()){throw new IOException("Shutdown in progress"); in method protected iterFromFile(ops FileOperations, path Path, conf Configuration) : Future<SortedKeyValueIterator<Key,Value>> from class datawave.mr.bulk.RecordIterator


    static public void writeToDisk(final CardinalityRecord cardinalityRecord, final File file) {

        if (cardinalityRecord.getCardinalityMap().size() > 0) {
            ExecutorService executor = Executors.newSingleThreadExecutor();
            executor.execute(() -> {
                synchronized (file) {
                    ObjectOutputStream oos = null;
                    try {
                        FileOutputStream fos = new FileOutputStream(file);
                        oos = new ObjectOutputStream(fos);
                        oos.writeObject(cardinalityRecord);
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                    } finally {
                        IOUtils.closeQuietly(oos);
                        file.notify();
                    }
                }
            });
            // schedule executor for shutdown after submitted task completes
            executor.shutdown();
        }
    }

    static public void writeToDisk(final CardinalityRecord cardinalityRecord, final File file) {

        if (cardinalityRecord.getCardinalityMap().size() > 0) {
            ExecutorService executor = Executors.newSingleThreadExecutor();
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    synchronized (file) {
                        ObjectOutputStream oos = null;
                        try {
                            FileOutputStream fos = new FileOutputStream(file);
                            oos = new ObjectOutputStream(fos);
                            oos.writeObject(cardinalityRecord);
                        } catch (Exception e) {
                            log.error(e.getMessage(), e);
                        } finally {
                            IOUtils.closeQuietly(oos);
                            file.notify();
                        }
                    }
                }
            });
            // schedule executor for shutdown after submitted task completes
            executor.shutdown();
        }
    }

Replace Anonymous With Lambda datawave.query.cardinality.CardinalityRecord.writeToDisk.execute.new Runnable with () -> {synchronized(file){ObjectOutputStream oos=null; in method public writeToDisk(cardinalityRecord CardinalityRecord, file File) : void from class datawave.query.cardinality.CardinalityRecord


    static Iterable<IndexInfo> convert(Iterable<? extends PeekingIterator<Tuple2<String,IndexInfo>>> i) {
        final Function<PeekingIterator<Tuple2<String,IndexInfo>>,IndexInfo> f = itr -> {
            if (log.isTraceEnabled())
                log.trace("ah" + itr.peek().first() + " " + itr.peek().second());
            return itr.peek().second();
        };
        return Iterables.transform(i, f);
    }

    static Iterable<IndexInfo> convert(Iterable<? extends PeekingIterator<Tuple2<String,IndexInfo>>> i) {
        final Function<PeekingIterator<Tuple2<String,IndexInfo>>,IndexInfo> f = new Function<PeekingIterator<Tuple2<String,IndexInfo>>,IndexInfo>() {
            public IndexInfo apply(PeekingIterator<Tuple2<String,IndexInfo>> itr) {
                if (log.isTraceEnabled())
                    log.trace("ah" + itr.peek().first() + " " + itr.peek().second());
                return itr.peek().second();
            }
        };
        return Iterables.transform(i, f);
    }

Replace Anonymous With Lambda datawave.query.index.lookup.Intersection.convert.f.new Function<PeekingIterator<Tuple2<String,IndexInfo>>,IndexInfo> with itr -> {if(log.isTraceEnabled())log.trace("ah" + itr.peek().first() + " " + itr.peek().second()); in method package convert(i Iterable<? extends PeekingIterator<Tuple2<String,IndexInfo>>>) : Iterable<IndexInfo> from class datawave.query.index.lookup.Intersection


    @Override
    public Iterator<Entry<DocumentData,Document>> iterator() {
        final DocumentDataIterator docItr = new DocumentDataIterator(this.source, this.environment, this.options, this.totalRange, this.filter, this.eq,
                        this.evaluationFilter, this.includeChildCount, this.includeParent);
        Iterator<Entry<DocumentData,Document>> itr = Iterators.transform(docItr, from -> Maps.immutableEntry(from, new Document()));

        return itr;
    }

    @Override
    public Iterator<Entry<DocumentData,Document>> iterator() {
        final DocumentDataIterator docItr = new DocumentDataIterator(this.source, this.environment, this.options, this.totalRange, this.filter, this.eq,
                        this.evaluationFilter, this.includeChildCount, this.includeParent);
        Iterator<Entry<DocumentData,Document>> itr = Iterators.transform(docItr, new Function<DocumentData,Entry<DocumentData,Document>>() {

            @Override
            public Entry<DocumentData,Document> apply(DocumentData from) {
                return Maps.immutableEntry(from, new Document());
            }

        });

        return itr;
    }

Replace Anonymous With Lambda datawave.query.iterator.AccumuloTableIterable.iterator.itr.transform.new Function<DocumentData,Entry<DocumentData,Document>> with from -> Maps.immutableEntry(from,new Document()) in method public iterator() : Iterator<Entry<DocumentData,Document>> from class datawave.query.iterator.AccumuloTableIterable


    @Override
    public Iterator<Entry<T,Document>> iterator() {
        if (seenSeek) {
            Span s = Trace.start("Field Index Initialize Boolean Tree");

            try {
                tree.initialize();
            } finally {
                if (null != s) {
                    s.stop();
                }
            }

            Iterator<Entry<S,Document>> wrapper = TraceIterators.transform(tree, from -> {
                Entry<S,Document> entry = Maps.immutableEntry(from, tree.document());
                return entry;
            }, "Field Index");

            return Iterators.transform(wrapper, func);
        } else {
            throw new IllegalStateException("You have to seek this tree.");
        }
    }

    @Override
    public Iterator<Entry<T,Document>> iterator() {
        if (seenSeek) {
            Span s = Trace.start("Field Index Initialize Boolean Tree");

            try {
                tree.initialize();
            } finally {
                if (null != s) {
                    s.stop();
                }
            }

            Iterator<Entry<S,Document>> wrapper = TraceIterators.transform(tree, new Function<S,Entry<S,Document>>() {

                @Override
                public Entry<S,Document> apply(S from) {
                    Entry<S,Document> entry = Maps.immutableEntry(from, tree.document());
                    return entry;
                }

            }, "Field Index");

            return Iterators.transform(wrapper, func);
        } else {
            throw new IllegalStateException("You have to seek this tree.");
        }
    }

Replace Anonymous With Lambda datawave.query.iterator.AccumuloTreeIterable.iterator.wrapper.transform.new Function<S,Entry<S,Document>> with from -> {Entry<S,Document> entry=Maps.immutableEntry(from,tree.document()); in method public iterator() : Iterator<Entry<T,Document>> from class datawave.query.iterator.AccumuloTreeIterable


    /**
     * Create the pipeline. It is very important that this pipeline can handle resetting the bottom iterator with a new value. This means that hasNext() needs
     * to call the next iterator. The only state that can be maintained is the next value ready after hasNext() has been called. Once next returns the value,
     * the next hasNext() call must call the next iterator again. So for example Iterators.filter() cannot be used as it uses a google commons AbstractIterator
     * that maintains an iterator state (failed, ready, done); use statelessFilter above instead.
     *
     * @param deepSourceCopy
     * @param documentSpecificSource
     * @return iterator of keys and values
     */
    public Iterator<Entry<Key,Value>> createDocumentPipeline(SortedKeyValueIterator<Key,Value> deepSourceCopy,
                    final NestedQueryIterator<Key> documentSpecificSource, QuerySpanCollector querySpanCollector) {

        QuerySpan trackingSpan = null;
        if (gatherTimingDetails()) {
            trackingSpan = new QuerySpan(getStatsdClient());
        }
        if (log.isTraceEnabled()) {
            log.trace("createDocumentPipeline");
        }
        final Function<Entry<Key,Document>,Entry<DocumentData,Document>> docMapper;

        if (isFieldIndexSatisfyingQuery()) {
            if (log.isTraceEnabled()) {
                log.trace("isFieldIndexSatisfyingQuery");
            }
            docMapper = new Function<Entry<Key,Document>,Entry<DocumentData,Document>>() {
                @Nullable
                @Override
                public Entry<DocumentData,Document> apply(@Nullable Entry<Key,Document> input) {

                    Entry<DocumentData,Document> entry = null;
                    if (input != null) {
                        entry = Maps.immutableEntry(new DocumentData(input.getKey(), Collections.singleton(input.getKey()), Collections.EMPTY_LIST),
                                        input.getValue());
                    }
                    return entry;
                }
            };
        } else {
            docMapper = new KeyToDocumentData(deepSourceCopy, myEnvironment, documentOptions, super.equality, getEvaluationFilter(),
                            this.includeHierarchyFields, this.includeHierarchyFields);
        }

        Iterator<Entry<DocumentData,Document>> sourceIterator = Iterators.transform(documentSpecificSource, from -> {
            Entry<Key,Document> entry = Maps.immutableEntry(from, documentSpecificSource.document());
            return docMapper.apply(entry);
        });

        // Take the document Keys and transform it into Entry<Key,Document>,
        // removing Attributes for this Document
        // which do not fall within the expected time range
        Iterator<Entry<Key,Document>> documents = null;
        Aggregation a = new Aggregation(this.getTimeFilter(), this.typeMetadataWithNonIndexed, compositeMetadata, this.isIncludeGroupingContext(),
                        this.includeRecordId, this.disableIndexOnlyDocuments(), getEvaluationFilter(), isTrackSizes());
        if (gatherTimingDetails()) {
            documents = Iterators.transform(sourceIterator, new EvaluationTrackingFunction<>(QuerySpan.Stage.Aggregation, trackingSpan, a));
        } else {
            documents = Iterators.transform(sourceIterator, a);
        }

        // Inject the data type as a field if the user requested it
        if (this.includeDatatype) {
            if (gatherTimingDetails()) {
                documents = Iterators.transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.DataTypeAsField, trackingSpan, new DataTypeAsField(
                                this.datatypeKey)));
            } else {
                documents = Iterators.transform(documents, new DataTypeAsField(this.datatypeKey));
            }
        }

        // Inject the document permutations if required
        if (!this.getDocumentPermutations().isEmpty()) {
            if (gatherTimingDetails()) {
                documents = Iterators.transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.DocumentPermutation, trackingSpan,
                                new DocumentPermutation.DocumentPermutationAggregation(this.getDocumentPermutations())));
            } else {
                documents = Iterators.transform(documents, new DocumentPermutation.DocumentPermutationAggregation(this.getDocumentPermutations()));
            }
        }

        if (gatherTimingDetails()) {
            documents = new EvaluationTrackingIterator(QuerySpan.Stage.DocumentEvaluation, trackingSpan, getEvaluation(documentSpecificSource, deepSourceCopy,
                            documents, compositeMetadata, typeMetadataWithNonIndexed));
        } else {
            documents = getEvaluation(documentSpecificSource, deepSourceCopy, documents, compositeMetadata, typeMetadataWithNonIndexed);
        }

        // a hook to allow mapping the document such as with the TLD or Parent
        // query logics
        // or if the document was not aggregated in the first place because the
        // field index fields completely satisfied the query
        documents = mapDocument(deepSourceCopy, documents, compositeMetadata);

        // apply any configured post processing
        documents = getPostProcessingChain(documents);
        if (gatherTimingDetails()) {
            documents = new EvaluationTrackingIterator(QuerySpan.Stage.PostProcessing, trackingSpan, documents);
        }

        // Filter out masked values if requested
        if (this.filterMaskedValues) {
            MaskedValueFilterInterface mvfi = MaskedValueFilterFactory.get(this.isIncludeGroupingContext(), this.isReducedResponse());
            if (gatherTimingDetails()) {
                documents = Iterators.transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.MaskedValueFilter, trackingSpan, mvfi));
            } else {
                documents = Iterators.transform(documents, mvfi);
            }
        }

        // now filter the attributes to those with the keep flag set true
        if (gatherTimingDetails()) {
            documents = Iterators.transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.AttributeKeepFilter, trackingSpan,
                            new AttributeKeepFilter<Key>()));
        } else {
            documents = Iterators.transform(documents, new AttributeKeepFilter<Key>());
        }

        // Project fields using a whitelist or a blacklist before serialization
        if (this.projectResults) {
            if (gatherTimingDetails()) {
                documents = Iterators.transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.DocumentProjection, trackingSpan, getProjection()));
            } else {
                documents = Iterators.transform(documents, getProjection());
            }
        }

        // remove the composite entries
        documents = Iterators.transform(documents, this.getCompositeProjection());

        // now apply the unique transform if requested
        UniqueTransform uniquify = getUniqueTransform();
        if (uniquify != null) {
            documents = Iterators.filter(documents, uniquify.getUniquePredicate());
        }

        // Filter out any Documents which are empty (e.g. due to attribute
        // projection or visibility filtering)
        if (gatherTimingDetails()) {
            documents = statelessFilter(documents, new EvaluationTrackingPredicate<>(QuerySpan.Stage.EmptyDocumentFilter, trackingSpan,
                            new EmptyDocumentFilter()));
            documents = Iterators
                            .transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.DocumentMetadata, trackingSpan, new DocumentMetadata()));
        } else {
            documents = statelessFilter(documents, new EmptyDocumentFilter());
            documents = Iterators.transform(documents, new DocumentMetadata());
        }

        if (this.limitFieldsMap.size() > 0) {
            if (gatherTimingDetails()) {
                documents = Iterators.transform(documents,
                                new EvaluationTrackingFunction<>(QuerySpan.Stage.LimitFields, trackingSpan, new LimitFields(this.getLimitFieldsMap())));
            } else {
                documents = Iterators.transform(documents, new LimitFields(this.getLimitFieldsMap()));
            }
        }

        // do I need to remove the grouping context I added above?
        if (groupingContextAddedByMe) {
            if (gatherTimingDetails()) {
                documents = Iterators.transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.RemoveGroupingContext, trackingSpan,
                                new RemoveGroupingContext()));
            } else {
                documents = Iterators.transform(documents, new RemoveGroupingContext());
            }
        }

        // only add the pipeline query span collection iterator which will cache metrics with each document if collectTimingDetails is true
        if (collectTimingDetails) {
            // if there is not a result, then add the trackingSpan to the
            // QuerySpanCollector
            // if there was a result, then the metrics from the trackingSpan
            // will be added here
            documents = new PipelineQuerySpanCollectionIterator(querySpanCollector, trackingSpan, documents);
        }

        if (this.getReturnType() == ReturnType.kryo) {
            // Serialize the Document using Kryo
            return Iterators.transform(documents, new KryoDocumentSerializer(isReducedResponse(), isCompressResults()));
        } else if (this.getReturnType() == ReturnType.writable) {
            // Use the Writable interface to serialize the Document
            return Iterators.transform(documents, new WritableDocumentSerializer(isReducedResponse()));
        } else if (this.getReturnType() == ReturnType.tostring) {
            // Just return a toString() representation of the document
            return Iterators.transform(documents, new ToStringDocumentSerializer(isReducedResponse()));
        } else {
            throw new IllegalArgumentException("Unknown return type of: " + this.getReturnType());
        }
    }

    /**
     * Create the pipeline. It is very important that this pipeline can handle resetting the bottom iterator with a new value. This means that hasNext() needs
     * to call the next iterator. The only state that can be maintained is the next value ready after hasNext() has been called. Once next returns the value,
     * the next hasNext() call must call the next iterator again. So for example Iterators.filter() cannot be used as it uses a google commons AbstractIterator
     * that maintains an iterator state (failed, ready, done); use statelessFilter above instead.
     *
     * @param deepSourceCopy
     * @param documentSpecificSource
     * @return iterator of keys and values
     */
    public Iterator<Entry<Key,Value>> createDocumentPipeline(SortedKeyValueIterator<Key,Value> deepSourceCopy,
                    final NestedQueryIterator<Key> documentSpecificSource, QuerySpanCollector querySpanCollector) {

        QuerySpan trackingSpan = null;
        if (gatherTimingDetails()) {
            trackingSpan = new QuerySpan(getStatsdClient());
        }
        if (log.isTraceEnabled()) {
            log.trace("createDocumentPipeline");
        }
        final Function<Entry<Key,Document>,Entry<DocumentData,Document>> docMapper;

        if (isFieldIndexSatisfyingQuery()) {
            if (log.isTraceEnabled()) {
                log.trace("isFieldIndexSatisfyingQuery");
            }
            docMapper = new Function<Entry<Key,Document>,Entry<DocumentData,Document>>() {
                @Nullable
                @Override
                public Entry<DocumentData,Document> apply(@Nullable Entry<Key,Document> input) {

                    Entry<DocumentData,Document> entry = null;
                    if (input != null) {
                        entry = Maps.immutableEntry(new DocumentData(input.getKey(), Collections.singleton(input.getKey()), Collections.EMPTY_LIST),
                                        input.getValue());
                    }
                    return entry;
                }
            };
        } else {
            docMapper = new KeyToDocumentData(deepSourceCopy, myEnvironment, documentOptions, super.equality, getEvaluationFilter(),
                            this.includeHierarchyFields, this.includeHierarchyFields);
        }

        Iterator<Entry<DocumentData,Document>> sourceIterator = Iterators.transform(documentSpecificSource, new Function<Key,Entry<DocumentData,Document>>() {

            @Override
            public Entry<DocumentData,Document> apply(Key from) {
                Entry<Key,Document> entry = Maps.immutableEntry(from, documentSpecificSource.document());
                return docMapper.apply(entry);
            }

        });

        // Take the document Keys and transform it into Entry<Key,Document>,
        // removing Attributes for this Document
        // which do not fall within the expected time range
        Iterator<Entry<Key,Document>> documents = null;
        Aggregation a = new Aggregation(this.getTimeFilter(), this.typeMetadataWithNonIndexed, compositeMetadata, this.isIncludeGroupingContext(),
                        this.includeRecordId, this.disableIndexOnlyDocuments(), getEvaluationFilter(), isTrackSizes());
        if (gatherTimingDetails()) {
            documents = Iterators.transform(sourceIterator, new EvaluationTrackingFunction<>(QuerySpan.Stage.Aggregation, trackingSpan, a));
        } else {
            documents = Iterators.transform(sourceIterator, a);
        }

        // Inject the data type as a field if the user requested it
        if (this.includeDatatype) {
            if (gatherTimingDetails()) {
                documents = Iterators.transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.DataTypeAsField, trackingSpan, new DataTypeAsField(
                                this.datatypeKey)));
            } else {
                documents = Iterators.transform(documents, new DataTypeAsField(this.datatypeKey));
            }
        }

        // Inject the document permutations if required
        if (!this.getDocumentPermutations().isEmpty()) {
            if (gatherTimingDetails()) {
                documents = Iterators.transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.DocumentPermutation, trackingSpan,
                                new DocumentPermutation.DocumentPermutationAggregation(this.getDocumentPermutations())));
            } else {
                documents = Iterators.transform(documents, new DocumentPermutation.DocumentPermutationAggregation(this.getDocumentPermutations()));
            }
        }

        if (gatherTimingDetails()) {
            documents = new EvaluationTrackingIterator(QuerySpan.Stage.DocumentEvaluation, trackingSpan, getEvaluation(documentSpecificSource, deepSourceCopy,
                            documents, compositeMetadata, typeMetadataWithNonIndexed));
        } else {
            documents = getEvaluation(documentSpecificSource, deepSourceCopy, documents, compositeMetadata, typeMetadataWithNonIndexed);
        }

        // a hook to allow mapping the document such as with the TLD or Parent
        // query logics
        // or if the document was not aggregated in the first place because the
        // field index fields completely satisfied the query
        documents = mapDocument(deepSourceCopy, documents, compositeMetadata);

        // apply any configured post processing
        documents = getPostProcessingChain(documents);
        if (gatherTimingDetails()) {
            documents = new EvaluationTrackingIterator(QuerySpan.Stage.PostProcessing, trackingSpan, documents);
        }

        // Filter out masked values if requested
        if (this.filterMaskedValues) {
            MaskedValueFilterInterface mvfi = MaskedValueFilterFactory.get(this.isIncludeGroupingContext(), this.isReducedResponse());
            if (gatherTimingDetails()) {
                documents = Iterators.transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.MaskedValueFilter, trackingSpan, mvfi));
            } else {
                documents = Iterators.transform(documents, mvfi);
            }
        }

        // now filter the attributes to those with the keep flag set true
        if (gatherTimingDetails()) {
            documents = Iterators.transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.AttributeKeepFilter, trackingSpan,
                            new AttributeKeepFilter<Key>()));
        } else {
            documents = Iterators.transform(documents, new AttributeKeepFilter<Key>());
        }

        // Project fields using a whitelist or a blacklist before serialization
        if (this.projectResults) {
            if (gatherTimingDetails()) {
                documents = Iterators.transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.DocumentProjection, trackingSpan, getProjection()));
            } else {
                documents = Iterators.transform(documents, getProjection());
            }
        }

        // remove the composite entries
        documents = Iterators.transform(documents, this.getCompositeProjection());

        // now apply the unique transform if requested
        UniqueTransform uniquify = getUniqueTransform();
        if (uniquify != null) {
            documents = Iterators.filter(documents, uniquify.getUniquePredicate());
        }

        // Filter out any Documents which are empty (e.g. due to attribute
        // projection or visibility filtering)
        if (gatherTimingDetails()) {
            documents = statelessFilter(documents, new EvaluationTrackingPredicate<>(QuerySpan.Stage.EmptyDocumentFilter, trackingSpan,
                            new EmptyDocumentFilter()));
            documents = Iterators
                            .transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.DocumentMetadata, trackingSpan, new DocumentMetadata()));
        } else {
            documents = statelessFilter(documents, new EmptyDocumentFilter());
            documents = Iterators.transform(documents, new DocumentMetadata());
        }

        if (this.limitFieldsMap.size() > 0) {
            if (gatherTimingDetails()) {
                documents = Iterators.transform(documents,
                                new EvaluationTrackingFunction<>(QuerySpan.Stage.LimitFields, trackingSpan, new LimitFields(this.getLimitFieldsMap())));
            } else {
                documents = Iterators.transform(documents, new LimitFields(this.getLimitFieldsMap()));
            }
        }

        // do I need to remove the grouping context I added above?
        if (groupingContextAddedByMe) {
            if (gatherTimingDetails()) {
                documents = Iterators.transform(documents, new EvaluationTrackingFunction<>(QuerySpan.Stage.RemoveGroupingContext, trackingSpan,
                                new RemoveGroupingContext()));
            } else {
                documents = Iterators.transform(documents, new RemoveGroupingContext());
            }
        }

        // only add the pipeline query span collection iterator which will cache metrics with each document if collectTimingDetails is true
        if (collectTimingDetails) {
            // if there is not a result, then add the trackingSpan to the
            // QuerySpanCollector
            // if there was a result, then the metrics from the trackingSpan
            // will be added here
            documents = new PipelineQuerySpanCollectionIterator(querySpanCollector, trackingSpan, documents);
        }

        if (this.getReturnType() == ReturnType.kryo) {
            // Serialize the Document using Kryo
            return Iterators.transform(documents, new KryoDocumentSerializer(isReducedResponse(), isCompressResults()));
        } else if (this.getReturnType() == ReturnType.writable) {
            // Use the Writable interface to serialize the Document
            return Iterators.transform(documents, new WritableDocumentSerializer(isReducedResponse()));
        } else if (this.getReturnType() == ReturnType.tostring) {
            // Just return a toString() representation of the document
            return Iterators.transform(documents, new ToStringDocumentSerializer(isReducedResponse()));
        } else {
            throw new IllegalArgumentException("Unknown return type of: " + this.getReturnType());
        }
    }

Replace Anonymous With Lambda datawave.query.iterator.QueryIterator.createDocumentPipeline.sourceIterator.transform.new Function<Key,Entry<DocumentData,Document>> with from -> {Entry<Key,Document> entry=Maps.immutableEntry(from,documentSpecificSource.document()); in method public createDocumentPipeline(deepSourceCopy SortedKeyValueIterator<Key,Value>, documentSpecificSource NestedQueryIterator<Key>, querySpanCollector QuerySpanCollector) : Iterator<Entry<Key,Value>> from class datawave.query.iterator.QueryIterator


    public BatchedDocumentIterator(PipelineIterator parent) {
        this.parent = parent;
        sortedResponses = Sets.newTreeSet(Comparator.comparing(Entry::getKey));
    }

    public BatchedDocumentIterator(PipelineIterator parent) {
        this.parent = parent;
        sortedResponses = Sets.newTreeSet(new Comparator<Entry<Key,Value>>() {

            @Override
            public int compare(Entry<Key,Value> o1, Entry<Key,Value> o2) {
                return o1.getKey().compareTo(o2.getKey());
            }

        });
    }

Replace Anonymous With Lambda datawave.query.iterator.pipeline.BatchedDocumentIterator.BatchedDocumentIterator.newTreeSet.new Comparator<Entry<Key,Value>> with Entry::getKey in method public BatchedDocumentIterator(parent PipelineIterator) from class datawave.query.iterator.pipeline.BatchedDocumentIterator


    protected Callable<Boolean> createTimedCallable(final Iterator<Entry<Key,Value>> iter, final IndexLookupMap fieldsToValues, ShardQueryConfiguration config,
                    Set<String> datatypeFilter, final Set<Text> fields, boolean isReverse, long timeout) {
        final Set<String> myDatatypeFilter = datatypeFilter;
        return () -> {
            Text holder = new Text();
            try {
                if (log.isTraceEnabled()) {
                    log.trace("Do we have next? " + iter.hasNext());

                }
                while (iter.hasNext()) {

                    Entry<Key,Value> entry = iter.next();

                    if (TimeoutExceptionIterator.exceededTimedValue(entry)) {
                        throw new Exception("Timeout exceeded for bounded range lookup");
                    }
                    Key k = entry.getKey();

                    if (log.isTraceEnabled()) {
                        log.trace("Foward Index entry: " + entry.getKey().toString());
                    }

                    k.getRow(holder);
                    String uniqueTerm = holder.toString();

                    SortedMap<Key,Value> keymap = WholeRowIterator.decodeRow(entry.getKey(), entry.getValue());

                    String field = null;

                    boolean foundDataType = false;

                    for (Key topKey : keymap.keySet()) {
                        if (null == field) {
                            topKey.getColumnFamily(holder);
                            field = holder.toString();
                        }
                        // Get the column qualifier from the key. It
                        // contains the datatype and normalizer class

                        if (null != topKey.getColumnQualifier()) {
                            if (null != myDatatypeFilter && myDatatypeFilter.size() > 0) {

                                String colq = topKey.getColumnQualifier().toString();
                                int idx = colq.indexOf(Constants.NULL);

                                if (idx != -1) {
                                    String type = colq.substring(idx + 1);

                                    // If types are specified and this type
                                    // is not in the list, skip it.
                                    if (myDatatypeFilter.contains(type)) {

                                        if (log.isTraceEnabled())
                                            log.trace(myDatatypeFilter + " contains " + type);
                                        foundDataType = true;
                                        break;
                                    }

                                }
                            } else
                                foundDataType = true;
                        }
                    }
                    if (foundDataType) {

                        // obtaining the size of a map can be expensive,
                        // instead
                        // track the count of each unique item added.
                        fieldsToValues.put(field, uniqueTerm);

                        // safety check...
                        Preconditions.checkState(field.equals(literalRange.getFieldName()), "Got an unexpected field name when expanding range" + field + " "
                                        + literalRange.getFieldName());

                        // If this range expands into to many values, we can
                        // stop
                        if (fieldsToValues.get(field).isThresholdExceeded()) {
                            return true;

                        }
                    }
                }

            } catch (Exception e) {
                log.info("Failed or timed out expanding range fields: " + e.getMessage());
                if (log.isDebugEnabled())
                    log.debug("Failed or Timed out ", e);
                if (fields.size() >= 1) {
                    for (Text fieldTxt : fields) {
                        String field = fieldTxt.toString();
                        if (log.isTraceEnabled()) {
                            log.trace("field is " + field);
                            log.trace("field is " + (null == fieldsToValues));
                        }
                        fieldsToValues.put(field, "");
                        fieldsToValues.get(field).setThresholdExceeded();
                    }
                } else
                    fieldsToValues.setKeyThresholdExceeded();
                return false;
            }

            return true;
        };
    }

    protected Callable<Boolean> createTimedCallable(final Iterator<Entry<Key,Value>> iter, final IndexLookupMap fieldsToValues, ShardQueryConfiguration config,
                    Set<String> datatypeFilter, final Set<Text> fields, boolean isReverse, long timeout) {
        final Set<String> myDatatypeFilter = datatypeFilter;
        return new Callable<Boolean>() {
            public Boolean call() {
                Text holder = new Text();
                try {
                    if (log.isTraceEnabled()) {
                        log.trace("Do we have next? " + iter.hasNext());

                    }
                    while (iter.hasNext()) {

                        Entry<Key,Value> entry = iter.next();

                        if (TimeoutExceptionIterator.exceededTimedValue(entry)) {
                            throw new Exception("Timeout exceeded for bounded range lookup");
                        }
                        Key k = entry.getKey();

                        if (log.isTraceEnabled()) {
                            log.trace("Foward Index entry: " + entry.getKey().toString());
                        }

                        k.getRow(holder);
                        String uniqueTerm = holder.toString();

                        SortedMap<Key,Value> keymap = WholeRowIterator.decodeRow(entry.getKey(), entry.getValue());

                        String field = null;

                        boolean foundDataType = false;

                        for (Key topKey : keymap.keySet()) {
                            if (null == field) {
                                topKey.getColumnFamily(holder);
                                field = holder.toString();
                            }
                            // Get the column qualifier from the key. It
                            // contains the datatype and normalizer class

                            if (null != topKey.getColumnQualifier()) {
                                if (null != myDatatypeFilter && myDatatypeFilter.size() > 0) {

                                    String colq = topKey.getColumnQualifier().toString();
                                    int idx = colq.indexOf(Constants.NULL);

                                    if (idx != -1) {
                                        String type = colq.substring(idx + 1);

                                        // If types are specified and this type
                                        // is not in the list, skip it.
                                        if (myDatatypeFilter.contains(type)) {

                                            if (log.isTraceEnabled())
                                                log.trace(myDatatypeFilter + " contains " + type);
                                            foundDataType = true;
                                            break;
                                        }

                                    }
                                } else
                                    foundDataType = true;
                            }
                        }
                        if (foundDataType) {

                            // obtaining the size of a map can be expensive,
                            // instead
                            // track the count of each unique item added.
                            fieldsToValues.put(field, uniqueTerm);

                            // safety check...
                            Preconditions.checkState(field.equals(literalRange.getFieldName()), "Got an unexpected field name when expanding range" + field
                                            + " " + literalRange.getFieldName());

                            // If this range expands into to many values, we can
                            // stop
                            if (fieldsToValues.get(field).isThresholdExceeded()) {
                                return true;

                            }
                        }
                    }

                } catch (Exception e) {
                    log.info("Failed or timed out expanding range fields: " + e.getMessage());
                    if (log.isDebugEnabled())
                        log.debug("Failed or Timed out ", e);
                    if (fields.size() >= 1) {
                        for (Text fieldTxt : fields) {
                            String field = fieldTxt.toString();
                            if (log.isTraceEnabled()) {
                                log.trace("field is " + field);
                                log.trace("field is " + (null == fieldsToValues));
                            }
                            fieldsToValues.put(field, "");
                            fieldsToValues.get(field).setThresholdExceeded();
                        }
                    } else
                        fieldsToValues.setKeyThresholdExceeded();
                    return false;
                }

                return true;
            }
        };
    }

Replace Anonymous With Lambda datawave.query.jexl.lookups.LookupBoundedRangeForTerms.createTimedCallable.new Callable<Boolean> with () -> {Text holder=new Text(); in method protected createTimedCallable(iter Iterator<Entry<Key,Value>>, fieldsToValues IndexLookupMap, config ShardQueryConfiguration, datatypeFilter Set<String>, fields Set<Text>, isReverse boolean, timeout long) : Callable<Boolean> from class datawave.query.jexl.lookups.LookupBoundedRangeForTerms


    @Override
    protected Callable<Boolean> createTimedCallable(final Iterator<Entry<Key,Value>> iter, final IndexLookupMap fieldsToValues, ShardQueryConfiguration config,
                    Set<String> datatypeFilter, final Set<Text> fields, final boolean isReverse, long timeout) {
        final Set<String> myDatatypeFilter = datatypeFilter;
        return () -> {
            Text holder = new Text();
            try {
                if (log.isTraceEnabled()) {
                    log.trace("Do we have next? " + iter.hasNext());

                }
                while (iter.hasNext()) {

                    Entry<Key,Value> entry = iter.next();

                    if (TimeoutExceptionIterator.exceededTimedValue(entry)) {
                        throw new Exception("Exceeded fair threshold");
                    }

                    Key topKey = entry.getKey();

                    if (log.isTraceEnabled()) {
                        log.trace("Foward Index entry: " + entry.getKey().toString());
                    }

                    // Get the column qualifier from the key. It contains the datatype and normalizer class
                    if (null != topKey.getColumnQualifier()) {
                        String colq = topKey.getColumnQualifier().toString();
                        int idx = colq.indexOf(Constants.NULL);

                        if (idx != -1) {
                            String type = colq.substring(idx + 1);

                            // If types are specified and this type is not in the list, skip it.
                            if (null != myDatatypeFilter && myDatatypeFilter.size() > 0 && !myDatatypeFilter.contains(type)) {

                                if (log.isTraceEnabled())
                                    log.trace(myDatatypeFilter + " does not contain " + type);
                                continue;
                            }

                            topKey.getRow(holder);
                            String term;
                            if (!isReverse)
                                term = holder.toString();
                            else
                                term = (new StringBuilder(holder.toString())).reverse().toString();

                            topKey.getColumnFamily(holder);
                            String field = holder.toString();

                            // We are only returning a mapping of field value to field name, no need to
                            // determine cardinality and such at this point.
                            fieldsToValues.put(field, term);
                            // conditional states that if we exceed the key threshold OR field name is not null and we've exceeded
                            // the value threshold for that field name ( in the case where we have a fielded lookup ).
                            if (fieldsToValues.isKeyThresholdExceeded() || (fields.size() == 1 && fieldsToValues.get(field).isThresholdExceeded())) {
                                if (log.isTraceEnabled())
                                    log.trace("We've passed term expansion threshold");
                                return true;
                            }
                        }
                    }
                }

            } catch (Exception e) {
                log.info("Failed or Timed out expanding regex: " + e.getMessage());
                if (log.isDebugEnabled())
                    log.debug("Failed or Timed out " + e);
                if (fields.size() >= 1) {
                    for (Text fieldTxt : fields) {
                        String field = fieldTxt.toString();
                        if (log.isTraceEnabled()) {
                            log.trace("field is " + field);
                            log.trace("field is " + (null == fieldsToValues));
                        }
                        fieldsToValues.put(field, "");
                        fieldsToValues.get(field).setThresholdExceeded();
                    }
                } else
                    fieldsToValues.setKeyThresholdExceeded();
                return false;
            }

            return true;
        };
    }

    @Override
    protected Callable<Boolean> createTimedCallable(final Iterator<Entry<Key,Value>> iter, final IndexLookupMap fieldsToValues, ShardQueryConfiguration config,
                    Set<String> datatypeFilter, final Set<Text> fields, final boolean isReverse, long timeout) {
        final Set<String> myDatatypeFilter = datatypeFilter;
        return new Callable<Boolean>() {
            public Boolean call() {
                Text holder = new Text();
                try {
                    if (log.isTraceEnabled()) {
                        log.trace("Do we have next? " + iter.hasNext());

                    }
                    while (iter.hasNext()) {

                        Entry<Key,Value> entry = iter.next();

                        if (TimeoutExceptionIterator.exceededTimedValue(entry)) {
                            throw new Exception("Exceeded fair threshold");
                        }

                        Key topKey = entry.getKey();

                        if (log.isTraceEnabled()) {
                            log.trace("Foward Index entry: " + entry.getKey().toString());
                        }

                        // Get the column qualifier from the key. It contains the datatype and normalizer class
                        if (null != topKey.getColumnQualifier()) {
                            String colq = topKey.getColumnQualifier().toString();
                            int idx = colq.indexOf(Constants.NULL);

                            if (idx != -1) {
                                String type = colq.substring(idx + 1);

                                // If types are specified and this type is not in the list, skip it.
                                if (null != myDatatypeFilter && myDatatypeFilter.size() > 0 && !myDatatypeFilter.contains(type)) {

                                    if (log.isTraceEnabled())
                                        log.trace(myDatatypeFilter + " does not contain " + type);
                                    continue;
                                }

                                topKey.getRow(holder);
                                String term;
                                if (!isReverse)
                                    term = holder.toString();
                                else
                                    term = (new StringBuilder(holder.toString())).reverse().toString();

                                topKey.getColumnFamily(holder);
                                String field = holder.toString();

                                // We are only returning a mapping of field value to field name, no need to
                                // determine cardinality and such at this point.
                                fieldsToValues.put(field, term);
                                // conditional states that if we exceed the key threshold OR field name is not null and we've exceeded
                                // the value threshold for that field name ( in the case where we have a fielded lookup ).
                                if (fieldsToValues.isKeyThresholdExceeded() || (fields.size() == 1 && fieldsToValues.get(field).isThresholdExceeded())) {
                                    if (log.isTraceEnabled())
                                        log.trace("We've passed term expansion threshold");
                                    return true;
                                }
                            }
                        }
                    }

                } catch (Exception e) {
                    log.info("Failed or Timed out expanding regex: " + e.getMessage());
                    if (log.isDebugEnabled())
                        log.debug("Failed or Timed out " + e);
                    if (fields.size() >= 1) {
                        for (Text fieldTxt : fields) {
                            String field = fieldTxt.toString();
                            if (log.isTraceEnabled()) {
                                log.trace("field is " + field);
                                log.trace("field is " + (null == fieldsToValues));
                            }
                            fieldsToValues.put(field, "");
                            fieldsToValues.get(field).setThresholdExceeded();
                        }
                    } else
                        fieldsToValues.setKeyThresholdExceeded();
                    return false;
                }

                return true;
            }
        };
    }

Replace Anonymous With Lambda datawave.query.jexl.lookups.LookupTermsFromRegex.createTimedCallable.new Callable<Boolean> with () -> {Text holder=new Text(); in method protected createTimedCallable(iter Iterator<Entry<Key,Value>>, fieldsToValues IndexLookupMap, config ShardQueryConfiguration, datatypeFilter Set<String>, fields Set<Text>, isReverse boolean, timeout long) : Callable<Boolean> from class datawave.query.jexl.lookups.LookupTermsFromRegex


    /**
     * This function is to order collections by size, this is useful so building composites can skip shorter composites ex. if KEY1_KEY2_KEY3 existed we would
     * not want to create KEY1_KEY2 or KEY1_KEY3 so could be skipped.
     *
     * @param mm
     *            Multimap to sort by size of the {@code collection<v>}
     * @param <K>
     *            Key type for mm, not relevant to sort
     * @param <V>
     *            Value type for mm, not relevant to sort
     * @return Sorted linked hash multimap to keep order
     */
    private <K,V> LinkedHashMultimap<K,V> orderByCollectionSize(Multimap<K,V> mm) {
        List<Entry<K,Collection<V>>> orderedCompositeToFieldMap = new ArrayList<>(mm.asMap().entrySet());
        Collections.sort(orderedCompositeToFieldMap, (o1, o2) -> Integer.compare(o2.getValue().size(), o1.getValue().size()));

        LinkedHashMultimap<K,V> orderedMm = LinkedHashMultimap.create();
        for (Map.Entry<K,Collection<V>> foundEntry : orderedCompositeToFieldMap) {
            orderedMm.putAll(foundEntry.getKey(), foundEntry.getValue());
        }
        return orderedMm;
    }

    /**
     * This function is to order collections by size, this is useful so building composites can skip shorter composites ex. if KEY1_KEY2_KEY3 existed we would
     * not want to create KEY1_KEY2 or KEY1_KEY3 so could be skipped.
     *
     * @param mm
     *            Multimap to sort by size of the {@code collection<v>}
     * @param <K>
     *            Key type for mm, not relevant to sort
     * @param <V>
     *            Value type for mm, not relevant to sort
     * @return Sorted linked hash multimap to keep order
     */
    private <K,V> LinkedHashMultimap<K,V> orderByCollectionSize(Multimap<K,V> mm) {
        List<Entry<K,Collection<V>>> orderedCompositeToFieldMap = new ArrayList<>(mm.asMap().entrySet());
        Collections.sort(orderedCompositeToFieldMap, new Comparator<Entry<K,Collection<V>>>() {
            @Override
            public int compare(Entry<K,Collection<V>> o1, Entry<K,Collection<V>> o2) {
                return Integer.compare(o2.getValue().size(), o1.getValue().size());
            }
        });

        LinkedHashMultimap<K,V> orderedMm = LinkedHashMultimap.create();
        for (Map.Entry<K,Collection<V>> foundEntry : orderedCompositeToFieldMap) {
            orderedMm.putAll(foundEntry.getKey(), foundEntry.getValue());
        }
        return orderedMm;
    }

Replace Anonymous With Lambda datawave.query.jexl.visitors.ExpandCompositeTerms.orderByCollectionSize.sort.new Comparator<Entry<K,Collection<V>>> with (o1, o2) -> Integer.compare(o2.getValue().size(),o1.getValue().size()) in method private orderByCollectionSize(mm Multimap<K,V>) : LinkedHashMultimap<K,V> from class datawave.query.jexl.visitors.ExpandCompositeTerms


    protected Future<IteratorSetting> loadQueryIterator(final MetadataHelper metadataHelper, final ShardQueryConfiguration config, final Query settings,
                    final String queryString, final Boolean isFullTable) throws DatawaveQueryException {

        return builderThread
                        .submit(() -> {
                            // VersioningIterator is typically set at 20 on the table
                            IteratorSetting cfg = new IteratorSetting(config.getBaseIteratorPriority() + 40, "query", getQueryIteratorClass());

                            addOption(cfg, Constants.RETURN_TYPE, config.getReturnType().toString(), false);
                            addOption(cfg, QueryOptions.FULL_TABLE_SCAN_ONLY, Boolean.toString(isFullTable), false);

                            if (sourceLimit > 0) {
                                addOption(cfg, QueryOptions.LIMIT_SOURCES, Long.toString(sourceLimit), false);
                            }
                            if (config.getCollectTimingDetails()) {
                                addOption(cfg, QueryOptions.COLLECT_TIMING_DETAILS, Boolean.toString(true), false);
                            }
                            if (config.getSendTimingToStatsd()) {
                                addOption(cfg, QueryOptions.STATSD_HOST_COLON_PORT, config.getStatsdHost() + ':' + Integer.toString(config.getStatsdPort()),
                                                false);
                                addOption(cfg, QueryOptions.STATSD_MAX_QUEUE_SIZE, Integer.toString(config.getStatsdMaxQueueSize()), false);
                            }
                            if (config.getHdfsSiteConfigURLs() != null) {
                                addOption(cfg, QueryOptions.HDFS_SITE_CONFIG_URLS, config.getHdfsSiteConfigURLs(), false);
                            }
                            if (config.getHdfsFileCompressionCodec() != null) {
                                addOption(cfg, QueryOptions.HDFS_FILE_COMPRESSION_CODEC, config.getHdfsFileCompressionCodec(), false);
                            }
                            if (config.getZookeeperConfig() != null) {
                                addOption(cfg, QueryOptions.ZOOKEEPER_CONFIG, config.getZookeeperConfig(), false);
                            }
                            if (config.getIvaratorCacheBaseURIs() != null) {
                                addOption(cfg, QueryOptions.IVARATOR_CACHE_BASE_URI_ALTERNATIVES, getIvaratorQueryCacheBaseUriAlternatives(config), false);
                            }
                            addOption(cfg, QueryOptions.IVARATOR_CACHE_BUFFER_SIZE, Integer.toString(config.getIvaratorCacheBufferSize()), false);
                            addOption(cfg, QueryOptions.IVARATOR_SCAN_PERSIST_THRESHOLD, Long.toString(config.getIvaratorCacheScanPersistThreshold()), false);
                            addOption(cfg, QueryOptions.IVARATOR_SCAN_TIMEOUT, Long.toString(config.getIvaratorCacheScanTimeout()), false);
                            addOption(cfg, QueryOptions.COLLECT_TIMING_DETAILS, Boolean.toString(config.getCollectTimingDetails()), false);
                            addOption(cfg, QueryOptions.MAX_INDEX_RANGE_SPLIT, Integer.toString(config.getMaxFieldIndexRangeSplit()), false);
                            addOption(cfg, QueryOptions.MAX_IVARATOR_OPEN_FILES, Integer.toString(config.getIvaratorMaxOpenFiles()), false);
                            addOption(cfg, QueryOptions.MAX_EVALUATION_PIPELINES, Integer.toString(config.getMaxEvaluationPipelines()), false);
                            addOption(cfg, QueryOptions.MAX_PIPELINE_CACHED_RESULTS, Integer.toString(config.getMaxPipelineCachedResults()), false);
                            addOption(cfg, QueryOptions.MAX_IVARATOR_SOURCES, Integer.toString(config.getMaxIvaratorSources()), false);

                            if (config.getYieldThresholdMs() != Long.MAX_VALUE && config.getYieldThresholdMs() > 0) {
                                addOption(cfg, QueryOptions.YIELD_THRESHOLD_MS, Long.toString(config.getYieldThresholdMs()), false);
                            }

                            addOption(cfg, QueryOptions.SORTED_UIDS, Boolean.toString(config.isSortedUIDs()), false);

                            configureTypeMappings(config, cfg, metadataHelper, compressMappings);
                            configureAdditionalOptions(config, cfg);

                            try {
                                addOption(cfg, QueryOptions.INDEX_ONLY_FIELDS,
                                                QueryOptions.buildIndexOnlyFieldsString(metadataHelper.getIndexOnlyFields(config.getDatatypeFilter())), true);
                                addOption(cfg, QueryOptions.COMPOSITE_FIELDS, QueryOptions.buildIndexOnlyFieldsString(metadataHelper.getCompositeToFieldMap(
                                                config.getDatatypeFilter()).keySet()), true);
                            } catch (TableNotFoundException e) {
                                QueryException qe = new QueryException(DatawaveErrorCode.INDEX_ONLY_FIELDS_RETRIEVAL_ERROR, e);
                                throw new DatawaveQueryException(qe);
                            }

                            try {
                                CompositeMetadata compositeMetadata = metadataHelper.getCompositeMetadata().filter(config.getQueryFieldsDatatypes().keySet());
                                if (compositeMetadata != null && !compositeMetadata.isEmpty())
                                    addOption(cfg, QueryOptions.COMPOSITE_METADATA,
                                                    java.util.Base64.getEncoder().encodeToString(CompositeMetadata.toBytes(compositeMetadata)), false);
                            } catch (TableNotFoundException e) {
                                QueryException qe = new QueryException(DatawaveErrorCode.COMPOSITE_METADATA_CONFIG_ERROR, e);
                                throw new DatawaveQueryException(qe);
                            }

                            String datatypeFilter = config.getDatatypeFilterAsString();

                            addOption(cfg, QueryOptions.DATATYPE_FILTER, datatypeFilter, false);

                            try {
                                addOption(cfg, QueryOptions.CONTENT_EXPANSION_FIELDS,
                                                Joiner.on(',').join(metadataHelper.getContentFields(config.getDatatypeFilter())), false);
                            } catch (TableNotFoundException e) {
                                QueryException qe = new QueryException(DatawaveErrorCode.CONTENT_FIELDS_RETRIEVAL_ERROR, e);
                                throw new DatawaveQueryException(qe);
                            }

                            if (config.isDebugMultithreadedSources()) {
                                addOption(cfg, QueryOptions.DEBUG_MULTITHREADED_SOURCES, Boolean.toString(config.isDebugMultithreadedSources()), false);
                            }

                            if (config.isDataQueryExpressionFilterEnabled()) {
                                addOption(cfg, QueryOptions.DATA_QUERY_EXPRESSION_FILTER_ENABLED,
                                                Boolean.toString(config.isDataQueryExpressionFilterEnabled()), false);
                            }

                            if (config.isLimitFieldsPreQueryEvaluation()) {
                                addOption(cfg, QueryOptions.LIMIT_FIELDS_PRE_QUERY_EVALUATION, Boolean.toString(config.isLimitFieldsPreQueryEvaluation()),
                                                false);
                            }

                            if (config.getLimitFieldsField() != null) {
                                addOption(cfg, QueryOptions.LIMIT_FIELDS_FIELD, config.getLimitFieldsField(), false);
                            }

                            return cfg;
                        });
    }

    protected Future<IteratorSetting> loadQueryIterator(final MetadataHelper metadataHelper, final ShardQueryConfiguration config, final Query settings,
                    final String queryString, final Boolean isFullTable) throws DatawaveQueryException {

        return builderThread.submit(new Callable<IteratorSetting>() {

            @Override
            public IteratorSetting call() throws Exception {
                // VersioningIterator is typically set at 20 on the table
                IteratorSetting cfg = new IteratorSetting(config.getBaseIteratorPriority() + 40, "query", getQueryIteratorClass());

                addOption(cfg, Constants.RETURN_TYPE, config.getReturnType().toString(), false);
                addOption(cfg, QueryOptions.FULL_TABLE_SCAN_ONLY, Boolean.toString(isFullTable), false);

                if (sourceLimit > 0) {
                    addOption(cfg, QueryOptions.LIMIT_SOURCES, Long.toString(sourceLimit), false);
                }
                if (config.getCollectTimingDetails()) {
                    addOption(cfg, QueryOptions.COLLECT_TIMING_DETAILS, Boolean.toString(true), false);
                }
                if (config.getSendTimingToStatsd()) {
                    addOption(cfg, QueryOptions.STATSD_HOST_COLON_PORT, config.getStatsdHost() + ':' + Integer.toString(config.getStatsdPort()), false);
                    addOption(cfg, QueryOptions.STATSD_MAX_QUEUE_SIZE, Integer.toString(config.getStatsdMaxQueueSize()), false);
                }
                if (config.getHdfsSiteConfigURLs() != null) {
                    addOption(cfg, QueryOptions.HDFS_SITE_CONFIG_URLS, config.getHdfsSiteConfigURLs(), false);
                }
                if (config.getHdfsFileCompressionCodec() != null) {
                    addOption(cfg, QueryOptions.HDFS_FILE_COMPRESSION_CODEC, config.getHdfsFileCompressionCodec(), false);
                }
                if (config.getZookeeperConfig() != null) {
                    addOption(cfg, QueryOptions.ZOOKEEPER_CONFIG, config.getZookeeperConfig(), false);
                }
                if (config.getIvaratorCacheBaseURIs() != null) {
                    addOption(cfg, QueryOptions.IVARATOR_CACHE_BASE_URI_ALTERNATIVES, getIvaratorQueryCacheBaseUriAlternatives(config), false);
                }
                addOption(cfg, QueryOptions.IVARATOR_CACHE_BUFFER_SIZE, Integer.toString(config.getIvaratorCacheBufferSize()), false);
                addOption(cfg, QueryOptions.IVARATOR_SCAN_PERSIST_THRESHOLD, Long.toString(config.getIvaratorCacheScanPersistThreshold()), false);
                addOption(cfg, QueryOptions.IVARATOR_SCAN_TIMEOUT, Long.toString(config.getIvaratorCacheScanTimeout()), false);
                addOption(cfg, QueryOptions.COLLECT_TIMING_DETAILS, Boolean.toString(config.getCollectTimingDetails()), false);
                addOption(cfg, QueryOptions.MAX_INDEX_RANGE_SPLIT, Integer.toString(config.getMaxFieldIndexRangeSplit()), false);
                addOption(cfg, QueryOptions.MAX_IVARATOR_OPEN_FILES, Integer.toString(config.getIvaratorMaxOpenFiles()), false);
                addOption(cfg, QueryOptions.MAX_EVALUATION_PIPELINES, Integer.toString(config.getMaxEvaluationPipelines()), false);
                addOption(cfg, QueryOptions.MAX_PIPELINE_CACHED_RESULTS, Integer.toString(config.getMaxPipelineCachedResults()), false);
                addOption(cfg, QueryOptions.MAX_IVARATOR_SOURCES, Integer.toString(config.getMaxIvaratorSources()), false);

                if (config.getYieldThresholdMs() != Long.MAX_VALUE && config.getYieldThresholdMs() > 0) {
                    addOption(cfg, QueryOptions.YIELD_THRESHOLD_MS, Long.toString(config.getYieldThresholdMs()), false);
                }

                addOption(cfg, QueryOptions.SORTED_UIDS, Boolean.toString(config.isSortedUIDs()), false);

                configureTypeMappings(config, cfg, metadataHelper, compressMappings);
                configureAdditionalOptions(config, cfg);

                try {
                    addOption(cfg, QueryOptions.INDEX_ONLY_FIELDS,
                                    QueryOptions.buildIndexOnlyFieldsString(metadataHelper.getIndexOnlyFields(config.getDatatypeFilter())), true);
                    addOption(cfg, QueryOptions.COMPOSITE_FIELDS,
                                    QueryOptions.buildIndexOnlyFieldsString(metadataHelper.getCompositeToFieldMap(config.getDatatypeFilter()).keySet()), true);
                } catch (TableNotFoundException e) {
                    QueryException qe = new QueryException(DatawaveErrorCode.INDEX_ONLY_FIELDS_RETRIEVAL_ERROR, e);
                    throw new DatawaveQueryException(qe);
                }

                try {
                    CompositeMetadata compositeMetadata = metadataHelper.getCompositeMetadata().filter(config.getQueryFieldsDatatypes().keySet());
                    if (compositeMetadata != null && !compositeMetadata.isEmpty())
                        addOption(cfg, QueryOptions.COMPOSITE_METADATA,
                                        java.util.Base64.getEncoder().encodeToString(CompositeMetadata.toBytes(compositeMetadata)), false);
                } catch (TableNotFoundException e) {
                    QueryException qe = new QueryException(DatawaveErrorCode.COMPOSITE_METADATA_CONFIG_ERROR, e);
                    throw new DatawaveQueryException(qe);
                }

                String datatypeFilter = config.getDatatypeFilterAsString();

                addOption(cfg, QueryOptions.DATATYPE_FILTER, datatypeFilter, false);

                try {
                    addOption(cfg, QueryOptions.CONTENT_EXPANSION_FIELDS, Joiner.on(',').join(metadataHelper.getContentFields(config.getDatatypeFilter())),
                                    false);
                } catch (TableNotFoundException e) {
                    QueryException qe = new QueryException(DatawaveErrorCode.CONTENT_FIELDS_RETRIEVAL_ERROR, e);
                    throw new DatawaveQueryException(qe);
                }

                if (config.isDebugMultithreadedSources()) {
                    addOption(cfg, QueryOptions.DEBUG_MULTITHREADED_SOURCES, Boolean.toString(config.isDebugMultithreadedSources()), false);
                }

                if (config.isDataQueryExpressionFilterEnabled()) {
                    addOption(cfg, QueryOptions.DATA_QUERY_EXPRESSION_FILTER_ENABLED, Boolean.toString(config.isDataQueryExpressionFilterEnabled()), false);
                }

                if (config.isLimitFieldsPreQueryEvaluation()) {
                    addOption(cfg, QueryOptions.LIMIT_FIELDS_PRE_QUERY_EVALUATION, Boolean.toString(config.isLimitFieldsPreQueryEvaluation()), false);
                }

                if (config.getLimitFieldsField() != null) {
                    addOption(cfg, QueryOptions.LIMIT_FIELDS_FIELD, config.getLimitFieldsField(), false);
                }

                return cfg;
            }
        });
    }

Replace Anonymous With Lambda datawave.query.planner.DefaultQueryPlanner.loadQueryIterator.submit.new Callable<IteratorSetting> with () -> {IteratorSetting cfg=new IteratorSetting(config.getBaseIteratorPriority() + 40,"query",getQueryIteratorClass()); in method protected loadQueryIterator(metadataHelper MetadataHelper, config ShardQueryConfiguration, settings Query, queryString String, isFullTable Boolean) : Future<IteratorSetting> from class datawave.query.planner.DefaultQueryPlanner


    /**
     * Do not set uncaught exception handler
     *
     */
    @Override
    protected Executor executor() {
        return command -> {
            String name = serviceName();
            Preconditions.checkNotNull(name);
            Preconditions.checkNotNull(command);
            Thread result = MoreExecutors.platformThreadFactory().newThread(command);
            try {
                result.setName(name);
            } catch (SecurityException e) {
                // OK if we can't set the name in this environment.
            }
            result.start();
        };
    }

    /**
     * Do not set uncaught exception handler
     *
     */
    @Override
    protected Executor executor() {
        return new Executor() {
            @Override
            public void execute(Runnable command) {
                String name = serviceName();
                Preconditions.checkNotNull(name);
                Preconditions.checkNotNull(command);
                Thread result = MoreExecutors.platformThreadFactory().newThread(command);
                try {
                    result.setName(name);
                } catch (SecurityException e) {
                    // OK if we can't set the name in this environment.
                }
                result.start();
            }
        };
    }

Replace Anonymous With Lambda datawave.query.tables.AnyFieldScanner.executor.new Executor with command -> {String name=serviceName(); in method protected executor() : Executor from class datawave.query.tables.AnyFieldScanner


    /**
     * overridden in order to set the UncaughtExceptionHandler on the Thread that is created to run the ScannerSession
     */
    @Override
    protected Executor executor() {
        return command -> {
            String name = serviceName();
            Preconditions.checkNotNull(name);
            Preconditions.checkNotNull(command);
            Thread result = MoreExecutors.platformThreadFactory().newThread(command);
            try {
                result.setName(name);
                if (null != settings && null != settings.getUncaughtExceptionHandler())
                    result.setUncaughtExceptionHandler(settings.getUncaughtExceptionHandler());
            } catch (SecurityException e) {
                // OK if we can't set the name in this environment.
            }
            result.start();
        };
    }

    /**
     * overridden in order to set the UncaughtExceptionHandler on the Thread that is created to run the ScannerSession
     */
    @Override
    protected Executor executor() {
        return new Executor() {
            @Override
            public void execute(Runnable command) {
                String name = serviceName();
                Preconditions.checkNotNull(name);
                Preconditions.checkNotNull(command);
                Thread result = MoreExecutors.platformThreadFactory().newThread(command);
                try {
                    result.setName(name);
                    if (null != settings && null != settings.getUncaughtExceptionHandler())
                        result.setUncaughtExceptionHandler(settings.getUncaughtExceptionHandler());
                } catch (SecurityException e) {
                    // OK if we can't set the name in this environment.
                }
                result.start();
            }
        };
    }

Replace Anonymous With Lambda datawave.query.tables.ScannerSession.executor.new Executor with command -> {String name=serviceName(); in method protected executor() : Executor from class datawave.query.tables.ScannerSession


    /**
     * Return the sum across all datatypes of the {@link ColumnFamilyConstants#COLF_F} on the given day in the provided types
     *
     * @param fieldName
     * @param date
     * @param datatypes
     * @return
     */
    public Long getCountsByFieldInDayWithTypes(String fieldName, String date, final Set<String> datatypes) {
        Preconditions.checkNotNull(fieldName);
        Preconditions.checkNotNull(date);
        Preconditions.checkNotNull(datatypes);

        try {
            Map<String,Long> countsByType = getCountsByFieldInDayWithTypes(Maps.immutableEntry(fieldName, date));
            Iterable<Entry<String,Long>> filteredByType = Iterables.filter(countsByType.entrySet(), input -> datatypes.contains(input.getKey()));

            long sum = 0;
            for (Entry<String,Long> entry : filteredByType) {
                sum += entry.getValue();
            }

            return sum;
        } catch (TableNotFoundException | IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Return the sum across all datatypes of the {@link ColumnFamilyConstants#COLF_F} on the given day in the provided types
     *
     * @param fieldName
     * @param date
     * @param datatypes
     * @return
     */
    public Long getCountsByFieldInDayWithTypes(String fieldName, String date, final Set<String> datatypes) {
        Preconditions.checkNotNull(fieldName);
        Preconditions.checkNotNull(date);
        Preconditions.checkNotNull(datatypes);

        try {
            Map<String,Long> countsByType = getCountsByFieldInDayWithTypes(Maps.immutableEntry(fieldName, date));
            Iterable<Entry<String,Long>> filteredByType = Iterables.filter(countsByType.entrySet(), new Predicate<Entry<String,Long>>() {
                @Override
                public boolean apply(Entry<String,Long> input) {
                    return datatypes.contains(input.getKey());
                }

            });

            long sum = 0;
            for (Entry<String,Long> entry : filteredByType) {
                sum += entry.getValue();
            }

            return sum;
        } catch (TableNotFoundException | IOException e) {
            throw new RuntimeException(e);
        }
    }

Replace Anonymous With Lambda datawave.query.util.MetadataHelper.getCountsByFieldInDayWithTypes.filteredByType.filter.new Predicate<Entry<String,Long>> with input -> datatypes.contains(input.getKey()) in method public getCountsByFieldInDayWithTypes(fieldName String, date String, datatypes Set<String>) : Long from class datawave.query.util.MetadataHelper