Commit ea5ed0ce authored by Donald H. (Donnie) Pinkston, III's avatar Donald H. (Donnie) Pinkston, III
Browse files

Complete implementation of DUMP INDEX command

The DUMP INDEX command now generates a proper execution plan, and can
therefore dump indexes now.
parent 24161f80
Showing with 38 additions and 23 deletions
+38 -23
package edu.caltech.nanodb.commands;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import edu.caltech.nanodb.plannodes.PlanNode;
......@@ -121,31 +122,28 @@ public abstract class DumpCommand extends Command {
@Override
public void execute(NanoDBServer server) throws ExecutionException {
try {
// Figure out where the dumped data should go.
PrintStream dumpOut = out;
if (fileName != null)
// Figure out where the dumped data should go.
PrintStream dumpOut = out;
if (fileName != null) {
try {
dumpOut = new PrintStream(fileName);
}
catch (FileNotFoundException e) {
throw new ExecutionException(e);
}
}
// Dump the table.
PlanNode dumpPlan = prepareDumpPlan(server);
TupleExporter exporter = new TupleExporter(dumpOut);
EvalStats stats = QueryEvaluator.executePlan(dumpPlan, exporter);
// Dump the table.
PlanNode dumpPlan = prepareDumpPlan(server);
TupleExporter exporter = new TupleExporter(dumpOut);
EvalStats stats = QueryEvaluator.executePlan(dumpPlan, exporter);
if (fileName != null)
dumpOut.close();
if (fileName != null)
dumpOut.close();
// Print out the evaluation statistics.
out.printf("Dumped %d rows in %f sec.%n",
stats.getRowsProduced(), stats.getElapsedTimeSecs());
}
catch (ExecutionException e) {
throw e;
}
catch (Exception e) {
throw new ExecutionException(e);
}
// Print out the evaluation statistics.
out.printf("Dumped %d rows in %f sec.%n",
stats.getRowsProduced(), stats.getElapsedTimeSecs());
}
......
package edu.caltech.nanodb.commands;
import edu.caltech.nanodb.indexes.IndexInfo;
import edu.caltech.nanodb.indexes.IndexManager;
import edu.caltech.nanodb.plannodes.FileScanNode;
import edu.caltech.nanodb.plannodes.PlanNode;
import edu.caltech.nanodb.relations.TableInfo;
import edu.caltech.nanodb.server.NanoDBServer;
import edu.caltech.nanodb.storage.TableManager;
/**
......@@ -60,8 +65,20 @@ public class DumpIndexCommand extends DumpCommand {
@Override
protected PlanNode prepareDumpPlan(NanoDBServer server) {
// TODO: Index scan!
return null;
// Open the table so we can open the index.
TableManager tblMgr = server.getStorageManager().getTableManager();
TableInfo tblInfo = tblMgr.openTable(tableName);
// Open the index.
IndexManager idxMgr = server.getStorageManager().getIndexManager();
IndexInfo idxInfo = idxMgr.openIndex(tblInfo, indexName);
// Make a file-scan plan-node over the index.
PlanNode plan = new FileScanNode(idxInfo, null);
plan.prepare();
// Done!
return plan;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment