Example usage for org.apache.commons.collections.iterators EmptyListIterator INSTANCE

List of usage examples for org.apache.commons.collections.iterators EmptyListIterator INSTANCE

Introduction

In this page you can find the example usage for org.apache.commons.collections.iterators EmptyListIterator INSTANCE.

Prototype

ListIterator INSTANCE

To view the source code for org.apache.commons.collections.iterators EmptyListIterator INSTANCE.

Click Source Link

Document

Singleton instance of the iterator.

Usage

From source file:com.splicemachine.derby.stream.compaction.SparkCompactionFunction.java

@SuppressWarnings("unchecked")
@Override//from  www  .j a v a2  s . c om
public Iterator<String> call(Iterator it) throws Exception {

    ArrayList<StoreFile> readersToClose = new ArrayList<StoreFile>();
    Configuration conf = HConfiguration.unwrapDelegate();
    TableName tn = TableName.valueOf(namespace, tableName);
    PartitionFactory tableFactory = SIDriver.driver().getTableFactory();
    Table table = (((ClientPartition) tableFactory.getTable(tn)).unwrapDelegate());

    FileSystem fs = FSUtils.getCurrentFileSystem(conf);
    Path rootDir = FSUtils.getRootDir(conf);

    HTableDescriptor htd = table.getTableDescriptor();
    HRegion region = HRegion.openHRegion(conf, fs, rootDir, hri, new ReadOnlyHTableDescriptor(htd), null, null,
            null);
    Store store = region.getStore(storeColumn);

    assert it.hasNext();
    Tuple2 t = (Tuple2) it.next();
    Iterator files = (Iterator) t._2;
    if (LOG.isTraceEnabled()) {
        LOG.trace("compacting files: ");
    }
    while (files.hasNext()) {
        String file = (String) files.next();
        if (LOG.isTraceEnabled()) {
            LOG.trace(file + "\n");
        }
        readersToClose.add(new StoreFile(fs, new Path(file), conf, store.getCacheConfig(),
                store.getFamily().getBloomFilterType()));
    }

    SpliceDefaultCompactor sdc = new SpliceDefaultCompactor(conf, store, smallestReadPoint);
    List<Path> paths = sdc.sparkCompact(new CompactionRequest(readersToClose));

    if (LOG.isTraceEnabled()) {
        StringBuilder sb = new StringBuilder(100);
        sb.append(String.format("Result %d paths: ", paths.size()));
        for (Path path : paths) {
            sb.append(String.format("\nPath: %s", path));
        }
        SpliceLogUtils.trace(LOG, sb.toString());
    }
    return (paths == null || paths.isEmpty()) ? EmptyListIterator.INSTANCE
            : new SingletonIterator(paths.get(0).toString());
}

From source file:com.splicemachine.derby.stream.function.RowAndIndexGenerator.java

@Override
public Iterator<Tuple2<Long, Tuple2<byte[], byte[]>>> call(LocatedRow locatedRow) throws Exception {
    ExecRow execRow = locatedRow.getRow();
    if (!initialized) {
        encoder = new PairEncoder(getKeyEncoder(), getRowHash(), dataType);
        int i = 0;
        indexTransformFunctions = new IndexTransformFunction[tentativeIndices.size()];
        for (DDLMessage.TentativeIndex index : tentativeIndices) {
            indexTransformFunctions[i] = new IndexTransformFunction(index);
            i++;//ww w .j a v  a  2 s  . com
        }
        initialized = true;
    }

    try {
        ArrayList<Tuple2<Long, Tuple2<byte[], byte[]>>> list = new ArrayList();
        KVPair mainRow = encoder.encode(execRow);
        locatedRow.setRowLocation(new HBaseRowLocation(mainRow.rowKeySlice()));
        list.add(new Tuple2<>(heapConglom, new Tuple2<>(mainRow.getRowKey(), mainRow.getValue())));
        for (int i = 0; i < indexTransformFunctions.length; i++) {
            LocatedRow indexRow = getIndexRow(indexTransformFunctions[i], locatedRow);
            Long indexConglomerate = indexTransformFunctions[i].getIndexConglomerateId();
            KVPair indexKVPair = indexTransformFunctions[i].call(indexRow);
            list.add(new Tuple2<>(indexConglomerate,
                    new Tuple2<>(indexKVPair.getRowKey(), indexKVPair.getValue())));
        }
        return list.iterator();

    } catch (Exception e) {
        if (operationContext != null && operationContext.isPermissive()) {
            operationContext.recordBadRecord(e.getLocalizedMessage() + execRow.toString(), e);
            return EmptyListIterator.INSTANCE;
        }
        throw Exceptions.parseException(e);
    }
}