private Table MatchRegexNotEqual(Predicate p) { int col = this.ColumnDefinitions.IndexOf(p.FieldName); List<Element[]> selRows = new List<Element[]>(); Regex regex = p.Value.RegexValue(); for (int i = 0; i < this.Rows; i++) { if (!regex.IsMatch((string)this[i, col])) { selRows.Add(this.Row(i)); } } return new Table(this.Name, this.ColumnDefinitions, selRows); }
private Table MatchNotEqual(Predicate p) { int col = this.ColumnDefinitions.IndexOf(p.FieldName); List<Element[]> selRows = new List<Element[]>(); TableIndex index = this.GetIndex(col); if (index != null) { HashSet<int> exclude = new HashSet<int>(); foreach (int i in index.FindEqual(p.Value)) { exclude.Add(i); } for (int i = 0; i < this.Rows; i++) { if (exclude.Contains(i)) continue; selRows.Add(this.Row(i)); } return new Table(this.Name, this.ColumnDefinitions, selRows); } for (int i = 0; i < this.Rows; i++) { if (this[i, col].CompareTo(p.Value) != 0) { selRows.Add(this.Row(i)); } } return new Table(this.Name, this.ColumnDefinitions, selRows); }
private Table MatchLike(Predicate p) { Regex regex = LikeToRegex((string)p.Value); Predicate q = new Predicate(p.FieldName, p.Operator, new Element(regex)); return MatchRegexEqual(q); }
private Table MatchLessThanEqual(Predicate p) { int col = this.ColumnDefinitions.IndexOf(p.FieldName); List<Element[]> selRows = new List<Element[]>(); for (int i = 0; i < this.Rows; i++) { if (this[i, col].CompareTo(p.Value) <= 0) { selRows.Add(this.Row(i)); } } return new Table(this.Name, this.ColumnDefinitions, selRows); }
private Table MatchEqual(Predicate p) { int col = this.ColumnDefinitions.IndexOf(p.FieldName); List<Element[]> selRows = new List<Element[]>(); TableIndex index = this.GetIndex(col); if (index!=null) { foreach (int i in index.FindEqual(p.Value)) { selRows.Add(this.Row(i)); } } else { for (int i = 0; i < this.Rows; i++) { if (this[i, col].CompareTo(p.Value) == 0) { selRows.Add(this.Row(i)); } } } return new Table(this.Name, this.ColumnDefinitions, selRows); }
public Table Select(Predicate p) { int col = this.ColumnDefinitions.IndexOf(p.FieldName); if (this.ColumnDefinitions[col].Indexed && this.GetIndex(col) == null) { if (this.Rows > MIN_ROWS_FOR_INDEX) { this.CreateIndex(col, true); } } switch (p.Operator) { case Predicate.PredicateOperator.EQ: return MatchEqual(p); case Predicate.PredicateOperator.NEQ: return MatchNotEqual(p); case Predicate.PredicateOperator.LIKE: return MatchLike(p); case Predicate.PredicateOperator.REGEXEQ: return MatchRegexEqual(p); case Predicate.PredicateOperator.REGEXNEQ: return MatchRegexNotEqual(p); case Predicate.PredicateOperator.GT: return MatchGreaterThan(p); case Predicate.PredicateOperator.GTE: return MatchGreaterThanEqual(p); case Predicate.PredicateOperator.LT: return MatchLessThan(p); case Predicate.PredicateOperator.LTE: return MatchLessThanEqual(p); } return null; }