Class HeapTupleFile

  • All Implemented Interfaces:
    TupleFile

    public class HeapTupleFile
    extends java.lang.Object
    implements TupleFile
    This class implements the TupleFile interface for heap files.
    • 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.
    • 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 the DBFile 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, or null 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
    • 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 interface TupleFile
        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.
        Specified by:
        getSchema in 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 the TupleFile.analyze() method is the intended way of updating a tuple file's statistics.
        Specified by:
        getStats in interface TupleFile
        Returns:
        statistics describing the data in this tuple file.
      • getDBFile

        public DBFile getDBFile()
        Description copied from interface: TupleFile
        Returns the DBFile object that this tuple file is stored in.
        Specified by:
        getDBFile in interface TupleFile
        Returns:
        the DBFile 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 interface TupleFile
        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 interface TupleFile
        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, or null 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 interface TupleFile
        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 interface TupleFile
        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 interface TupleFile
        Parameters:
        tup - the tuple to modify in the table
        newValues - 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 interface TupleFile
        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.
        Specified by:
        analyze in interface TupleFile
      • 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.
        Specified by:
        verify in interface TupleFile
        Returns:
        a list of error-message strings describing issues identified during verification. The list will be empty if the file has no identifiable errors.
      • 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.
        Specified by:
        optimize in interface TupleFile