📄 lookupscan.java
字号:
package simpledb.index.query;import simpledb.record.RID;import simpledb.query.*;/** * The scan class corresponding to the lookup relational * algebra operator. * @author Edward Sciore */public class LookupScan implements Scan { private RidScan rs; private TableScan ts; /** * Creates a lookup scan for the specified rid-scan * and table scan. * Note that the table scan is <i>not</i> used for scanning. * Instead, records from the table scan will be read * by looking up their RIDs. * @param rs the rid-scan * @param ts the table scan */ public LookupScan(RidScan rs, TableScan ts) { this.rs = rs; this.ts = ts; beforeFirst(); } /** * Positions the scan before the first record, which * in this case is before the first rid-scan record. * @see simpledb.query.Scan#beforeFirst() */ public void beforeFirst() { rs.beforeFirst(); } /** * Moves to the next rid-scan record. * If there is such a record, then get the dataRid * of that record and read in the corresponding * record from the table scan. * @see simpledb.query.Scan#next() */ public boolean next() { boolean ok = rs.next(); if (ok) { RID rid = rs.getDataRid(); ts.moveToRid(rid); } return ok; } /** * Closes the scan by closing the rid-scan and the table scan. * @see simpledb.query.Scan#close() */ public void close() { rs.close(); ts.close(); } /** * Returns the Constant value of the specified field. * This value will come either from the current * rid-scan record or from the looked-up * table scan record. * @see simpledb.query.Scan#getVal(java.lang.String) */ public Constant getVal(String fldname) { if (ts.hasField(fldname)) return ts.getVal(fldname); else return rs.getVal(fldname); } /** * Returns the integer value of the specified field. * This value will come either from the current * rid-scan record or from the looked-up * table scan record. * @see simpledb.query.Scan#getVal(java.lang.String) */ public int getInt(String fldname) { if (ts.hasField(fldname)) return ts.getInt(fldname); else return rs.getInt(fldname); } /** * Returns the string value of the specified field. * This value will come either from the current * rid-scan record or from the looked-up * table scan record. * @see simpledb.query.Scan#getVal(java.lang.String) */ public String getString(String fldname) { if (ts.hasField(fldname)) return ts.getString(fldname); else return rs.getString(fldname); } /** * Returns true if the specified field is in * either the rid-scan or the table scan. * @see simpledb.query.Scan#hasField(java.lang.String) */ public boolean hasField(String fldname) { return ts.hasField(fldname) || rs.hasField(fldname); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -