Package org.apache.hadoop.hbase.io.hfile
Interface HFileScanner
- All Superinterfaces:
AutoCloseable
,Closeable
,Shipper
- All Known Implementing Classes:
HFileReaderImpl.EncodedScanner
,HFileReaderImpl.HFileScannerImpl
A scanner allows you to position yourself within a HFile and scan through it. It allows you to
reposition yourself as well.
A scanner doesn't always have a key/value that it is pointing to when it is first created and
before seekTo()
/seekTo(ExtendedCell)
are called. In this case,
getKey()
/getValue()
returns null. At most other times, a key and value will be
available. The general pattern is that you position the Scanner using the seekTo variants and
then getKey and getValue.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this HFile scanner and do necessary cleanup.getCell()
Returns Instance ofExtendedCell
.getKey()
Gets the current key in the form of a cell.Returns the next key in the index (the key to seek to the next block)Returns Reader that underlies this Scanner instance.getValue()
Gets a buffer view to the current value.boolean
isSeeked()
boolean
next()
Scans to the next entry in the file.void
recordBlockSize
(IntConsumer blockSizeConsumer) Record the size of the current block in bytes, passing as an argument to the blockSizeConsumer.int
reseekTo
(ExtendedCell cell) Reseek to or just before the passedcell
.boolean
seekBefore
(ExtendedCell cell) Consider the cell stream of all the cells in the file,c[0] ..
boolean
seekTo()
Positions this scanner at the start of the file.int
seekTo
(ExtendedCell cell) SeekTo or just before the passedcell
.
-
Method Details
-
seekTo
SeekTo or just before the passedcell
. Examine the return code to figure whether we found the cell or not. Consider the cell stream of all the cells in the file,c[0] .. c[n]
, where there are n cells in the file.- Returns:
- -1, if cell < c[0], no position; 0, such that c[i] = cell and scanner is left in position i; and 1, such that c[i] < cell, and scanner is left in position i. The scanner will position itself between c[i] and c[i+1] where c[i] < cell <= c[i+1]. If there is no cell c[i+1] greater than or equal to the input cell, then the scanner will position itself at the end of the file and next() will return false when it is called.
- Throws:
IOException
-
reseekTo
Reseek to or just before the passedcell
. Similar to seekTo except that this can be called even if the scanner is not at the beginning of a file. This can be used to seek only to cells which come after the current position of the scanner. Consider the cell stream of all the cells in the file,c[0] .. c[n]
, where there are n cellc in the file after current position of HFileScanner. The scanner will position itself between c[i] and c[i+1] where c[i] < cell <= c[i+1]. If there is no cell c[i+1] greater than or equal to the input cell, then the scanner will position itself at the end of the file and next() will return false when it is called.- Parameters:
cell
- Cell to find (should be non-null)- Returns:
- -1, if cell < c[0], no position; 0, such that c[i] = cell and scanner is left in position i; and 1, such that c[i] < cell, and scanner is left in position i.
- Throws:
IOException
-
seekBefore
Consider the cell stream of all the cells in the file,c[0] .. c[n]
, where there are n cells in the file.- Parameters:
cell
- Cell to find- Returns:
- false if cell <= c[0] or true with scanner in position 'i' such that: c[i] < cell. Furthermore: there may be a c[i+1], such that c[i] < cell <= c[i+1] but there may also NOT be a c[i+1], and next() will return false (EOF).
- Throws:
IOException
-
seekTo
Positions this scanner at the start of the file.- Returns:
- False if empty file; i.e. a call to next would return false and the current key and value are undefined.
- Throws:
IOException
-
next
Scans to the next entry in the file.- Returns:
- Returns false if you are at the end otherwise true if more in file.
- Throws:
IOException
-
getKey
Gets the current key in the form of a cell. You must callseekTo(ExtendedCell)
before this method.- Returns:
- gets the current key as a Cell.
-
getValue
Gets a buffer view to the current value. You must callseekTo(ExtendedCell)
before this method.- Returns:
- byte buffer for the value. The limit is set to the value size, and the position is 0, the start of the buffer view.
-
getCell
Returns Instance ofExtendedCell
. -
getReader
Returns Reader that underlies this Scanner instance. -
isSeeked
boolean isSeeked()- Returns:
- True is scanner has had one of the seek calls invoked; i.e.
seekBefore(ExtendedCell)
orseekTo()
orseekTo(ExtendedCell)
. Otherwise returns false.
-
getNextIndexedKey
Returns the next key in the index (the key to seek to the next block) -
close
void close()Close this HFile scanner and do necessary cleanup.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
recordBlockSize
Record the size of the current block in bytes, passing as an argument to the blockSizeConsumer. Implementations should ensure that blockSizeConsumer is only called once per block.- Parameters:
blockSizeConsumer
- to be called with block size in bytes, once per block.
-