Package edu.caltech.nanodb.commands
Class DeleteCommand
- java.lang.Object
-
- edu.caltech.nanodb.commands.Command
-
- edu.caltech.nanodb.commands.QueryCommand
-
- edu.caltech.nanodb.commands.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DeleteCommand.TupleRemover
An implementation of the tuple processor interface used by theDeleteCommand
to delete each tuple.-
Nested classes/interfaces inherited from class edu.caltech.nanodb.commands.QueryCommand
QueryCommand.Type
-
-
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.QueryCommand
explain, plan
-
-
Constructor Summary
Constructors Constructor Description DeleteCommand(java.lang.String tableName, Expression whereExpr)
Constructs a new delete command.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getTableName()
Returns the name of the table that this delete command operates on.protected TupleProcessor
getTupleProcessor(EventDispatcher eventDispatcher)
Creates a tuple-processor responsible for dealing with the tuples that are generated by the query command.Expression
getWhereExpr()
Returns the WHERE predicate for this delete command, if specified, ornull
if there is no WHERE predicate.protected void
prepareQueryPlan(NanoDBServer server)
Prepares an execution plan for generating the tuples that this query command will operate on.java.lang.String
toString()
-
Methods inherited from class edu.caltech.nanodb.commands.QueryCommand
execute, setExplain
-
Methods inherited from class edu.caltech.nanodb.commands.Command
getCommandType
-
-
-
-
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.
-
tableInfo
TableInfo tableInfo
-
-
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 tupleswhereExpr
- 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 benull
.- 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, ornull
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 classQueryCommand
- 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 classQueryCommand
- 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 classjava.lang.Object
-
-