/// <inheritdoc/>
public override ITable Evaluate(IQueryContext context)
{
var t = Child.Evaluate(context);
var exp = Expression;
// Assert that all variables in the expression are identical.
var columnNames = exp.DiscoverReferences();
ObjectName columnName = null;
foreach (var cv in columnNames) {
if (columnName != null && !cv.Equals(columnName))
throw new InvalidOperationException("Range plan does not contain common column.");
columnName = cv;
}
// Find the variable field in the table.
var col = t.IndexOfColumn(columnName);
if (col == -1)
throw new InvalidOperationException("Could not find column reference in table: " + columnName);
var field = t.TableInfo[col];
// Calculate the range
var range = new IndexRangeSet();
var calculator = new RangeSetCalculator(context, field, range);
range = calculator.Calculate(exp);
// Select the range from the table
var ranges = range.ToArray();
return t.SelectRange(columnName, ranges);
}