Ejemplo n.º 1
0
        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());
            }
        }
Ejemplo n.º 2
0
        public List <FilterItem> ParserFilter(string conditiontext)
        {
            var conditions = QueryPraser.ParseConditoin(conditiontext);

            if (conditions == null || conditions.Count() == 0)
            {
                return(null);
            }
            ;

            List <FilterItem> result = new List <FilterItem>();

            foreach (var item in conditions)
            {
                var col = this.table.ObjectConverter.Fields.Find(o => o.FieldName == item.Field);
                if (col != null)
                {
                    FilterItem filter = new FilterItem()
                    {
                        FieldOrProperty = col.FieldName
                    };
                    filter.Compare = item.Comparer;
                    if (!col.ClrType.IsValueType && col.ClrType != typeof(string))
                    {
                        throw new Exception("only value type column are allowed to use on search condition");
                    }
                    var rightvalue = Convert.ChangeType(item.Value, col.ClrType);

                    // For datetime col, need to have something different.
                    if (rightvalue != null)
                    {
                        filter.Value = col.ToBytes(rightvalue);
                        result.Add(filter);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        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);
            }
        }