Example usage for org.apache.cassandra.io.sstable SSTableIdentityIterator hasNext

List of usage examples for org.apache.cassandra.io.sstable SSTableIdentityIterator hasNext

Introduction

In this page you can find the example usage for org.apache.cassandra.io.sstable SSTableIdentityIterator hasNext.

Prototype

public boolean hasNext() 

Source Link

Usage

From source file:com.chaordicsystems.sstableconverter.SSTableConverter.java

License:Apache License

public static void main(String[] args) throws Exception {
    LoaderOptions options = LoaderOptions.parseArgs(args);
    OutputHandler handler = new OutputHandler.SystemOutput(options.verbose, options.debug);

    File srcDir = options.sourceDir;
    File dstDir = options.destDir;
    IPartitioner srcPart = options.srcPartitioner;
    IPartitioner dstPart = options.dstPartitioner;
    String keyspace = options.ks;
    String cf = options.cf;//from ww w .  ja  va 2  s.c  o  m

    if (keyspace == null) {
        keyspace = srcDir.getParentFile().getName();
    }
    if (cf == null) {
        cf = srcDir.getName();
    }

    CFMetaData metadata = new CFMetaData(keyspace, cf, ColumnFamilyType.Standard, BytesType.instance, null);
    Collection<SSTableReader> originalSstables = readSSTables(srcPart, srcDir, metadata, handler);

    handler.output(
            String.format("Converting sstables of ks[%s], cf[%s], from %s to %s. Src dir: %s. Dest dir: %s.",
                    keyspace, cf, srcPart.getClass().getName(), dstPart.getClass().getName(),
                    srcDir.getAbsolutePath(), dstDir.getAbsolutePath()));

    SSTableSimpleUnsortedWriter destWriter = new SSTableSimpleUnsortedWriter(dstDir, dstPart, keyspace, cf,
            AsciiType.instance, null, 64);

    for (SSTableReader reader : originalSstables) {
        handler.output("Reading: " + reader.getFilename());
        SSTableIdentityIterator row;
        SSTableScanner scanner = reader.getDirectScanner(null);

        // collecting keys to export
        while (scanner.hasNext()) {
            row = (SSTableIdentityIterator) scanner.next();

            destWriter.newRow(row.getKey().key);
            while (row.hasNext()) {
                IColumn col = (IColumn) row.next();
                destWriter.addColumn(col.name(), col.value(), col.timestamp());
            }
        }
        scanner.close();
    }

    // Don't forget to close!
    destWriter.close();

    System.exit(0);
}

From source file:com.knewton.mapreduce.SSTableColumnRecordReaderTest.java

License:Apache License

private SSTableIdentityIterator getNewRow() {
    SSTableIdentityIterator row = mock(SSTableIdentityIterator.class);
    when(row.hasNext()).thenReturn(true, true, false);
    when(row.getKey()).thenReturn(key);/* w w w.  java 2  s . c  om*/
    when(row.next()).thenReturn(value);
    return row;
}

From source file:com.spotify.cassandra.opstools.CountTombstones.java

License:Apache License

private static void run(Descriptor desc, CommandLine cmd, PrintStream out) throws IOException {
    // Since we don't have a schema, make one up!
    CFMetaData cfm = new CFMetaData(desc.ksname, desc.cfname, ColumnFamilyType.Standard, UTF8Type.instance,
            UTF8Type.instance);/*from  w  ww.j  a va2 s  .  c  o  m*/

    SSTableReader reader = SSTableReader.open(desc, cfm);
    SSTableScanner scanner = reader.getScanner();

    long totalTombstones = 0, totalColumns = 0;
    if (cmd.hasOption("l")) {
        out.printf(desc.baseFilename() + "\n");
        out.printf("rowkey #tombstones (#columns)\n");
    }
    while (scanner.hasNext()) {
        SSTableIdentityIterator row = (SSTableIdentityIterator) scanner.next();

        int tombstonesCount = 0, columnsCount = 0;
        while (row.hasNext()) {
            OnDiskAtom column = row.next();
            long now = System.currentTimeMillis();
            if (column instanceof Column && ((Column) column).isMarkedForDelete(now)) {
                tombstonesCount++;
            }
            columnsCount++;
        }
        totalTombstones += tombstonesCount;
        totalColumns += columnsCount;

        if (tombstonesCount > 0) {
            String key;
            try {
                key = UTF8Type.instance.getString(row.getKey().key);
            } catch (RuntimeException e) {
                key = BytesType.instance.getString(row.getKey().key);
            }
            out.printf("%s %d (%d)%n", key, tombstonesCount, columnsCount);
        }

    }

    if (cmd.hasOption("l")) {
        out.printf("#total_tombstones (#total_columns)\n");
    }
    out.printf("%d (%d)%n", totalTombstones, totalColumns);

    scanner.close();
}

From source file:org.jasonstack.cassandra.devops.TomnStoneScanner.java

License:Apache License

private static void run(Descriptor desc) throws IOException {
    CFMetaData cfm = CFMetaData.sparseCFMetaData(desc.ksname, desc.cfname, UTF8Type.instance);
    SSTableReader reader = SSTableReader.open(desc, cfm);
    ISSTableScanner scanner = reader.getScanner();

    long totalTombstones = 0, totalColumns = 0;

    while (scanner.hasNext()) {
        // for each partition
        SSTableIdentityIterator row = (SSTableIdentityIterator) scanner.next();

        int tombstonesCount = 0, columnsCount = 0;
        while (row.hasNext()) {
            // for each column in partition
            OnDiskAtom column = row.next();
            if (column instanceof BufferDeletedCell) {
                tombstonesCount++;/*from   w w w.j  a v  a  2 s. c om*/
            }
            columnsCount++;
        }
        totalTombstones += tombstonesCount;
        totalColumns += columnsCount;

        if (tombstonesCount > 0) {
            String key;
            try {
                key = UTF8Type.instance.getString(row.getKey().getKey());
            } catch (RuntimeException e) {
                key = BytesType.instance.getString(row.getKey().getKey());
            }
            //System.out.printf("PartitionKey: %s, Tombstones(Total): %d (%d)%n", paritionKey, tombstonesCount, columnsCount);
            TombstoneMetric count = new TombstoneMetric(desc.cfname, key, tombstonesCount, columnsCount);
            collector.add(count);
        }
    }
    //System.out.printf("Result: %d tombstones out of total %d columns", totalTombstones, totalColumns);
    scanner.close();
}