List<String> selectedStrs = Lists.newArrayList();
List<Integer> projectionInts = Lists.newArrayList();
boolean canUseProject = true;
boolean canOmitProjectSelect = true;
ColumnIndexesImpl attributesAfterSelection = new ColumnIndexesImpl();
ChainedColumnIndexes attr =
new ChainedColumnIndexes(new ChainedColumnIndexes(null, this.columns()));
int i = 0;
for (Expression expr : selectElems) {
++ i;
if (expr.codeRefersToConjuredColumn()) {
try {
// TODO fix this - do not even attempt to add a second time here
attr.find(expr.conjure().column());
} catch (IndexOutOfBoundsException ex) {
attr.add(expr.conjure().column());
}
}
if (! expr.isSuitableForProject()) {
canUseProject = false;
}
projectionInts.add(expr.conjure().conjuredIndex(attr.columnIndexes()));
attributesAfterSelection.add(expr.conjure().column());
if (i > columns().size() || expr.conjure().column() != columns().get(i-1)) {
canOmitProjectSelect = false;
}
selectedStrs.add(expr.code(attr.columnIndexes()));
}
if (attributesAfterSelection.size() != columns().size()) {
canOmitProjectSelect = false;
}