Example usage for org.apache.cassandra.io.sstable SSTableSimpleUnsortedWriter close

List of usage examples for org.apache.cassandra.io.sstable SSTableSimpleUnsortedWriter close

Introduction

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

Prototype

@Override
    public void close() throws IOException 

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  v a 2s  .  co 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:net.oneandone.phantomcabinet.SSTableCreator.java

License:Apache License

public static void create(File baseDir, String keyspace, String cf) throws IOException {
    if (!baseDir.exists())
        baseDir.mkdir();//www  .  j  a  v  a  2 s  . c  o m
    SSTableSimpleUnsortedWriter writer = new SSTableSimpleUnsortedWriter(baseDir,
            StorageService.getPartitioner(), keyspace, cf, AsciiType.instance, null, 64);

    writer.newRow(bytes("0"));
    writer.close();
}