} else {
// add the group by columns from the src table
for (int i = 0; i < stmt.m_groupByColumns.size(); i++) {
ParsedSelectStmt.ParsedColInfo gbcol = stmt.m_groupByColumns.get(i);
Column srcCol = srcColumnArray.get(gbcol.index);
ColumnRef cref = matviewinfo.getGroupbycols().add(srcCol.getTypeName());
// groupByColumns is iterating in order of groups. Store that grouping order
// in the column ref index. When the catalog is serialized, it will, naturally,
// scramble this order like a two year playing dominos, presenting the data
// in a meaningless sequence.
cref.setIndex(i); // the column offset in the view's grouping order
cref.setColumn(srcCol); // the source column from the base (non-view) table
}
// parse out the group by columns into the dest table
for (int i = 0; i < stmt.m_groupByColumns.size(); i++) {
ParsedSelectStmt.ParsedColInfo col = stmt.m_displayColumns.get(i);
Column destColumn = destColumnArray.get(i);
processMaterializedViewColumn(matviewinfo, srcTable, destColumn,
ExpressionType.VALUE_TUPLE, (TupleValueExpression)col.expression);
}
}
// Set up COUNT(*) column
ParsedSelectStmt.ParsedColInfo countCol = stmt.m_displayColumns.get(stmt.m_groupByColumns.size());
assert(countCol.expression.getExpressionType() == ExpressionType.AGGREGATE_COUNT_STAR);
assert(countCol.expression.getLeft() == null);
processMaterializedViewColumn(matviewinfo, srcTable,
destColumnArray.get(stmt.m_groupByColumns.size()),
ExpressionType.AGGREGATE_COUNT_STAR, null);
// create an index and constraint for the table
Index pkIndex = destTable.getIndexes().add(HSQLInterface.AUTO_GEN_MATVIEW_IDX);
pkIndex.setType(IndexType.BALANCED_TREE.getValue());
pkIndex.setUnique(true);
// add the group by columns from the src table
// assume index 1 throuh #grpByCols + 1 are the cols
for (int i = 0; i < stmt.m_groupByColumns.size(); i++) {
ColumnRef c = pkIndex.getColumns().add(String.valueOf(i));
c.setColumn(destColumnArray.get(i));
c.setIndex(i);
}
Constraint pkConstraint = destTable.getConstraints().add(HSQLInterface.AUTO_GEN_MATVIEW_CONST);
pkConstraint.setType(ConstraintType.PRIMARY_KEY.getValue());
pkConstraint.setIndex(pkIndex);