1) In the method createPlan (please see below), is the line of code, marked by an arrow ( Plan p = plans.remove(0); <----- ) chaining the Plan interface to the array list of plans?
Can this line be replaced by Plan p = new ArrayList<Plan>(); , without having any practical differences by any chance?
If not, what exactly is this line of code doing?
/**
* Creates a query plan as follows. It first takes
* the product of all tables and views; it then selects on the predicate;
* and finally it projects on the field list.
*/
public Plan createPlan(QueryData data, Transaction tx) {
//Step 1: Create a plan for each mentioned table or view
List<Plan> plans = new ArrayList<Plan>();
for (String tblname : data.tables()) {
String viewdef = SimpleDB.mdMgr().getViewDef(tblname, tx);
if (viewdef != null)
plans.add(SimpleDB.planner().createQueryPlan(viewdef, tx));
else
plans.add(new TablePlan(tblname, tx));
}
//Step 2: Create the product of all table plans
Plan p = plans.remove(0); <-----
for (Plan nextplan : plans)
p = new ProductPlan(p, nextplan);
//Step 3: Add a selection plan for the predicate
p = new SelectPlan(p, data.pred());
//Step 4: Project on the field names
p = new ProjectPlan(p, data.fields());
return p;
}
2) Considering how computers only executes our commands sequentialy in a forward direction, it is unlikely, but I thought I'd ask.
When running a debuger on eclipse, is there a functionality that lets us go back to the previous execution of a line of code in a similar way as a browser would let us go back to what we were viewing previously by clicking on the browser's back button ?
3) Does a StreamTokenizer treat ' . ' as a number 0.0?
I would imaging that "tok.ordinaryChar('.');" is done in the Lexer.java class (please see below) in order to
classify periods as a single character token so that the parser will view the character as a string or char so that we can use it in places like, " ... s.SName, c.pId ... "?
public Lexer(String s) {
initKeywords();
tok = new StreamTokenizer(new StringReader(s));
tok.ordinaryChar('.'); <-----
tok.lowerCaseMode(true); //ids and keywords are converted
nextToken();
}
4) What is the point of having the following method if it should never be called as the comment suggest?
Is this simply giving us a framework so that we can create a method to allow use of aliases of field names in SQL command as a practice?
/**
* This method should never be called.
* Throws a ClassCastException.
* @see simpledb.query.Expression#asFieldName()
*/
public String asFieldName() {
throw new ClassCastException();
}
5) There is an author comments that reads, "BadSyntaxException: simply extends RuntimeException ...".
Does this mean that the author created a subclass of RuntimeException? If so, is the reason for doing so to make it easier for us to narrow down which part of the code created the exception (i.e. BadSyntaxException would only be created within the SimpleDB code wherares RuntimeException might come from JAVA library code)? If not, what does the author mean by that line?
Any insights will be greatly appreciated.
Thank you,