Package org.apache.hadoop.io.file.tfile
Class TFile.Reader.Scanner
java.lang.Object
org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner
- All Implemented Interfaces:
Closeable,AutoCloseable
- Enclosing class:
- TFile.Reader
The TFile Scanner. The Scanner has an implicit cursor, which, upon
creation, points to the first key-value pair in the scan range. If the
scan range is empty, the cursor will point to the end of the scan range.
Use atEnd() to test whether the cursor is at the end
location of the scanner.
Use advance() to move the cursor to the next key-value
pair (or end if none exists). Use seekTo methods (
seekTo(byte[]) or
seekTo(byte[], int, int)) to seek to any arbitrary
location in the covered range (including backward seeking). Use
rewind() to seek back to the beginning of the scanner.
Use seekToEnd() to seek to the end of the scanner.
Actual keys and values may be obtained through TFile.Reader.Scanner.Entry
object, which is obtained through entry().
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedScanner(TFile.Reader reader, long offBegin, long offEnd) ConstructorprotectedScanner(TFile.Reader reader, RawComparable beginKey, RawComparable endKey) Constructor -
Method Summary
Modifier and TypeMethodDescriptionbooleanadvance()Move the cursor to the next key-value pair.booleanatEnd()Is cursor at the end location?voidclose()Close the scanner.entry()Get an entry to access the key and value.longGet the RecordNum corresponding to the entry pointed by the cursor.voidlowerBound(byte[] key) Move the cursor to the first entry whose key is greater than or equal to the input key.voidlowerBound(byte[] key, int keyOffset, int keyLen) Move the cursor to the first entry whose key is greater than or equal to the input key.voidrewind()Rewind to the first entry in the scanner.booleanseekTo(byte[] key) Move the cursor to the first entry whose key is greater than or equal to the input key.booleanseekTo(byte[] key, int keyOffset, int keyLen) Move the cursor to the first entry whose key is greater than or equal to the input key.voidSeek to the end of the scanner.voidupperBound(byte[] key) Move the cursor to the first entry whose key is strictly greater than the input key.voidupperBound(byte[] key, int keyOffset, int keyLen) Move the cursor to the first entry whose key is strictly greater than the input key.
-
Constructor Details
-
Scanner
Constructor- Parameters:
reader- The TFile reader object.offBegin- Begin byte-offset of the scan.offEnd- End byte-offset of the scan.- Throws:
IOException- The offsets will be rounded to the beginning of a compressed block whose offset is greater than or equal to the specified offset.
-
Scanner
protected Scanner(TFile.Reader reader, RawComparable beginKey, RawComparable endKey) throws IOException Constructor- Parameters:
reader- The TFile reader object.beginKey- Begin key of the scan. If null, scan from the first <K, V> entry of the TFile.endKey- End key of the scan. If null, scan up to the last <K, V> entry of the TFile.- Throws:
IOException- raised on errors performing I/O.
-
-
Method Details
-
seekTo
Move the cursor to the first entry whose key is greater than or equal to the input key. Synonymous to seekTo(key, 0, key.length). The entry returned by the previous entry() call will be invalid.- Parameters:
key- The input key- Returns:
- true if we find an equal key.
- Throws:
IOException- raised on errors performing I/O.
-
seekTo
Move the cursor to the first entry whose key is greater than or equal to the input key. The entry returned by the previous entry() call will be invalid.- Parameters:
key- The input keykeyOffset- offset in the key buffer.keyLen- key buffer length.- Returns:
- true if we find an equal key; false otherwise.
- Throws:
IOException- raised on errors performing I/O.
-
rewind
Rewind to the first entry in the scanner. The entry returned by the previous entry() call will be invalid.- Throws:
IOException- raised on errors performing I/O.
-
seekToEnd
Seek to the end of the scanner. The entry returned by the previous entry() call will be invalid.- Throws:
IOException- raised on errors performing I/O.
-
lowerBound
Move the cursor to the first entry whose key is greater than or equal to the input key. Synonymous to lowerBound(key, 0, key.length). The entry returned by the previous entry() call will be invalid.- Parameters:
key- The input key- Throws:
IOException- raised on errors performing I/O.
-
lowerBound
Move the cursor to the first entry whose key is greater than or equal to the input key. The entry returned by the previous entry() call will be invalid.- Parameters:
key- The input keykeyOffset- offset in the key buffer.keyLen- key buffer length.- Throws:
IOException- raised on errors performing I/O.
-
upperBound
Move the cursor to the first entry whose key is strictly greater than the input key. Synonymous to upperBound(key, 0, key.length). The entry returned by the previous entry() call will be invalid.- Parameters:
key- The input key- Throws:
IOException- raised on errors performing I/O.
-
upperBound
Move the cursor to the first entry whose key is strictly greater than the input key. The entry returned by the previous entry() call will be invalid.- Parameters:
key- The input keykeyOffset- offset in the key buffer.keyLen- key buffer length.- Throws:
IOException- raised on errors performing I/O.
-
advance
Move the cursor to the next key-value pair. The entry returned by the previous entry() call will be invalid.- Returns:
- true if the cursor successfully moves. False when cursor is already at the end location and cannot be advanced.
- Throws:
IOException- raised on errors performing I/O.
-
close
Close the scanner. Release all resources. The behavior of using the scanner after calling close is not defined. The entry returned by the previous entry() call will be invalid.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
atEnd
public boolean atEnd()Is cursor at the end location?- Returns:
- true if the cursor is at the end location.
-
entry
Get an entry to access the key and value.- Returns:
- The Entry object to access the key and value.
- Throws:
IOException- raised on errors performing I/O.
-
getRecordNum
Get the RecordNum corresponding to the entry pointed by the cursor.- Returns:
- The RecordNum corresponding to the entry pointed by the cursor.
- Throws:
IOException- raised on errors performing I/O.
-