public class HashEquiJoin extends Operator
Modifier and Type | Field and Description |
---|---|
private DbIterator |
child1 |
private DbIterator |
child2 |
private TupleDesc |
comboTD |
(package private) java.util.Iterator<Tuple> |
listIt |
(package private) java.util.HashMap<java.lang.Object,java.util.ArrayList<Tuple>> |
map |
static int |
MAP_SIZE |
private JoinPredicate |
pred |
private static long |
serialVersionUID |
private Tuple |
t1 |
private Tuple |
t2 |
Constructor and Description |
---|
HashEquiJoin(JoinPredicate p,
DbIterator child1,
DbIterator child2)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this iterator.
|
protected Tuple |
fetchNext()
Returns the next Tuple in the iterator, or null if the iteration is
finished.
|
DbIterator[] |
getChildren() |
java.lang.String |
getJoinField1Name() |
java.lang.String |
getJoinField2Name() |
JoinPredicate |
getJoinPredicate() |
TupleDesc |
getTupleDesc()
Returns the TupleDesc associated with this DbIterator.
|
private boolean |
loadMap() |
void |
open()
Opens the iterator.
|
private Tuple |
processList()
Returns the next tuple generated by the join, or null if there are no
more tuples.
|
void |
rewind()
Resets the iterator to the start.
|
void |
setChildren(DbIterator[] children)
Set the children(child) of this operator.
|
getEstimatedCardinality, hasNext, next, setEstimatedCardinality
private static final long serialVersionUID
private JoinPredicate pred
private DbIterator child1
private DbIterator child2
private TupleDesc comboTD
private transient Tuple t1
private transient Tuple t2
java.util.HashMap<java.lang.Object,java.util.ArrayList<Tuple>> map
public static final int MAP_SIZE
transient java.util.Iterator<Tuple> listIt
public HashEquiJoin(JoinPredicate p, DbIterator child1, DbIterator child2)
p
- The predicate to use to join the childrenchild1
- Iterator for the left(outer) relation to joinchild2
- Iterator for the right(inner) relation to joinpublic JoinPredicate getJoinPredicate()
public TupleDesc getTupleDesc()
DbIterator
getTupleDesc
in interface DbIterator
getTupleDesc
in class Operator
public java.lang.String getJoinField1Name()
public java.lang.String getJoinField2Name()
private boolean loadMap() throws DbException, TransactionAbortedException
public void open() throws DbException, java.util.NoSuchElementException, TransactionAbortedException
DbIterator
open
in interface DbIterator
open
in class Operator
DbException
- when there are problems opening/accessing the database.java.util.NoSuchElementException
TransactionAbortedException
public void close()
Operator
close
in interface DbIterator
close
in class Operator
public void rewind() throws DbException, TransactionAbortedException
DbIterator
DbException
- when rewind is unsupported.TransactionAbortedException
private Tuple processList() throws TransactionAbortedException, DbException
Note that the tuples returned from this particular implementation of Join are simply the concatenation of joining tuples from the left and right relation. Therefore, there will be two copies of the join attribute in the results. (Removing such duplicate columns can be done with an additional projection operator if needed.)
For example, if one tuple is {1,2,3} and the other tuple is {1,5,6}, joined on equality of the first column, then this returns {1,2,3,1,5,6}.
TransactionAbortedException
DbException
JoinPredicate.filter(simpledb.Tuple, simpledb.Tuple)
protected Tuple fetchNext() throws TransactionAbortedException, DbException
Operator
next
and hasNext
.fetchNext
in class Operator
TransactionAbortedException
DbException
public DbIterator[] getChildren()
getChildren
in class Operator
public void setChildren(DbIterator[] children)
Operator
setChildren
in class Operator
children
- the DbIterators which are to be set as the children(child) of
this operator