Class HeapTupleFile
- java.lang.Object
-
- edu.caltech.nanodb.storage.heapfile.HeapTupleFile
-
-
Field Summary
Fields Modifier and Type Field Description private DBFile
dbFile
The file that stores the tuples.private HeapTupleFileManager
heapFileManager
The manager for heap tuple files provides some higher-level operations such as saving the metadata of a heap tuple file, so it's useful to have a reference to it.private static org.apache.logging.log4j.Logger
logger
A logging object for reporting anything interesting that happens.private Schema
schema
The schema of tuples in this tuple file.private TableStats
stats
Statistics for this tuple file.private StorageManager
storageManager
The storage manager to use for reading and writing file pages, pinning and unpinning pages, write-ahead logging, and so forth.
-
Constructor Summary
Constructors Constructor Description HeapTupleFile(StorageManager storageManager, HeapTupleFileManager heapFileManager, DBFile dbFile, Schema schema, TableStats stats)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tuple
addTuple(Tuple tup)
Adds the specified tuple into the table file.void
analyze()
Analyzes the tuple data in the file, updating the file's statistics.void
deleteTuple(Tuple tup)
Deletes the specified tuple from the table.DBFile
getDBFile()
Returns theDBFile
object that this tuple file is stored in.Tuple
getFirstTuple()
Returns the first tuple in this table file, or null if there are no tuples in the file.TupleFileManager
getManager()
Returns the manager class for this kind of tuple file.Tuple
getNextTuple(Tuple tup)
Returns the tuple that follows the specified tuple, ornull
if there are no more tuples in the file.Schema
getSchema()
Returns the schema of tuples stored in this tuple file.TableStats
getStats()
Returns statistics describing the data in this tuple file.Tuple
getTuple(FilePointer fptr)
Returns the tuple corresponding to the specified file pointer.void
optimize()
Optimizes the tuple file's layout or other characteristics to ensure optimal performance and space usage.void
updateTuple(Tuple tup, java.util.Map<java.lang.String,java.lang.Object> newValues)
Modifies the values in the specified tuple.java.util.List<java.lang.String>
verify()
Verifies the tuple file's internal storage format, identifying any potential structural errors in the file.
-
-
-
Field Detail
-
logger
private static org.apache.logging.log4j.Logger logger
A logging object for reporting anything interesting that happens.
-
storageManager
private StorageManager storageManager
The storage manager to use for reading and writing file pages, pinning and unpinning pages, write-ahead logging, and so forth.
-
heapFileManager
private HeapTupleFileManager heapFileManager
The manager for heap tuple files provides some higher-level operations such as saving the metadata of a heap tuple file, so it's useful to have a reference to it.
-
schema
private Schema schema
The schema of tuples in this tuple file.
-
stats
private TableStats stats
Statistics for this tuple file.
-
dbFile
private DBFile dbFile
The file that stores the tuples.
-
-
Constructor Detail
-
HeapTupleFile
HeapTupleFile(StorageManager storageManager, HeapTupleFileManager heapFileManager, DBFile dbFile, Schema schema, TableStats stats)
-
-
Method Detail
-
getManager
public TupleFileManager getManager()
Description copied from interface:TupleFile
Returns the manager class for this kind of tuple file.- Specified by:
getManager
in interfaceTupleFile
- Returns:
- the manager class for this kind of tuple file.
-
getSchema
public Schema getSchema()
Description copied from interface:TupleFile
Returns the schema of tuples stored in this tuple file.
-
getStats
public TableStats getStats()
Description copied from interface:TupleFile
Returns statistics describing the data in this tuple file. Note that there is no corresponding "set-stats" method, because theTupleFile.analyze()
method is the intended way of updating a tuple file's statistics.
-
getDBFile
public DBFile getDBFile()
Description copied from interface:TupleFile
Returns theDBFile
object that this tuple file is stored in.
-
getFirstTuple
public Tuple getFirstTuple()
Returns the first tuple in this table file, or null if there are no tuples in the file.- Specified by:
getFirstTuple
in interfaceTupleFile
- Returns:
- the first tuple, or null if the table is empty
-
getTuple
public Tuple getTuple(FilePointer fptr) throws InvalidFilePointerException
Returns the tuple corresponding to the specified file pointer. This method is used by many other operations in the database, such as indexes.- Specified by:
getTuple
in interfaceTupleFile
- Parameters:
fptr
- a file-pointer specifying the tuple to retrieve- Returns:
- the tuple referenced by fptr
- Throws:
InvalidFilePointerException
- if the specified file-pointer doesn't actually point to a real tuple.
-
getNextTuple
public Tuple getNextTuple(Tuple tup)
Returns the tuple that follows the specified tuple, ornull
if there are no more tuples in the file. This method must operate correctly regardless of whether the input tuple is pinned or unpinned.- Specified by:
getNextTuple
in interfaceTupleFile
- Parameters:
tup
- the "previous tuple" that specifies where to start looking for the next tuple- Returns:
- the tuple following the previous tuple, or
null
if the previous tuple is the last one in the table
-
addTuple
public Tuple addTuple(Tuple tup)
Adds the specified tuple into the table file. A new HeapFilePageTuple object corresponding to the tuple is returned.- Specified by:
addTuple
in interfaceTupleFile
- Parameters:
tup
- a tuple object containing the values to add to the table- Returns:
- a tuple object actually backed by this table
- Code Review:
- (donnie) This could be made a little more space-efficient. Right now when computing the required space, we assume that we will always need a new slot entry, whereas the page may contain empty slots. (Note that we don't always create a new slot when adding a tuple; we will reuse an empty slot. This inefficiency is simply in estimating the size required for the new tuple.)
-
updateTuple
public void updateTuple(Tuple tup, java.util.Map<java.lang.String,java.lang.Object> newValues)
Description copied from interface:TupleFile
Modifies the values in the specified tuple.- Specified by:
updateTuple
in interfaceTupleFile
- Parameters:
tup
- the tuple to modify in the tablenewValues
- a map containing the name/value pairs to use to update the tuple. Values in this map will be coerced to the column-type of the specified columns. Only the columns being modified need to be specified in this collection.- Code Review:
- (donnie) This method will fail if a tuple is modified in a way that requires more space than is currently available in the data page. One solution would be to move the tuple to a different page and then perform the update, but that would cause all kinds of additional issues. So, if the page runs out of data, oh well.
-
deleteTuple
public void deleteTuple(Tuple tup)
Description copied from interface:TupleFile
Deletes the specified tuple from the table.- Specified by:
deleteTuple
in interfaceTupleFile
- Parameters:
tup
- the tuple to delete from the table
-
analyze
public void analyze()
Description copied from interface:TupleFile
Analyzes the tuple data in the file, updating the file's statistics.
-
verify
public java.util.List<java.lang.String> verify()
Description copied from interface:TupleFile
Verifies the tuple file's internal storage format, identifying any potential structural errors in the file. Errors are returned as a list of error-message strings, each one reporting some error that was found.
-
optimize
public void optimize()
Description copied from interface:TupleFile
Optimizes the tuple file's layout or other characteristics to ensure optimal performance and space usage. Tuple file formats that don't provide any optimization capabilities can simply return when this is called.
-
-