public class TableWriter
extends java.lang.Object
The static methods write and writeWithTempStorage are all you need
to write an Iterable or Iterator of key-value
Pairs to a directory, given a config.
The minimum config is just the key serializer - see TableConfig for
details. Example:
final TableConfig<Long, Long> config =
new TableConfig()
.withKeySerializer(new SmartLongSerializer())
.withValueSerializer(new SmartVLongSerializer());
final Set<Pair<Long, Long>> entries = new HashSet<>();
for (long i = 0; i < 20; ++i) {
entries.add(new Pair(i, i * i));
}
TableWriter.write(new File("squares"), config, entries);
As a convenience, the main method lets you build tables from TSV files:
java com.indeed.recommend.common.platform.mph.TableWriter [options] output_dir input.tsv...
where options are:
--separator: separator to use instead of tab --keySerializer: full class name of the key serializer (default .SmartStringSerializer) --valueSerializer: full class name of the value serializer (default .SmartStringSerializer) --keyStorage: set to IMPLICIT to remove keys from table --offsetStorage: override the default choice --rangeChecking: set to AUTOMATIC to enable tracking of min/max keys --maxHeapUsage: the limit beyond which offsets are mmapped instead of being stored in the heap --signatureWidth: bits per key to use in a bloom filter (required for IMPLICIT keyStorage)
Serializers in the com.indeed.mph.serializers package can be abbreviated with a leading ".", e.g. ".SmartStringSerializer".
The serializer syntax also allows simple expressions of the form Class(args...), notably useful for generic serializers, e.g.:
".SmartListSerializer(.SmartLongSerializer, 20)"
is a serializer for lists of up to 20 Longs.
| Modifier and Type | Class and Description |
|---|---|
static class |
TableWriter.PairFirstIterable<K,V> |
static class |
TableWriter.PairFirstIterator<K,V> |
static class |
TableWriter.PairFirstRangeTrackingIterable<K extends java.lang.Comparable<K>,V> |
static class |
TableWriter.PairFirstRangeTrackingIterator<K extends java.lang.Comparable<K>,V> |
static class |
TableWriter.SerializedKeyValueIterable<K,V> |
static class |
TableWriter.SerializerTransformationStrategy<K> |
static class |
TableWriter.TsvFileReader<K,V> |
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_TEMP_SHARDS |
| Modifier and Type | Method and Description |
|---|---|
static void |
ensureOutputDirectory(java.io.File outputDir) |
static void |
main(java.lang.String[] args) |
static SmartSerializer<java.lang.Object> |
parseSerializer(java.lang.String name) |
static <K,V> void |
write(java.io.File outputDir,
TableConfig<K,V> config,
java.lang.Iterable<com.indeed.util.core.Pair<K,V>> entries)
Constructs and writes a minimal perfect hash table to
outputDir.
|
static <K,V> void |
write(java.io.File outputDir,
TableConfig<K,V> config,
java.lang.Iterable<com.indeed.util.core.Pair<K,V>> entries,
long dataSize)
As above, with a pre-computed dataSize.
|
static <K,V> void |
writeWithTempStorage(java.io.File outputDir,
TableConfig<K,V> config,
java.util.Iterator<com.indeed.util.core.Pair<K,V>> entries)
As above, using the outputDir for temp storage.
|
static <K,V> void |
writeWithTempStorage(java.io.File outputDir,
TableConfig<K,V> config,
java.util.Iterator<com.indeed.util.core.Pair<K,V>> entries,
java.io.File tempDir)
As above, using a one-time iterator.
|
public static final int MAX_TEMP_SHARDS
public static <K,V> void write(java.io.File outputDir,
TableConfig<K,V> config,
java.lang.Iterable<com.indeed.util.core.Pair<K,V>> entries)
throws java.io.IOException
K - key typeV - value typeoutputDir - directory to write the hash table files toconfig - a TableConfig specifying at least a key serializerentries - an iterable of key-value Pairs representing entries in the tablejava.io.IOException - if unable to write the files or serialize the datapublic static <K,V> void write(java.io.File outputDir,
TableConfig<K,V> config,
java.lang.Iterable<com.indeed.util.core.Pair<K,V>> entries,
long dataSize)
throws java.io.IOException
K - key typeV - value typeoutputDir - directory to write the hash table files toconfig - a TableConfig specifying at least a key serializerentries - an iterable of key-value Pairs representing entries in the tabledataSize - the final size of the raw serialized data in the table
(omitting keys if using implicit storage, and omitting values if not used)java.io.IOException - if unable to write the files or serialize the datapublic static <K,V> void writeWithTempStorage(java.io.File outputDir,
TableConfig<K,V> config,
java.util.Iterator<com.indeed.util.core.Pair<K,V>> entries,
java.io.File tempDir)
throws java.io.IOException
K - key typeV - value typeoutputDir - directory to write the hash table files toconfig - a TableConfig specifying at least a key serializerentries - an iterable of key-value Pairs representing entries in the tabletempDir - directory to write temporary files tojava.io.IOException - if unable to write the files or serialize the datapublic static <K,V> void writeWithTempStorage(java.io.File outputDir,
TableConfig<K,V> config,
java.util.Iterator<com.indeed.util.core.Pair<K,V>> entries)
throws java.io.IOException
K - key typeV - value typeoutputDir - directory to write the hash table files toconfig - a TableConfig specifying at least a key serializerentries - an iterable of key-value Pairs representing entries in the tablejava.io.IOException - if unable to write the files or serialize the datapublic static void ensureOutputDirectory(java.io.File outputDir)
throws java.io.IOException
java.io.IOExceptionpublic static SmartSerializer<java.lang.Object> parseSerializer(java.lang.String name) throws java.io.IOException
java.io.IOExceptionpublic static void main(java.lang.String[] args)
throws java.io.IOException
java.io.IOExceptionCopyright © 2018. All Rights Reserved.