?? indexjoinscan.java
字號(hào):
package simpledb.index.query;import simpledb.record.RID;import simpledb.query.*;import simpledb.index.Index;/** * The scan class corresponding to the indexjoin relational * algebra operator. * The code is very similar to that of ProductScan, * which makes sense because an index join is essentially * the product of each LHS record with the matching RHS index records. * @author Edward Sciore */public class IndexJoinScan implements RidScan { private Scan s; private Index idx; private String joinfield; /** * Creates an index join scan for the specified LHS scan and * RHS index. * @param s the LHS scan * @param idx the RHS index * @param joinfield the LHS field used for joining */ public IndexJoinScan(Scan s, Index idx, String joinfield) { this.s = s; this.idx = idx; this.joinfield = joinfield; beforeFirst(); } /** * Positions the scan before the first record. * That is, the LHS scan will be positioned at its * first record, and the index will be positioned * before the first record for the join value. * @see simpledb.query.Scan#beforeFirst() */ public void beforeFirst() { s.beforeFirst(); s.next(); resetIndex(); } /** * Moves the scan to the next record. * The method moves to the next index record, if possible. * Otherwise, it moves to the next LHS record and the * first index record. * If there are no more LHS records, the method returns false. * @see simpledb.query.Scan#next() */ public boolean next() { while (true) { if (idx.next()) return true; if (!s.next()) return false; resetIndex(); } } /** * Closes the scan by closing its LHS scan and its RHS index. * @see simpledb.query.Scan#close() */ public void close() { s.close(); idx.close(); } /** * Returns the Constant value of the specified field. * Since the index contains no interesting fields, * the value will be obtained from the LHS scan. * @see simpledb.query.Scan#getVal(java.lang.String) */ public Constant getVal(String fldname) { return s.getVal(fldname); } /** * Returns the integer value of the specified field. * Since the index contains no interesting fields, * the value will be obtained from the LHS scan. * @see simpledb.query.Scan#getVal(java.lang.String) */ public int getInt(String fldname) { return s.getInt(fldname); } /** * Returns the string value of the specified field. * Since the index contains no interesting fields, * the value will be obtained from the LHS scan. * @see simpledb.query.Scan#getVal(java.lang.String) */ public String getString(String fldname) { return s.getString(fldname); } /** Returns true if the field is in the schema. * Since the index has an empty schema, the method * returns the value that the LHS returns. * @see simpledb.query.Scan#hasField(java.lang.String) */ public boolean hasField(String fldname) { return s.hasField(fldname); } /** * Returns the dataRid of the current index record. * @see simpledb.index.query.RidScan#getDataRid() */ public RID getDataRid() { return idx.getDataRid(); } private void resetIndex() { Constant searchkey = s.getVal(joinfield); idx.beforeFirst(searchkey); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -