Commit 4c8b4486 authored by Michael A. Goulet's avatar Michael A. Goulet :cold_sweat:
Browse files

Fix overwritten columns in selclause resultSchema

the `SelectClause.computeSchema` method aggregates a `resultSchema`
member by appending all of the ColumnInfos for each of the selectValues
in the statement.

However, when efforts were made to make Schema less "mutable", I think
a change was overlooked that causes all but the last selectValue's
ColumnInfos to remain in the resultSchema.

I believe this was left undetected because the resultSchema of the
SelectClause isn't really used in many places, except for nested
subqueries. This problem was found by a student, that the first out of
two columns in a nested subquery would "disappear" from the schema.
parent 1ceddf40
No related merge requests found
Showing with 6 additions and 2 deletions
+6 -2
......@@ -368,8 +368,9 @@ public class SelectClause {
// known and non-ambiguous names from the FROM clause.
// SELECT values: SELECT a, b + c, tbl.* ...
resultSchema = new Schema();
List<ColumnInfo> resultColumnInfos = new ArrayList<>();
Set<String> fromTables = fromSchema.getTableNames();
for (SelectValue selVal : selectValues) {
if (selVal.isWildcard()) {
// Make sure that if a table name is specified, that the table
......@@ -400,9 +401,12 @@ public class SelectClause {
}
// Update the result-schema with this select-value's column-info(s).
resultSchema = new Schema(selVal.getColumnInfos(fromSchema, resultSchema));
resultColumnInfos.addAll(selVal.getColumnInfos(fromSchema, resultSchema));
}
// Construct a resultSchema which is the "summation" of all SelectValues' columnInfos.
resultSchema = new Schema(resultColumnInfos);
logger.debug("Query schema: " + resultSchema);
logger.debug("FROM-clause schema: " + fromSchema);
......
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