diff --git a/src/main/java/edu/caltech/nanodb/commands/DumpCommand.java b/src/main/java/edu/caltech/nanodb/commands/DumpCommand.java index d08a69227052a2c400f3178e5df777102cabd089..e0d49c38744cd9de9aadf32ecafe740b20061258 100644 --- a/src/main/java/edu/caltech/nanodb/commands/DumpCommand.java +++ b/src/main/java/edu/caltech/nanodb/commands/DumpCommand.java @@ -1,6 +1,7 @@ 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()); } diff --git a/src/main/java/edu/caltech/nanodb/commands/DumpIndexCommand.java b/src/main/java/edu/caltech/nanodb/commands/DumpIndexCommand.java index 80e430b20993c27f689f2560f4318678cd6f10db..908221d1227f437d1d5e7fa8a90a9e96335509a4 100644 --- a/src/main/java/edu/caltech/nanodb/commands/DumpIndexCommand.java +++ b/src/main/java/edu/caltech/nanodb/commands/DumpIndexCommand.java @@ -1,8 +1,13 @@ 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; }