public interface DataBag<T> extends Sink<T>, Iterable<T>, Closeable
DataBag provides an Iterator interface, that allows callers to read through the contents. The iterators are aware of the data spilling. They have to be able to handle reading from files.
The DataBag interface assumes that all data is written before any is read. That is, a DataBag cannot be used as a queue. If data is written after data is read, the results are undefined. This condition is not checked on each add or read, for reasons of speed. Caveat emptor.
DataBags come in several types, default, sorted, and distinct. The type must be chosen up front, there is no way to convert a bag on the fly. Default data bags do not guarantee any particular order of retrieval for the tuples and may contain duplicate tuples. Sorted data bags guarantee that tuples will be retrieved in order, where "in order" is defined either by the default comparator for Tuple or the comparator provided by the caller when the bag was created. Sorted bags may contain duplicates. Distinct bags do not guarantee any particular order of retrieval, but do guarantee that they will not contain duplicate tuples.
Inspired by Apache Pig
Modifier and Type | Method and Description |
---|---|
void |
add(T t)
Add a tuple to the bag.
|
void |
addAll(Iterable<? extends T> it)
Add contents of an Iterable to the bag.
|
void |
addAll(Iterator<? extends T> it)
Add contents of an Iterator to the bag.
|
boolean |
isDistinct()
Find out if the bag is distinct.
|
boolean |
isSorted()
Find out if the bag is sorted.
|
long |
size()
Get the number of elements in the bag, both in memory and on disk.
|
long size()
boolean isSorted()
boolean isDistinct()
void add(T t)
t
- tuple to add.void addAll(Iterable<? extends T> it)
it
- iterable to add contents of.Licenced under the Apache License, Version 2.0