final List<String> tableLabels = getLabelsFromTable( tableDescriptor, tableElements );
final List<ExpressionNode> dataElements = stripLabelsFromTable( tableDescriptor, tableElements );
final List<CellModel> firstRow = getFirstRowFromTable( tableDescriptor, dataElements );
final DataType[] colTypes = getColTypesFromFirstRow( firstRow );
final int[] foldableColumnKeys = getFoldableColumnKeys( colTypes );
final ExpressionNode data = getShapedDataFromTable( tableDescriptor, dataElements );
final ArrayDescriptor critDescriptor = this.criteria.arrayDescriptor();
final List<ExpressionNode> critElements = this.criteria.arguments();
final List<String> critLabels = getLabelsFromTable( critDescriptor, critElements );
final List<ExpressionNode> critData = stripLabelsFromTable( critDescriptor, critElements );
final int[] critCols = associateCriteriaColumnsWithTableLabels( tableLabels, critLabels );
final int foldedColumnIndex = buildFoldedColumnIndex( this.valueColumn, tableLabels );
if (foldedColumnIndex < 0) {
if (DataType.NUMERIC != TypeAnnotator.annotateExpr( this.valueColumn )) {
throw new CompilerException.UnsupportedExpression(
"The value column must either be a constant name or an index. It cannot be a computed name." );
}
}
final FilterBuilder filterBuilder = new FilterBuilder();
final ExpressionNode filter = filterBuilder.buildFilter( critCols, critData, colTypes, firstRow );
final ExpressionNodeForFoldDatabase apply = new ExpressionNodeForFoldDatabase( this.fold, colTypes, this
.colPrefix(), filter, foldedColumnIndex, foldableColumnKeys, this.valueColumn, data );
return filterBuilder.encloseFoldInLets( apply );