Example #1
0
        private Node VisitCollectionAggregateFunction(FunctionOp op, Node n)
        {
            TypeUsage type   = (TypeUsage)null;
            Node      child0 = n.Child0;

            if (OpType.SoftCast == child0.Op.OpType)
            {
                type   = TypeHelpers.GetEdmType <CollectionType>(child0.Op.Type).TypeUsage;
                child0 = child0.Child0;
                while (OpType.SoftCast == child0.Op.OpType)
                {
                    child0 = child0.Child0;
                }
            }
            Node        node1       = this.BuildUnnest(child0);
            Var         column      = (node1.Op as UnnestOp).Table.Columns[0];
            AggregateOp aggregateOp = this.m_command.CreateAggregateOp(op.Function, false);
            Node        node2       = this.m_command.CreateNode((Op)this.m_command.CreateVarRefOp(column));

            if (type != null)
            {
                node2 = this.m_command.CreateNode((Op)this.m_command.CreateSoftCastOp(type), node2);
            }
            Node   node3   = this.m_command.CreateNode((Op)aggregateOp, node2);
            VarVec varVec1 = this.m_command.CreateVarVec();
            Node   node4   = this.m_command.CreateNode((Op)this.m_command.CreateVarDefListOp());
            VarVec varVec2 = this.m_command.CreateVarVec();
            Var    computedVar;
            Node   varDefListNode = this.m_command.CreateVarDefListNode(node3, out computedVar);

            varVec2.Set(computedVar);
            Node node5 = this.m_command.CreateNode((Op)this.m_command.CreateGroupByOp(varVec1, varVec2), node1, node4, varDefListNode);

            return(this.AddSubqueryToParentRelOp(computedVar, node5));
        }
Example #2
0
            /// <summary>
            /// Returns the ReplicateGroupOp based on the current value of Settings.Default.GroupByReplicateAnnotation,
            /// and the specified AggregateOp.  Note that if the ReplicateGroupOp is not grouping on an annotation,
            /// the AggregateOp will be override with the value MEAN.
            /// </summary>
            public static ReplicateGroupOp FromCurrentSettings(SrmSettings settings, AggregateOp aggregateOp)
            {
                AnnotationDef groupByAnnotationDef = null;
                string        annotationName       = Settings.Default.GroupByReplicateAnnotation;

                if (null != annotationName)
                {
                    groupByAnnotationDef =
                        settings.DataSettings.AnnotationDefs.FirstOrDefault(
                            annotationDef => annotationName == annotationDef.Name);
                }
                if (null == groupByAnnotationDef)
                {
                    aggregateOp = AggregateOp.MEAN;
                }
                return(new ReplicateGroupOp(groupByAnnotationDef, aggregateOp));
            }
Example #3
0
        /// <summary>
        /// Converts a collection aggregate function count(X), where X is a collection into
        /// two parts. Part A is a groupby subquery that looks like
        ///    GroupBy(Unnest(X), empty, count(y))
        /// where "empty" describes the fact that the groupby has no keys, and y is an
        /// element var of the Unnest
        ///
        /// Part 2 is a VarRef that refers to the aggregate var for count(y) described above.
        ///
        /// Logically, we would replace the entire functionOp by element(GroupBy...). However,
        /// since we also want to translate element() into single-row-subqueries, we do this
        /// here as well.
        ///
        /// The function itself is replaced by the VarRef, and the GroupBy is added to the list
        /// of scalar subqueries for the current relOp node on the stack
        ///
        /// </summary>
        /// <param name="op">the functionOp for the collection agg</param>
        /// <param name="n">current subtree</param>
        /// <returns>the VarRef node that should replace the function</returns>
        private Node VisitCollectionAggregateFunction(FunctionOp op, Node n)
        {
            TypeUsage softCastType = null;
            Node      argNode      = n.Child0;

            if (OpType.SoftCast == argNode.Op.OpType)
            {
                softCastType = TypeHelpers.GetEdmType <CollectionType>(argNode.Op.Type).TypeUsage;
                argNode      = argNode.Child0;

                while (OpType.SoftCast == argNode.Op.OpType)
                {
                    argNode = argNode.Child0;
                }
            }

            Node     unnestNode      = BuildUnnest(argNode);
            UnnestOp unnestOp        = unnestNode.Op as UnnestOp;
            Var      unnestOutputVar = unnestOp.Table.Columns[0];

            AggregateOp aggregateOp      = m_command.CreateAggregateOp(op.Function, false);
            VarRefOp    unnestVarRefOp   = m_command.CreateVarRefOp(unnestOutputVar);
            Node        unnestVarRefNode = m_command.CreateNode(unnestVarRefOp);

            if (softCastType != null)
            {
                unnestVarRefNode = m_command.CreateNode(m_command.CreateSoftCastOp(softCastType), unnestVarRefNode);
            }
            Node aggExprNode = m_command.CreateNode(aggregateOp, unnestVarRefNode);

            VarVec keyVars           = m_command.CreateVarVec(); // empty keys
            Node   keyVarDefListNode = m_command.CreateNode(m_command.CreateVarDefListOp());

            VarVec gbyOutputVars = m_command.CreateVarVec();
            Var    aggVar;
            Node   aggVarDefListNode = m_command.CreateVarDefListNode(aggExprNode, out aggVar);

            gbyOutputVars.Set(aggVar);
            GroupByOp gbyOp           = m_command.CreateGroupByOp(keyVars, gbyOutputVars);
            Node      gbySubqueryNode = m_command.CreateNode(gbyOp, unnestNode, keyVarDefListNode, aggVarDefListNode);

            // "Move" this subquery to my parent relop
            Node ret = AddSubqueryToParentRelOp(aggVar, gbySubqueryNode);

            return(ret);
        }
Example #4
0
 public RetentionTimeTransform(RTPeptideValue rtPeptideValue, IRetentionTimeTransformOp rtAlignment, AggregateOp aggregateOp)
 {
     RtPeptideValue = rtPeptideValue;
     RtTransformOp  = rtAlignment;
     AggregateOp    = aggregateOp;
 }
Example #5
0
 /// <summary>
 /// Returns the ReplicateGroupOp based on the current value of Settings.Default.GroupByReplicateAnnotation,
 /// and the current Settings.Default.ShowPeptideCV.  Note that if the ReplicateGroupOp is not grouping on
 /// an annotation, the AggregateOp will always be set to MEAN.
 /// </summary>
 public static ReplicateGroupOp FromCurrentSettings(SrmSettings settings)
 {
     return(FromCurrentSettings(settings, AggregateOp.FromCurrentSettings()));
 }
Example #6
0
 private ReplicateGroupOp(AnnotationDef groupByAnnotationDef, AggregateOp aggregateOp)
 {
     GroupByAnnotation = groupByAnnotationDef;
     AggregateOp       = aggregateOp;
 }
 public override void Visit(AggregateOp op, Node n)
 {
     VisitScalarOpDefault(op, n);
 }
Example #8
0
 /// <summary>
 /// Clone an aggregateop
 /// </summary>
 /// <param name="op">The Op to Copy</param>
 /// <param name="n">The Node that references the Op</param>
 /// <returns>A copy of the original Node that references a copy of the original Op</returns>
 public override Node Visit(AggregateOp op, Node n)
 {
     return(CopyDefault(m_destCmd.CreateAggregateOp(op.AggFunc, op.IsDistinctAggregate), n));
 }
 /// <summary>
 ///     Visitor pattern method for AggregateOp
 /// </summary>
 /// <param name="op"> The AggregateOp being visited </param>
 /// <param name="n"> The Node that references the Op </param>
 public virtual void Visit(AggregateOp op, Node n)
 {
     VisitScalarOpDefault(op, n);
 }
 public override Node Visit(AggregateOp op, Node n)
 {
     return(null);
 }
 public override Node Visit(AggregateOp op, Node n)
 {
     return null;
 }
Example #12
0
 public override System.Data.Entity.Core.Query.InternalTrees.Node Visit(
     AggregateOp op,
     System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     return((System.Data.Entity.Core.Query.InternalTrees.Node)null);
 }
Example #13
0
 // <summary>
 // Clone an aggregateop
 // </summary>
 // <param name="op"> The Op to Copy </param>
 // <param name="n"> The Node that references the Op </param>
 // <returns> A copy of the original Node that references a copy of the original Op </returns>
 public override Node Visit(AggregateOp op, Node n)
 {
     return CopyDefault(m_destCmd.CreateAggregateOp(op.AggFunc, op.IsDistinctAggregate), n);
 }
Example #14
0
 public override void Visit(AggregateOp op, Node n)
 {
     VisitScalarOpDefault(op, n);
 }
Example #15
0
        public override void WriteJson(JsonWriter writer,
                                       object untypedValue,
                                       JsonSerializer serializer)
        {
            if (untypedValue == null)
            {
                serializer.Serialize(writer,
                                     null);

                return;
            }

            AggregateOp value = (AggregateOp)untypedValue;

            switch (value)
            {
            case AggregateOp.Argmax:
                serializer.Serialize(writer,
                                     "argmax");

                return;

            case AggregateOp.Argmin:
                serializer.Serialize(writer,
                                     "argmin");

                return;

            case AggregateOp.Average:
                serializer.Serialize(writer,
                                     "average");

                return;

            case AggregateOp.Ci0:
                serializer.Serialize(writer,
                                     "ci0");

                return;

            case AggregateOp.Ci1:
                serializer.Serialize(writer,
                                     "ci1");

                return;

            case AggregateOp.Count:
                serializer.Serialize(writer,
                                     "count");

                return;

            case AggregateOp.Distinct:
                serializer.Serialize(writer,
                                     "distinct");

                return;

            case AggregateOp.Max:
                serializer.Serialize(writer,
                                     "max");

                return;

            case AggregateOp.Mean:
                serializer.Serialize(writer,
                                     "mean");

                return;

            case AggregateOp.Median:
                serializer.Serialize(writer,
                                     "median");

                return;

            case AggregateOp.Min:
                serializer.Serialize(writer,
                                     "min");

                return;

            case AggregateOp.Missing:
                serializer.Serialize(writer,
                                     "missing");

                return;

            case AggregateOp.Q1:
                serializer.Serialize(writer,
                                     "q1");

                return;

            case AggregateOp.Q3:
                serializer.Serialize(writer,
                                     "q3");

                return;

            case AggregateOp.Stderr:
                serializer.Serialize(writer,
                                     "stderr");

                return;

            case AggregateOp.Stdev:
                serializer.Serialize(writer,
                                     "stdev");

                return;

            case AggregateOp.Stdevp:
                serializer.Serialize(writer,
                                     "stdevp");

                return;

            case AggregateOp.Sum:
                serializer.Serialize(writer,
                                     "sum");

                return;

            case AggregateOp.Valid:
                serializer.Serialize(writer,
                                     "valid");

                return;

            case AggregateOp.Values:
                serializer.Serialize(writer,
                                     "values");

                return;

            case AggregateOp.Variance:
                serializer.Serialize(writer,
                                     "variance");

                return;

            case AggregateOp.Variancep:
                serializer.Serialize(writer,
                                     "variancep");

                return;
            }

            throw new Exception("Cannot marshal type AggregateOp");
        }