Class DeleteCommand


  • public class DeleteCommand
    extends QueryCommand

    This command object represents a top-level DELETE command issued against the database. DELETE commands are pretty simple, having a single form: DELETE FROM ... [WHERE ...].

    Execution of this command is relatively straightforward; the only nuance is that we can treat it as a "select for deletion", and possibly perform the deletion in an optimized manner (particularly if the WHERE clause contains subqueries). Internally, we treat it as a SELECT, and each row returned is deleted from the specified table.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) TableInfo tableInfo  
      private java.lang.String tableName
      The name of the table that the data will be deleted from.
      private Expression whereExpr
      If a WHERE expression is specified, this field will refer to the expression to be evaluated.
      • Fields inherited from class edu.caltech.nanodb.commands.Command

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      DeleteCommand​(java.lang.String tableName, Expression whereExpr)
      Constructs a new delete command.
    • Field Detail

      • tableName

        private java.lang.String tableName
        The name of the table that the data will be deleted from.
      • whereExpr

        private Expression whereExpr
        If a WHERE expression is specified, this field will refer to the expression to be evaluated.
    • Constructor Detail

      • DeleteCommand

        public DeleteCommand​(java.lang.String tableName,
                             Expression whereExpr)
        Constructs a new delete command.
        Parameters:
        tableName - the name of the table from which we will be deleting tuples
        whereExpr - the predicate governing which rows will be deleted
    • Method Detail

      • getTableName

        public java.lang.String getTableName()
        Returns the name of the table that this delete command operates on. This should never be null.
        Returns:
        the name of the table that this delete command operates on.
      • getWhereExpr

        public Expression getWhereExpr()
        Returns the WHERE predicate for this delete command, if specified, or null if there is no WHERE predicate.
        Returns:
        the WHERE predicate for this delete command, if specified, or null if there is no WHERE predicate.
      • prepareQueryPlan

        protected void prepareQueryPlan​(NanoDBServer server)
        Description copied from class: QueryCommand
        Prepares an execution plan for generating the tuples that this query command will operate on. Since the specific plan to generate depends on the operation being performed, this is an abstract method to be implemented by subclasses. For example, SELECTs support very sophisticated operations and thus require complex plans, but a DELETE operation simply requires a scan over a tuple file, perhaps with a predicate applied.
        Specified by:
        prepareQueryPlan in class QueryCommand
        Parameters:
        server - the server to use for planning, fetching table schemas, statistics, and other details relevant for planning
      • getTupleProcessor

        protected TupleProcessor getTupleProcessor​(EventDispatcher eventDispatcher)
        Description copied from class: QueryCommand
        Creates a tuple-processor responsible for dealing with the tuples that are generated by the query command. Depending on the operation being performed, different tuple-processors are appropriate. For example, the SELECT processor sends the tuples to the console or to a remote client; the DELETE processor deletes the tuples from the referenced table.
        Specified by:
        getTupleProcessor in class QueryCommand
        Parameters:
        eventDispatcher - used for notifying other components in the database when rows are inserted/updated/deleted
        Returns:
        the tuple processor to use in processing tuples generated by the query
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object