public class RFileWriter extends Object implements AutoCloseable
TableOperations.importDirectory(String, String, String, boolean)
A RFileWriter has the following constraints. Violating these constraints will result in runtime exceptions.
Below is an example of using RFileWriter
Iterable<Entry<Key, Value>> localityGroup1Data = ...
Iterable<Entry<Key, Value>> localityGroup2Data = ...
Iterable<Entry<Key, Value>> defaultGroupData = ...
try(RFileWriter writer = RFile.newWriter().to(file).build()) {
// Start a locality group before appending data.
writer.startNewLocalityGroup("groupA", "columnFam1", "columnFam2");
// Append data to the locality group that was started above. Must append in sorted order.
writer.append(localityGroup1Data);
// Add another locality group.
writer.startNewLocalityGroup("groupB", "columnFam3", "columnFam4");
writer.append(localityGroup2Data);
// The default locality group must be started last.
// The column families for the default group do not need to be specified.
writer.startDefaultLocalityGroup();
// Data appended here can not contain any
// column families specified in previous locality groups.
writer.append(defaultGroupData);
// This is a try-with-resources so the writer is closed here at the end of the code block.
}
Create instances by calling RFile.newWriter()
Modifier and Type | Method and Description |
---|---|
void |
append(Iterable<Map.Entry<Key,Value>> keyValues)
Append the keys and values to the last locality group that was started.
|
void |
append(Key key,
Value val)
Append the key and value to the last locality group that was started.
|
void |
close() |
void |
startDefaultLocalityGroup()
A locality group in which the column families do not need to specified.
|
void |
startNewLocalityGroup(String name,
byte[]... families)
See javadoc for
startNewLocalityGroup(String, List) |
void |
startNewLocalityGroup(String name,
List<byte[]> families)
Before appending any data, a locality group must be started.
|
void |
startNewLocalityGroup(String name,
Set<String> families)
See javadoc for
startNewLocalityGroup(String, List) . |
void |
startNewLocalityGroup(String name,
String... families)
See javadoc for
startNewLocalityGroup(String, List) . |
public void startNewLocalityGroup(String name, List<byte[]> families) throws IOException
name
- locality group name, used for informational purposesfamilies
- the column families the locality group can containIllegalStateException
- When default locality group already started.IOException
public void startNewLocalityGroup(String name, byte[]... families) throws IOException
startNewLocalityGroup(String, List)
IllegalStateException
- When default locality group already started.IOException
public void startNewLocalityGroup(String name, Set<String> families) throws IOException
startNewLocalityGroup(String, List)
.families
- will be encoded using UTF-8IllegalStateException
- When default locality group already started.IOException
public void startNewLocalityGroup(String name, String... families) throws IOException
startNewLocalityGroup(String, List)
.families
- will be encoded using UTF-8IllegalStateException
- When default locality group already started.IOException
public void startDefaultLocalityGroup() throws IOException
IllegalStateException
- When default locality group already started.IOException
public void append(Key key, Value val) throws IOException
key
- This key must be greater than or equal to the last key appended. For non-default
locality groups, the keys column family must be one of the column families specified
when calling startNewLocalityGroup(). Must be non-null.val
- value to append, must be non-null.IllegalArgumentException
- This is thrown when data is appended out of order OR when the key contains a invalid
visibility OR when a column family is not valid for a locality group.IOException
public void append(Iterable<Map.Entry<Key,Value>> keyValues) throws IOException
keyValues
- The keys must be in sorted order. The first key returned by the iterable must be
greater than or equal to the last key appended. For non-default locality groups, the
keys column family must be one of the column families specified when calling
startNewLocalityGroup(). Must be non-null. If no locality group was started, then the
default group will automatically be started.IllegalArgumentException
- This is thrown when data is appended out of order OR when the key contains a invalid
visibility OR when a column family is not valid for a locality group.IOException
public void close() throws IOException
close
in interface AutoCloseable
IOException
Copyright © 2011–2019 The Apache Software Foundation. All rights reserved.