CQLSSTableWriter (apache-cassandra API)
Date: 2014-10-21

org.apache.cassandra.io.sstable

## Class CQLSSTableWriter

- java.lang.Object
- - org.apache.cassandra.io.sstable.CQLSSTableWriter

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

      public class CQLSSTableWriter
      extends java.lang.Object
      implements java.io.Closeable

  Utility to write SSTables.

  Typical usage looks like:

         String schema = "CREATE TABLE myKs.myTable ("
                       + "  k int PRIMARY KEY,"
                       + "  v1 text,"
                       + "  v2 int"
                       + ")";
         String insert = "INSERT INTO myKs.myTable (k, v1, v2) VALUES (?, ?, ?)";

         // Creates a new writer. You need to provide at least the directory where to write the created sstable,
         // the schema for the sstable to write and a (prepared) insert statement to use. If you do not use the
         // default partitioner (Murmur3Partitioner), you will also need to provide the partitioner in use, see
         // CQLSSTableWriter.Builder for more details on the available options.
         CQLSSTableWriter writer = CQLSSTableWriter.builder()
                                                   .inDirectory("path/to/directory")
                                                   .forTable(schema)
                                                   .using(insert).build();

         // Adds a nember of rows to the resulting sstable
         writer.addRow(0, "test1", 24);
         writer.addRow(1, "test2", null);
         writer.addRow(2, "test3", 42);

         // Close the writer, finalizing the sstable
         writer.close();

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `CQLSSTableWriter.Builder` A Builder for a CQLSSTableWriter object.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `CQLSSTableWriter` | `addRow(java.util.List<java.lang.Object> values)` Adds a new row to the writer.
    `CQLSSTableWriter` | `addRow(java.util.Map<java.lang.String,java.lang.Object> values)` Adds a new row to the writer.
    `CQLSSTableWriter` | `addRow(java.lang.Object... values)` Adds a new row to the writer.
    `static CQLSSTableWriter.Builder` | `builder()` Returns a new builder for a CQLSSTableWriter.
    `void` | `close()` Close this writer.
    `CQLSSTableWriter` | `rawAddRow(java.nio.ByteBuffer... values)` Adds a new row to the writer given already serialized values.
    `CQLSSTableWriter` | `rawAddRow(java.util.List<java.nio.ByteBuffer> values)` Adds a new row to the writer given already serialized values.
    `CQLSSTableWriter` | `rawAddRow(java.util.Map<java.lang.String,java.nio.ByteBuffer> values)` Adds a new row to the writer given already serialized values.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### builder

          public static CQLSSTableWriter.Builder builder()

      Returns a new builder for a CQLSSTableWriter.
      Returns:
        the new builder.

    - #### addRow

          public CQLSSTableWriter addRow(java.lang.Object... values)
                                  throws InvalidRequestException,
                                         java.io.IOException

      Adds a new row to the writer.

      This is a shortcut for `addRow(Arrays.asList(values))`.

      Parameters:
        `values` - the row values (corresponding to the bind variables of the insertion statement used when creating by this writer).
      Returns:
        this writer.
      Throws:
        `InvalidRequestException`
        `java.io.IOException`

    - #### addRow

          public CQLSSTableWriter addRow(java.util.List<java.lang.Object> values)
                                  throws InvalidRequestException,
                                         java.io.IOException

      Adds a new row to the writer.

      Each provided value type should correspond to the types of the CQL column the value is for. The correspondance between java type and CQL type is the same one than the one documented at www.datastax.com/drivers/java/2.0/apidocs/com/datastax/driver/core/DataType.Name.html#asJavaClass().

      If you prefer providing the values directly as binary, use `rawAddRow(java.nio.ByteBuffer...)` instead.

      Parameters:
        `values` - the row values (corresponding to the bind variables of the insertion statement used when creating by this writer).
      Returns:
        this writer.
      Throws:
        `InvalidRequestException`
        `java.io.IOException`

    - #### addRow

          public CQLSSTableWriter addRow(java.util.Map<java.lang.String,java.lang.Object> values)
                                  throws InvalidRequestException,
                                         java.io.IOException

      Adds a new row to the writer.

      This is equivalent to the other addRow methods, but takes a map whose keys are the names of the columns to add instead of taking a list of the values in the order of the insert statement used during construction of this write.

      Please note that the column names in the map keys must be in lowercase unless the declared column name is a case-sensitive quoted identifier (in which case the map key must use the exact case of the column).

      Parameters:
        `values` - a map of colum name to column values representing the new row to add. Note that if a column is not part of the map, it's value will be `null`. If the map contains keys that does not correspond to one of the column of the insert statement used when creating this writer, the the corresponding value is ignored.
      Returns:
        this writer.
      Throws:
        `InvalidRequestException`
        `java.io.IOException`

    - #### rawAddRow

          public CQLSSTableWriter rawAddRow(java.nio.ByteBuffer... values)
                                     throws InvalidRequestException,
                                            java.io.IOException

      Adds a new row to the writer given already serialized values.
      Parameters:
        `values` - the row values (corresponding to the bind variables of the insertion statement used when creating by this writer) as binary.
      Returns:
        this writer.
      Throws:
        `InvalidRequestException`
        `java.io.IOException`

    - #### rawAddRow

          public CQLSSTableWriter rawAddRow(java.util.List<java.nio.ByteBuffer> values)
                                     throws InvalidRequestException,
                                            java.io.IOException

      Adds a new row to the writer given already serialized values.

      This is a shortcut for `rawAddRow(Arrays.asList(values))`.

      Parameters:
        `values` - the row values (corresponding to the bind variables of the insertion statement used when creating by this writer) as binary.
      Returns:
        this writer.
      Throws:
        `InvalidRequestException`
        `java.io.IOException`

    - #### rawAddRow

          public CQLSSTableWriter rawAddRow(java.util.Map<java.lang.String,java.nio.ByteBuffer> values)
                                     throws InvalidRequestException,
                                            java.io.IOException

      Adds a new row to the writer given already serialized values.

      This is equivalent to the other rawAddRow methods, but takes a map whose keys are the names of the columns to add instead of taking a list of the values in the order of the insert statement used during construction of this write.

      Parameters:
        `values` - a map of colum name to column values representing the new row to add. Note that if a column is not part of the map, it's value will be `null`. If the map contains keys that does not correspond to one of the column of the insert statement used when creating this writer, the the corresponding value is ignored.
      Returns:
        this writer.
      Throws:
        `InvalidRequestException`
        `java.io.IOException`

    - #### close

          public void close()
                     throws java.io.IOException

      Close this writer.

      This method should be called, otherwise the produced sstables are not guaranteed to be complete (and won't be in practice).

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Throws:
        `java.io.IOException`

Copyright © 2014 The Apache Software Foundation