public static void main(String[] args) throws ConfigurationException
    {
        String usage = String.format("Usage: %s <sstable> [-k key [-k key [...]] -x key [-x key [...]]]%n", SSTableExport.class.getName());

        CommandLineParser parser = new PosixParser();
        try
        {
            cmd = parser.parse(options, args);
        }
        catch (ParseException e1)
        {
            System.err.println(e1.getMessage());
            System.err.println(usage);
            System.exit(1);
        }


        if (cmd.getArgs().length != 1)
        {
            System.err.println("You must supply exactly one sstable");
            System.err.println(usage);
            System.exit(1);
        }


        String[] keys = cmd.getOptionValues(KEY_OPTION);
        String[] excludes = cmd.getOptionValues(EXCLUDEKEY_OPTION);
        String ssTableFileName = new File(cmd.getArgs()[0]).getAbsolutePath();

        DatabaseDescriptor.loadSchemas(false);
        Descriptor descriptor = Descriptor.fromFilename(ssTableFileName);

        // Start by validating keyspace name
        if (Schema.instance.getKSMetaData(descriptor.ksname) == null)
        {
            System.err.println(String.format("Filename %s references to nonexistent keyspace: %s!",
                                             ssTableFileName, descriptor.ksname));
            System.exit(1);
        }
        Keyspace keyspace = Keyspace.open(descriptor.ksname);

        // Make it works for indexes too - find parent cf if necessary
        String baseName = descriptor.cfname;
        if (descriptor.cfname.contains("."))
        {
            String[] parts = descriptor.cfname.split("\\.", 2);
            baseName = parts[0];
        }

        // IllegalArgumentException will be thrown here if ks/cf pair does not exist
        ColumnFamilyStore cfStore = null;
        try
        {
            cfStore = keyspace.getColumnFamilyStore(baseName);
        }
        catch (IllegalArgumentException e)
        {
            System.err.println(String.format("The provided column family is not part of this cassandra keyspace: keyspace = %s, column family = %s",
                                             descriptor.ksname, descriptor.cfname));
            System.exit(1);
        }

        try
        {
            if (cmd.hasOption(ENUMERATEKEYS_OPTION))
            {
                enumeratekeys(descriptor, System.out, cfStore.metadata);
            }
            else
            {
                if ((keys != null) && (keys.length > 0))
                    export(descriptor, System.out, Arrays.asList(keys), excludes, cfStore.metadata);
                else
                    export(descriptor, excludes, cfStore.metadata);
            }
        }
        catch (IOException e)
        {
            // throwing exception outside main with broken pipe causes windows cmd to hang
            e.printStackTrace(System.err);
        }

        System.exit(0);
    }
public static void main ( String [ ] args ) throws ConfigurationException { String usage = String . format ( "Usage: %s <sstable> [-k key [-k key [...]] -x key [-x key [...]]]%n" , SSTableExport . class . getName ( ) ) ; CommandLineParser parser = new PosixParser ( ) ; try { cmd = parser . parse ( options , args ) ; } catch ( ParseException e1 ) { System . err . println ( e1 . getMessage ( ) ) ; System . err . println ( usage ) ; System . exit ( 1 ) ; } if ( cmd . getArgs ( ) . length != 1 ) { System . err . println ( "You must supply exactly one sstable" ) ; System . err . println ( usage ) ; System . exit ( 1 ) ; } String [ ] keys = cmd . getOptionValues ( KEY_OPTION ) ; String [ ] excludes = cmd . getOptionValues ( EXCLUDEKEY_OPTION ) ; String ssTableFileName = new File ( cmd . getArgs ( ) [ 0 ] ) . getAbsolutePath ( ) ; DatabaseDescriptor . loadSchemas ( false ) ; Descriptor descriptor = Descriptor . fromFilename ( ssTableFileName ) ; if ( Schema . instance . getKSMetaData ( descriptor . ksname ) == null ) { System . err . println ( String . format ( "Filename %s references to nonexistent keyspace: %s!" , ssTableFileName , descriptor . ksname ) ) ; System . exit ( 1 ) ; } Keyspace keyspace = Keyspace . open ( descriptor . ksname ) ; String baseName = descriptor . cfname ; if ( descriptor . cfname . contains ( "." ) ) { String [ ] parts = descriptor . cfname . split ( "\\." , 2 ) ; baseName = parts [ 0 ] ; } ColumnFamilyStore cfStore = null ; try { cfStore = keyspace . getColumnFamilyStore ( baseName ) ; } catch ( IllegalArgumentException e ) { System . err . println ( String . format ( "The provided column family is not part of this cassandra keyspace: keyspace = %s, column family = %s" , descriptor . ksname , descriptor . cfname ) ) ; System . exit ( 1 ) ; } try { if ( cmd . hasOption ( ENUMERATEKEYS_OPTION ) ) { enumeratekeys ( descriptor , System . out , cfStore . metadata ) ; } else { if ( ( keys != null ) && ( keys . length > 0 ) ) export ( descriptor , System . out , Arrays . asList ( keys ) , excludes , cfStore . metadata ) ; else export ( descriptor , excludes , cfStore . metadata ) ; } } catch ( IOException e ) { e . printStackTrace ( System . err ) ; } System . exit ( 0 ) ; }
Given arguments specifying an SSTable, and optionally an output file,
export the contents of the SSTable to JSON.

@param args command lines arguments
@throws IOException            on failure to open/read/write files or output streams
@throws ConfigurationException on configuration failure (wrong params given)