src/java/org/apache/cassandra/tools/SSTableExport.java
/**
     * Export specific rows from an SSTable and write the resulting JSON to a PrintStream.
     * 
     * @param ssTableFile the SSTableScanner to export the rows from
     * @param outs PrintStream to write the output to
     * @param toExport the keys corresponding to the rows to export
     * @param excludes keys to exclude from export
     * @throws IOException on failure to read/write input/output
     */
Export specific rows from an SSTable and write the resulting JSON to a PrintStream.


Export specific rows from an SSTable and write the resulting JSON to a PrintStream .
public static void export(String ssTableFile, PrintStream outs, Collection<String> toExport, String[] excludes) throws IOException
    {
        SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(ssTableFile));
        SSTableScanner scanner = reader.getDirectScanner();
        IPartitioner<?> partitioner = StorageService.getPartitioner();
        if (excludes != null)
            toExport.removeAll(Arrays.asList(excludes));
        outs.println("{");
        int i = 0;
        DecoratedKey lastKey = null;
        for (String key : toExport)
        {
            DecoratedKey decoratedKey = partitioner.decorateKey(hexToBytes(key));
            if (lastKey != null && lastKey.compareTo(decoratedKey) > 0)
                throw new IOException("Key out of order! " + lastKey + " > " + decoratedKey);
            lastKey = decoratedKey;
            scanner.seekTo(decoratedKey);
            if (!scanner.hasNext())
                continue;
            SSTableIdentityIterator row = (SSTableIdentityIterator) scanner.next();
            if (!row.getKey().equals(decoratedKey))
                continue;
            serializeRow(row, decoratedKey, outs);
            if (i != 0)
                outs.println(",");
            i++;
        }
        outs.println("\n}");
        outs.flush();
        scanner.close();
    }
public static void export ( String ssTableFile , PrintStream outs , Collection < String > toExport , String [ ] excludes ) throws IOException { SSTableReader reader = SSTableReader . open ( Descriptor . fromFilename ( ssTableFile ) ) ; SSTableScanner scanner = reader . getDirectScanner ( ) ; IPartitioner < ? > partitioner = StorageService . getPartitioner ( ) ; if ( excludes != null ) toExport . removeAll ( Arrays . asList ( excludes ) ) ; outs . println ( "{" ) ; int i = 0 ; DecoratedKey lastKey = null ; for ( String key : toExport ) { DecoratedKey decoratedKey = partitioner . decorateKey ( hexToBytes ( key ) ) ; if ( lastKey != null && lastKey . compareTo ( decoratedKey ) > 0 ) throw new IOException ( "Key out of order! " + lastKey + " > " + decoratedKey ) ; lastKey = decoratedKey ; scanner . seekTo ( decoratedKey ) ; if ( ! scanner . hasNext ( ) ) continue ; SSTableIdentityIterator row = ( SSTableIdentityIterator ) scanner . next ( ) ; if ( ! row . getKey ( ) . equals ( decoratedKey ) ) continue ; serializeRow ( row , decoratedKey , outs ) ; if ( i != 0 ) outs . println ( "," ) ; i ++ ; } outs . println ( "\n}" ) ; outs . flush ( ) ; scanner . close ( ) ; }
Export specific rows from an SSTable and write the resulting JSON to a PrintStream.
Export specific rows from an SSTable and write the resulting JSON to a PrintStream .
// last key to compare order