public class TableReader<K,V>
extends java.lang.Object
implements java.io.Closeable, java.lang.Iterable<com.indeed.util.core.Pair<K,V>>
Example:
try (final TableReader<KeyClass, ValueClass> reader = TableReader.open(dir)) {
final ValueClass value = reader.get(key);
}
As a convenience, the main method lets you query existing tables from the command line:
java com.indeed.mph.TableReader [options] table_dir [keys.txt]
where options are
--info: print the meta info --dump: print the key/values of the entire table as TSV --hash: print only the hash value for each key --offset: print only the data offset for each key --get key: print the value for a specific key --random: print the value for a randomly generated long
otherwise prints all values for the associated keys taken from keys.txt (defaulting to stdin). Additional options useful for benchmarking are:
--time: print the time taken to finish all reads --quiet: don't actually print the values --repeat n: repeat the read n times --threads n: duplicate all reads simultaneously among n threads
| Modifier and Type | Class and Description |
|---|---|
class |
TableReader.TableIterator |
static class |
TableReader.TableStats |
| Constructor and Description |
|---|
TableReader(TableMeta<K,V> meta,
byte[] rawData) |
TableReader(TableMeta<K,V> meta,
com.indeed.util.mmap.MMapBuffer data,
com.indeed.util.mmap.MMapBuffer offsets) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
boolean |
containsKey(K key) |
V |
get(K key) |
TableConfig<K,V> |
getConfig() |
V |
getForHash(long hash) |
long |
getHash(K key) |
long |
getHashOffset(long hash) |
K |
getKeyForHash(long hash) |
com.indeed.util.mmap.MemoryDataInput |
getMemoryForHash(long hash) |
TableMeta<K,V> |
getMeta() |
long |
getOffset(K key) |
long |
getSizeInBytes() |
TableReader.TableStats |
getStats() |
long |
getTimestamp() |
boolean |
isDiskBased() |
TableReader.TableIterator |
iterator() |
static void |
main(java.lang.String[] args) |
static <K,V> TableReader<K,V> |
open(java.io.File metaPath) |
static <K,V> TableReader<K,V> |
open(java.io.File metaPath,
java.io.File offsetsPath,
java.io.File dataPath) |
static <K,V> TableReader<K,V> |
open(java.io.File metaPath,
java.io.File offsetsPath,
java.io.File dataPath,
java.lang.Long maxDataHeapUsage)
General interface to opening a TableReader.
|
static <K,V> TableReader<K,V> |
open(java.io.File metaPath,
java.lang.Long maxDataHeapUsage) |
static <K,V> TableReader<K,V> |
open(java.lang.String metaPath) |
static <K,V> TableReader<K,V> |
open(java.lang.String metaPath,
java.lang.Long maxDataHeapUsage) |
long |
size() |
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic static <K,V> TableReader<K,V> open(@Nonnull java.io.File metaPath, @Nullable java.io.File offsetsPath, @Nullable java.io.File dataPath, @Nullable java.lang.Long maxDataHeapUsage) throws java.io.IOException
K - key typeV - value typemetaPath - path to the table's meta-data, either the exact file or the containing directoryoffsetsPath - path to the raw offsets if different from the meta-data settingdataPath - path to the raw serialized data if different from the meta-data settingmaxDataHeapUsage - if specified and positive, raw data less than this size will be
stored directly in the heap instead of mmapedjava.io.IOException - if unable to open any of the files, or deserialize the metadatapublic static <K,V> TableReader<K,V> open(@Nonnull java.io.File metaPath, @Nullable java.io.File offsetsPath, @Nullable java.io.File dataPath) throws java.io.IOException
java.io.IOExceptionpublic static <K,V> TableReader<K,V> open(@Nonnull java.io.File metaPath, @Nullable java.lang.Long maxDataHeapUsage) throws java.io.IOException
java.io.IOExceptionpublic static <K,V> TableReader<K,V> open(@Nonnull java.io.File metaPath) throws java.io.IOException
java.io.IOExceptionpublic static <K,V> TableReader<K,V> open(@Nonnull java.lang.String metaPath) throws java.io.IOException
java.io.IOExceptionpublic static <K,V> TableReader<K,V> open(@Nonnull java.lang.String metaPath, @Nullable java.lang.Long maxDataHeapUsage) throws java.io.IOException
java.io.IOExceptionpublic boolean isDiskBased()
public TableConfig<K,V> getConfig()
public TableReader.TableStats getStats()
public boolean containsKey(@Nonnull
K key)
public com.indeed.util.mmap.MemoryDataInput getMemoryForHash(long hash)
throws java.io.IOException
java.io.IOExceptionpublic K getKeyForHash(long hash) throws java.io.IOException
java.io.IOExceptionpublic V getForHash(long hash) throws java.io.IOException
java.io.IOExceptionpublic long getHash(@Nonnull
K key)
public long getOffset(@Nonnull
K key)
public long getHashOffset(long hash)
public long size()
public long getSizeInBytes()
public long getTimestamp()
public TableReader.TableIterator iterator()
public static void main(java.lang.String[] args)
throws java.io.IOException,
java.lang.InterruptedException
java.io.IOExceptionjava.lang.InterruptedExceptionCopyright © 2018. All Rights Reserved.