public class CQLSSTableWriter
extends java.lang.Object
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();
Modifier and Type | Class and Description |
---|---|
static class |
CQLSSTableWriter.Builder
A Builder for a CQLSSTableWriter object.
|
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.
|
public static CQLSSTableWriter.Builder builder()
public CQLSSTableWriter addRow(java.lang.Object... values) throws InvalidRequestException, java.io.IOException
This is a shortcut for addRow(Arrays.asList(values))
.
values
- the row values (corresponding to the bind variables of the
insertion statement used when creating by this writer).InvalidRequestException
java.io.IOException
public CQLSSTableWriter addRow(java.util.List<java.lang.Object> values) throws InvalidRequestException, java.io.IOException
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.
values
- the row values (corresponding to the bind variables of the
insertion statement used when creating by this writer).InvalidRequestException
java.io.IOException
public CQLSSTableWriter addRow(java.util.Map<java.lang.String,java.lang.Object> values) throws InvalidRequestException, java.io.IOException
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.
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.InvalidRequestException
java.io.IOException
public CQLSSTableWriter rawAddRow(java.nio.ByteBuffer... values) throws InvalidRequestException, java.io.IOException
values
- the row values (corresponding to the bind variables of the
insertion statement used when creating by this writer) as binary.InvalidRequestException
java.io.IOException
public CQLSSTableWriter rawAddRow(java.util.List<java.nio.ByteBuffer> values) throws InvalidRequestException, java.io.IOException
This is a shortcut for rawAddRow(Arrays.asList(values))
.
values
- the row values (corresponding to the bind variables of the
insertion statement used when creating by this writer) as binary.InvalidRequestException
java.io.IOException
public CQLSSTableWriter rawAddRow(java.util.Map<java.lang.String,java.nio.ByteBuffer> values) throws InvalidRequestException, java.io.IOException
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.
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.InvalidRequestException
java.io.IOException
public void close() throws java.io.IOException
This method should be called, otherwise the produced sstables are not guaranteed to be complete (and won't be in practice).
java.io.IOException
Copyright © 2013 The Apache Software Foundation