diff --git a/query/graphql/planner/sum.go b/query/graphql/planner/sum.go index 5ac0ce13e0..aa56c3bae3 100644 --- a/query/graphql/planner/sum.go +++ b/query/graphql/planner/sum.go @@ -28,7 +28,11 @@ type sumNode struct { virtualFieldId string } -func (p *Planner) Sum(sourceInfo *sourceInfo, field *parser.Field, parent *parser.Select) (*sumNode, error) { +func (p *Planner) Sum( + sourceInfo *sourceInfo, + field *parser.Field, + parent *parser.Select, +) (*sumNode, error) { source, err := field.GetAggregateSource() if err != nil { return nil, err @@ -51,8 +55,20 @@ func (p *Planner) Sum(sourceInfo *sourceInfo, field *parser.Field, parent *parse } // Returns true if the value to be summed is a float, otherwise false. -func (p *Planner) isValueFloat(sourceInfo *sourceInfo, parent *parser.Select, source []string, sourceCollection string, sourceProperty string) (bool, error) { - sourceFieldDescription, err := p.getSourceField(sourceInfo, parent, source, sourceCollection, sourceProperty) +func (p *Planner) isValueFloat( + sourceInfo *sourceInfo, + parent *parser.Select, + source []string, + sourceCollection string, + sourceProperty string, +) (bool, error) { + sourceFieldDescription, err := p.getSourceField( + sourceInfo, + parent, + source, + sourceCollection, + sourceProperty, + ) if err != nil { return false, err } @@ -61,8 +77,15 @@ func (p *Planner) isValueFloat(sourceInfo *sourceInfo, parent *parser.Select, so sourceFieldDescription.Kind == client.FieldKind_FLOAT, nil } -// Gets the root underlying field of the aggregate. This could be several layers deap if aggregating an aggregate. -func (p *Planner) getSourceField(sourceInfo *sourceInfo, parent *parser.Select, source []string, sourceCollection string, sourceProperty string) (client.FieldDescription, error) { +// Gets the root underlying field of the aggregate. +// This could be several layers deap if aggregating an aggregate. +func (p *Planner) getSourceField( + sourceInfo *sourceInfo, + parent *parser.Select, + source []string, + sourceCollection string, + sourceProperty string, +) (client.FieldDescription, error) { if len(source) == 1 { // If path length is one - we are summing an inline array fieldDescription, fieldDescriptionFound := sourceInfo.collectionDescription.GetField(sourceCollection) @@ -105,16 +128,23 @@ func (p *Planner) getSourceField(sourceInfo *sourceInfo, parent *parser.Select, sourceSourceCollection := sourceSource[0] sourceSourceProperty := p.getSourceProperty(sourceSource, sourceParent) - return p.getSourceField(sourceInfo, sourceParent, sourceSource, sourceSourceCollection, sourceSourceProperty) + return p.getSourceField( + sourceInfo, + sourceParent, + sourceSource, + sourceSourceCollection, + sourceSourceProperty, + ) } // If path length is two, we are summing a group or a child relationship if sourceCollection == parser.GroupFieldName { // If the source collection is a group, then the description of the collection - // to sum is this object. + // to sum is this object. fieldDescription, fieldDescriptionFound := sourceInfo.collectionDescription.GetField(sourceProperty) if !fieldDescriptionFound { - return client.FieldDescription{}, fmt.Errorf("Unable to find field description for field: %s", sourceProperty) + return client.FieldDescription{}, + fmt.Errorf("Unable to find field description for field: %s", sourceProperty) } return fieldDescription, nil } else { @@ -131,7 +161,8 @@ func (p *Planner) getSourceField(sourceInfo *sourceInfo, parent *parser.Select, } fieldDescription, fieldDescriptionFound := collectionDescription.GetField(sourceProperty) if !fieldDescriptionFound { - return client.FieldDescription{}, fmt.Errorf("Unable to find child field description for field: %s", sourceProperty) + return client.FieldDescription{}, + fmt.Errorf("Unable to find child field description for field: %s", sourceProperty) } return fieldDescription, nil }