Exemplo n.º 1
0
        public static IEnumerable <long> SelectRows(this ITable table, int column, Operator op, DataObject cell)
        {
            // If the cell is of an incompatible type, return no results,
            DataType colType = table.TableInfo[column].DataType;

            if (!cell.DataType.IsComparable(colType))
            {
                // Types not comparable, so return 0
                return(new List <long>(0));
            }

            // Get the selectable scheme for this column
            SelectableScheme ss = table.GetScheme(column);

            // If the operator is a standard operator, use the interned SelectableScheme
            // methods.
            if (op.IsEquivalent(Operator.Equal))
            {
                return(ss.SelectEqual(cell));
            }
            if (op.IsEquivalent(Operator.NotEqual))
            {
                return(ss.SelectNotEqual(cell));
            }
            if (op.IsEquivalent(Operator.Greater))
            {
                return(ss.SelectGreater(cell));
            }
            if (op.IsEquivalent(Operator.Smaller))
            {
                return(ss.SelectLess(cell));
            }
            if (op.IsEquivalent(Operator.GreaterOrEqual))
            {
                return(ss.SelectGreaterOrEqual(cell));
            }
            if (op.IsEquivalent(Operator.SmallerOrEqual))
            {
                return(ss.SelectLessOrEqual(cell));
            }

            // If it's not a standard operator (such as IS, NOT IS, etc) we generate the
            // range set especially.
            SelectableRangeSet rangeSet = new SelectableRangeSet();

            rangeSet.Intersect(op, cell);
            return(ss.SelectRange(rangeSet.ToArray()));
        }
Exemplo n.º 2
0
        public override ITable Evaluate(IQueryContext context)
        {
            ITable t = Child.Evaluate(context);

            Expression exp = expression;

            // Assert that all variables in the expression are identical.
            IEnumerable <ObjectName> allVars = exp.AllVariables();
            ObjectName v = null;

            foreach (ObjectName cv in allVars)
            {
                if (v != null && !cv.Equals(v))
                {
                    throw new ApplicationException("Assertion failed: Range plan does not contain common variable.");
                }

                v = cv;
            }

            // Find the variable field in the table.
            int col = ((Table)t).FindFieldName(v);

            if (col == -1)
            {
                throw new ApplicationException("Couldn't find column reference in table: " + v);
            }

            DataColumnInfo field = t.TableInfo[col];
            // Calculate the range
            SelectableRangeSet range = new SelectableRangeSet();

            CalcRange(context, field, range, exp);

            // Select the range from the table
            SelectableRange[] ranges = range.ToArray();
            return(t.RangeSelect(v, ranges));
        }