Skip to content

Commit

Permalink
linter line limit stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Apr 12, 2022
1 parent 9162787 commit 08bef70
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions query/graphql/planner/sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 08bef70

Please sign in to comment.