-
Notifications
You must be signed in to change notification settings - Fork 0
/
SeqScan.java
64 lines (54 loc) · 2.06 KB
/
SeqScan.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package simpledb;
import java.util.*;
/**
* SeqScan is an implementation of a sequential scan access method that reads
* each tuple of a table in no particular order (e.g., as they are laid out on
* disk).
*/
public class SeqScan implements DbIterator {
DbFileIterator fileit;
TupleDesc td;
/**
* Creates a sequential scan over the specified table as a part of the
* specified transaction.
*
* @param tid The transaction this scan is running as a part of.
* @param tableid the table to scan.
* @param tableAlias the alias of this table (needed by the parser);
* the returned tupleDesc should have fields with name tableAlias.fieldName
* (note: this class is not responsible for handling a case where tableAlias
* or fieldName are null. It shouldn't crash if they are, but the resulting
* name can be null.fieldName, tableAlias.null, or null.null).
*/
public SeqScan(TransactionId tid, int tableid, String tableAlias) {
fileit = Database.getCatalog().getDbFile(tableid).iterator(tid);
td = Database.getCatalog().getTupleDesc(tableid);
}
public void open()
throws DbException, TransactionAbortedException {
fileit.open();
}
/**
* Returns the TupleDesc with field names from the underlying HeapFile,
* prefixed with the tableAlias string from the constructor.
* @return the TupleDesc with field names from the underlying HeapFile,
* prefixed with the tableAlias string from the constructor.
*/
public TupleDesc getTupleDesc() {
return td;
}
public boolean hasNext() throws TransactionAbortedException, DbException {
return fileit.hasNext();
}
public Tuple next()
throws NoSuchElementException, TransactionAbortedException, DbException {
return fileit.next();
}
public void close() {
fileit.close();
}
public void rewind()
throws DbException, NoSuchElementException, TransactionAbortedException {
fileit.rewind();
}
}