MCPcopy Create free account
hub / github.com/1345414527/MIT6.830 / parseQueryLogicalPlan

Method parseQueryLogicalPlan

src/java/simpledb/Parser.java:140–276  ·  view source on GitHub ↗
(TransactionId tid, ZQuery q)

Source from the content-addressed store, hash-verified

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 }

Callers 4

processExpressionMethod · 0.95
handleQueryStatementMethod · 0.95
handleInsertStatementMethod · 0.95
generateLogicalPlanMethod · 0.95

Calls 14

setQueryMethod · 0.95
getCatalogMethod · 0.95
addScanMethod · 0.95
processExpressionMethod · 0.95
addProjectFieldMethod · 0.95
addAggregateMethod · 0.95
addOrderByMethod · 0.95
getMethod · 0.80
getOperandMethod · 0.80
toStringMethod · 0.65
getTableIdMethod · 0.65
equalsMethod · 0.65

Tested by

no test coverage detected