(TransactionId tid, ZQuery q)
| 138 | } |
| 139 | |
| 140 | public LogicalPlan parseQueryLogicalPlan(TransactionId tid, ZQuery q) |
| 141 | throws IOException, Zql.ParseException, simpledb.ParsingException { |
| 142 | @SuppressWarnings("unchecked") |
| 143 | List<ZFromItem> from = q.getFrom(); |
| 144 | LogicalPlan lp = new LogicalPlan(); |
| 145 | lp.setQuery(q.toString()); |
| 146 | // walk through tables in the FROM clause |
| 147 | for (int i = 0; i < from.size(); i++) { |
| 148 | ZFromItem fromIt = from.get(i); |
| 149 | try { |
| 150 | |
| 151 | int id = Database.getCatalog().getTableId(fromIt.getTable()); // will |
| 152 | // fall |
| 153 | // through |
| 154 | // if |
| 155 | // table |
| 156 | // doesn't |
| 157 | // exist |
| 158 | String name; |
| 159 | |
| 160 | if (fromIt.getAlias() != null) |
| 161 | name = fromIt.getAlias(); |
| 162 | else |
| 163 | name = fromIt.getTable(); |
| 164 | |
| 165 | lp.addScan(id, name); |
| 166 | |
| 167 | // XXX handle subquery? |
| 168 | } catch (NoSuchElementException e) { |
| 169 | e.printStackTrace(); |
| 170 | throw new simpledb.ParsingException("Table " |
| 171 | + fromIt.getTable() + " is not in catalog"); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | // now parse the where clause, creating Filter and Join nodes as needed |
| 176 | ZExp w = q.getWhere(); |
| 177 | if (w != null) { |
| 178 | |
| 179 | if (!(w instanceof ZExpression)) { |
| 180 | throw new simpledb.ParsingException( |
| 181 | "Nested queries are currently unsupported."); |
| 182 | } |
| 183 | ZExpression wx = (ZExpression) w; |
| 184 | processExpression(tid, wx, lp); |
| 185 | |
| 186 | } |
| 187 | |
| 188 | // now look for group by fields |
| 189 | ZGroupBy gby = q.getGroupBy(); |
| 190 | String groupByField = null; |
| 191 | if (gby != null) { |
| 192 | @SuppressWarnings("unchecked") |
| 193 | List<ZExp> gbs = gby.getGroupBy(); |
| 194 | if (gbs.size() > 1) { |
| 195 | throw new simpledb.ParsingException( |
| 196 | "At most one grouping field expression supported."); |
| 197 | } |
no test coverage detected