public List <IDictionary <string, object> > Take(int count) { ExecutionPlan executionplan = QueryPraser.GetExecutionPlan(this); List <long> list = GetList(executionplan, count); List <IDictionary <string, object> > listvalue = new List <IDictionary <string, object> >(); foreach (var item in list) { var record = this.table._getvalue(item); listvalue.Add(record); } if (!executionplan.RequireOrderBy) { return(listvalue); } else { if (!string.IsNullOrEmpty(this.OrderByFieldName) && this.table.Setting.Columns.Any(o => o.Name == this.OrderByFieldName)) { var col = this.table.Setting.Columns.First(o => o.Name == this.OrderByFieldName); if (col != null) { if (this.Ascending) { return(listvalue.OrderBy(o => GetValue(o, this.OrderByFieldName, col.ClrType)).Skip(this.SkipCount).Take(count).ToList()); } else { return(listvalue.OrderByDescending(o => GetValue(o, this.OrderByFieldName, col.ClrType)).Skip(this.SkipCount).Take(count).ToList()); } } } return(listvalue.Skip(this.SkipCount).Take(count).ToList()); } }
public int Count() { lock (this.table._Locker) { int skipped = 0; int taken = 0; ExecutionPlan executionplan = QueryPraser.GetExecutionPlan(this); List <List <long> > rangelist = new List <List <long> >(); foreach (var item in executionplan.indexRanges) { List <long> blockpositionList = new List <long>(); var index = this.table.Indexs.Find(o => o.FieldName == item.Key); ItemCollection collection = index.GetCollection(item.Value.lower, item.Value.upper, item.Value.lowerOpen, item.Value.upperOpen, this.Ascending); foreach (Int64 position in collection) { blockpositionList.Add(position); } rangelist.Add(blockpositionList); } bool itemMatch = true; foreach (Int64 item in executionplan.startCollection) { /// check matches. itemMatch = true; foreach (List <long> rangeitem in rangelist) { if (!rangeitem.Contains(item)) { itemMatch = false; break; } } if (!itemMatch) { continue; } /// check column matchs. foreach (ColumnScan plan in executionplan.scanColumns) { byte[] columnbytes = this.table.BlockFile.GetCol(item, plan.relativeStartPosition, plan.length); if (!plan.Evaluator.isMatch(columnbytes)) { itemMatch = false; break; } } if (!itemMatch) { continue; } /// pass all tests. if (skipped < this.SkipCount) { skipped += 1; continue; } taken += 1; } executionplan = null; return(taken); } }