}
}
protected static IntIterator getRangeIterator(Table t, RangePredicate rp) {
ColumnExpression col;
Expression l, r;
// make sure columns are of the right type
if ( !(rp.getMiddleExpression() instanceof ColumnExpression) ||
ExpressionAnalyzer.hasDependency(rp.getLeftExpression()) ||
ExpressionAnalyzer.hasDependency(rp.getRightExpression()) )
{
return null;
}
// assign variables
col = (ColumnExpression)rp.getMiddleExpression();
l = rp.getLeftExpression();
r = rp.getRightExpression();
// if table has index of the right type, use it
Comparator cmp = rp.getComparator();
Index index = t.getIndex(col.getColumnName());
if ( index == null || !cmp.equals(index.getComparator()) )
return null;
int operation = rp.getOperation();
Class ltype = t.getColumnType(col.getColumnName());
// TODO safety check literal types
// get the index type
int indexType;
switch ( operation ) {
case RangePredicate.IN_IN:
indexType = Index.TYPE_AII;
break;
case RangePredicate.IN_EX:
indexType = Index.TYPE_AIE;
break;
case RangePredicate.EX_IN:
indexType = Index.TYPE_AEI;
break;
case RangePredicate.EX_EX:
indexType = Index.TYPE_AEE;
break;
default:
throw new IllegalStateException(); // should never occur
}
// get the indexed rows
if ( ltype == int.class ) {
return index.rows(l.getInt(null), r.getInt(null), indexType);
} else if ( ltype == long.class ) {
return index.rows(l.getLong(null), r.getLong(null), indexType);
} else if ( ltype == float.class ) {
return index.rows(l.getFloat(null), r.getFloat(null), indexType);
} else if ( ltype == double.class ) {
return index.rows(l.getDouble(null), r.getDouble(null), indexType);
} else {
return index.rows(l.get(null), r.get(null), indexType);
}
}