Ejemplo n.º 1
0
        private Object ResolveAggregateResult(FuncParameter aggrResult, Int64 myDepth)
        {
            #region Add aggregate return value to attributes

            if (aggrResult.Value is IHyperEdge)
            {
                throw new NotImplementedQLException("TODO");

                //#region Reference edge

                ////myUsingGraph = false;

                ////Depth = GetDepth(myDepth, minDepth, myDBType);
                //var Depth = myDepth;

                //if (myDepth > 0)
                //{

                //    var myLevelKey = new EdgeList(new EdgeKey(aggrResult.TypeAttribute));

                //    #region Resolve DBReferences

                //    return ResolveAttributeValue(aggrResult.TypeAttribute, aggrResult.Value, Depth, myLevelKey, null, null, false);

                //    #endregion

                //}
                //else
                //{
                //    GraphDBType type;
                //    if (aggrResult.TypeAttribute.IsBackwardEdge)
                //    {
                //        type = _DBContext.DBTypeManager.GetTypeByUUID(aggrResult.TypeAttribute.BackwardEdgeDefinition.TypeUUID);
                //    }
                //    else
                //    {
                //        type = aggrResult.TypeAttribute.GetDBType(_DBContext.DBTypeManager);
                //    }

                //    return GetNotResolvedReferenceEdgeAttributeValue(aggrResult.Value as IReferenceEdge, type, _DBContext);

                //}

                //#endregion

            }
            else
            {

                return aggrResult.Value;

            }

            #endregion
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Go through each DBO and aggregate them
        /// </summary>
        /// <param name="myAggregates"></param>
        /// <param name="mySelections"></param>
        /// <param name="myDBOs"></param>
        /// <param name="myReferencedDBType"></param>
        /// <returns></returns>
        private IEnumerable<IVertexView> ExamineDBO_Aggregates(Int64 myTransactionToken, 
                                                                SecurityToken mySecurityToken, 
                                                                IEnumerable<IVertex> myDBOs, 
                                                                List<SelectionElementAggregate> myAggregates, 
                                                                List<SelectionElement> mySelections, 
                                                                Boolean myUsingGraph, 
                                                                Int64 myDepth)
        {

            #region Aggregate

            if (mySelections.CountIsGreater(0))
            {

                #region Grouping - each selection is grouped (checked prior)

                var aggregatedGroupings = new Dictionary<GroupingKey, SelectionElementAggregate>();

                #region Create groupings using the ILookup

                var groupedDBOs = myDBOs.ToLookup((dbo) =>
                {
                    #region Create GroupingKey based on the group values and attributes

                    Dictionary<GroupingValuesKey, IComparable> groupingVals = new Dictionary<GroupingValuesKey, IComparable>();
                    foreach (var selection in mySelections)
                    {
                        var attrValue = (selection.Element as IPropertyDefinition).GetValue(dbo);

                        groupingVals.Add(new GroupingValuesKey(selection.Element, selection.Alias), attrValue);
                    }
                    GroupingKey groupingKey = new GroupingKey(groupingVals);

                    #endregion

                    return groupingKey;

                }, (dbo) =>
                {

                    return dbo;
                });

                #endregion

                foreach (var group in groupedDBOs)
                {

                    #region Create group readouts

                    var aggregatedAttributes = new Dictionary<String, Object>();

                    foreach (var aggr in myAggregates)
                    {
                        var aggrResult =
                            aggr.Aggregate.Aggregate(
                                (group).Select(
                                    aVertex => (aggr.Element as IPropertyDefinition).GetValue(aVertex)), (IPropertyDefinition)aggr.Element);

                        if (aggrResult.Value != null)
                        {
                            //aggregatedAttributes.Add(aggr.Alias, aggrResult.Value.Value.GetReadoutValue());
                            aggregatedAttributes.Add(aggr.Alias, ResolveAggregateResult(aggrResult, myDepth));
                        }

                    }

                    foreach (var groupingKeyVal in group.Key.Values)
                    {
                        aggregatedAttributes.Add(groupingKeyVal.Key.AttributeAlias, groupingKeyVal.Value);
                    }

                    var dbObjectReadout = new VertexView(aggregatedAttributes, null);

                    #endregion

                    #region Evaluate having if exist and yield return

                    if (_HavingExpression != null)
                    {
                        var res = _HavingExpression.IsSatisfyHaving(dbObjectReadout);
                        if (res)
                            yield return dbObjectReadout;
                    }
                    else
                    {
                        yield return dbObjectReadout;
                    }

                    #endregion

                }

                yield break;

                #endregion

            }
            else
            {

                #region No grouping, just aggregates

                var aggregatedAttributes = new Dictionary<String, Object>();
                VertexView _Vertex;

                #region OR Attribute aggregates

                foreach (var aggr in myAggregates)
                {
                    FuncParameter aggrResult = null;

                    if (aggr.Aggregate.PluginShortName == "count" && aggr.RelatedIDChainDefinition.SelectType == TypesOfSelect.Asterisk)
                    {
                        aggrResult = new FuncParameter(_graphdb.GetVertexCount<UInt64>(mySecurityToken, 
                                                                                        myTransactionToken, 
                                                                                        new RequestGetVertexCount(aggr.EdgeList.LastEdge.VertexTypeID), 
                                                                                        (stats, count) => count));
                    }
                    else
                    {
                        aggrResult =
                            aggr.Aggregate.Aggregate(
                            myDBOs.Where(aVertex => (aggr.Element as IPropertyDefinition).HasValue(aVertex)).Select(
                                dbo => (aggr.Element as IPropertyDefinition).GetValue(dbo)), (IPropertyDefinition)aggr.Element);

                    }


                    //aggregatedAttributes.Add(aggr.Alias, aggrResult.Value.GetReadoutValue());
                    if (aggrResult.Value != null)
                    {
                        aggregatedAttributes.Add(aggr.Alias, ResolveAggregateResult(aggrResult, myDepth));
                    }

                }

                _Vertex = new VertexView(aggregatedAttributes, null);

                #endregion

                #region Check having expression and yield return value

                if (_HavingExpression != null)
                {
                    var res = _HavingExpression.IsSatisfyHaving(_Vertex);
                    if (res)
                        yield return _Vertex;
                }
                else
                {
                    yield return _Vertex;
                }

                #endregion

                yield break;

                #endregion

            }

            #endregion

        }