public class SeqScan implements DbIterator {
private static final long serialVersionUID = 1L;
TransactionId tid;
int tableid;
String tableAlia;
DbFile dbFile;
DbFileIterator dbFileIterator;
/**
* 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) {
// some code goes here
this.tid =tid;
this.tableid = tableid;
this.tableAlia = tableAlias;
dbFile = Database.getCatalog().getDbFile(tableid);
}
/**
* @return
* return the table name of the table the operator scans. This should
* be the actual name of the table in the catalog of the database
* */
public String getTableName() {
return Database.getCatalog().getTableName(tableid);
}
/**
* @return Return the alias of the table this operator scans.
* */
public String getAlias()
{
// some code goes here
return tableAlia;
}
/**
* Reset the tableid, and tableAlias of this operator.
* @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 void reset(int tableid, String tableAlias) {
Database.getCatalog().getTable(tableid).tupleDesc.tableAlias = tableAlias;
// some code goes here
}
public SeqScan(TransactionId tid, int tableid) {
this(tid, tableid, Database.getCatalog().getTableName(tableid));
}
public void open() throws DbException, TransactionAbortedException {
dbFileIterator.open();
}
/**
* Returns the TupleDesc with field names from the underlying HeapFile,
* prefixed with the tableAlias string from the constructor. This prefix
* becomes useful when joining tables containing a field(s) with the same
* name.
*
* @return the TupleDesc with field names from the underlying HeapFile,
* prefixed with the tableAlias string from the constructor.
*/
public TupleDesc getTupleDesc() {
// some code goes here
return Database.getCatalog().getTupleDesc(tableid);
}
public boolean hasNext() throws TransactionAbortedException, DbException {
// some code goes here
return dbFileIterator.hasNext();
}
public Tuple next() throws NoSuchElementException,
TransactionAbortedException, DbException {
return dbFileIterator.next();
}
public void close() {
// some code goes here
dbFileIterator=null;
}
public void rewind() throws DbException, NoSuchElementException,
TransactionAbortedException {
// some code goes here
}
}
2.6. Operators
最新推荐文章于 2025-08-08 00:05:28 发布