Ejemplo n.º 1
0
        public override Exceptional<FuncParameter> Aggregate(IEnumerable<DBObjectStream> myDBObjects, TypeAttribute myTypeAttribute, DBContext myDBContext, params Functions.ParameterValue[] myParameters)
        {
            var aggregateResult = new DBDouble(0d);
            var total = 0UL;

            foreach (var dbo in myDBObjects)
            {
                var attr = dbo.GetAttribute(myTypeAttribute, myTypeAttribute.GetDBType(myDBContext.DBTypeManager), myDBContext);
                if (attr.Failed())
                {
                    return new Exceptional<FuncParameter>(attr);
                }
                if (attr.Value != null && attr.Value is ADBBaseObject && aggregateResult.IsValidValue((attr.Value as ADBBaseObject).Value))
                {
                    aggregateResult.Add((attr.Value as ADBBaseObject));
                    total++;
                }
                else
                {
                    return new Exceptional<FuncParameter>(new Error_AggregateIsNotValidOnThisAttribute(myTypeAttribute.Name));
                }
            }
            aggregateResult.Div(new DBUInt64(total));

            return new Exceptional<FuncParameter>(new FuncParameter(aggregateResult));
        }
Ejemplo n.º 2
0
        public override Exceptional<FuncParameter> Aggregate(AAttributeIndex attributeIndex, GraphDBType graphDBType, DBContext dbContext)
        {
            if (attributeIndex.IsUUIDIndex)
            {
                return new Exceptional<FuncParameter>(new Error_NotImplemented(new System.Diagnostics.StackTrace(true), "AVG(UUID) is not implemented!"));
            }

            var indexRelatedType = dbContext.DBTypeManager.GetTypeByUUID(attributeIndex.IndexRelatedTypeUUID);

            // HACK: rewrite as soon as we have real attribute index keys
            ADBBaseObject aADBBaseObject = new DBDouble(DBObjectInitializeType.Default);
            DBUInt64 total = new DBUInt64((UInt64)0);

            foreach (var idxEntry in attributeIndex.GetKeyValues(indexRelatedType, dbContext))
            {
                aADBBaseObject.Add(aADBBaseObject.Clone(idxEntry.Key));

                total += (UInt64)idxEntry.Value.LongCount();
            }
            aADBBaseObject.Div(total);

            return new Exceptional<FuncParameter>(new FuncParameter(aADBBaseObject));
        }