Skip to content

Commit

Permalink
Fix golint warnings in the gql package. (#3639)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmr authored Jul 8, 2019
1 parent 536cae7 commit 5ea2553
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions gql/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (s *mathTreeStack) peek() *MathTree {
return s.a[len(s.a)-1]
}

// MathTree represents math operations in tree form for evaluation.
type MathTree struct {
Fn string
Var string
Expand Down
15 changes: 11 additions & 4 deletions gql/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

var (
ErrInvalidUID = errors.New("UID has to be greater than one")
errInvalidUID = errors.New("UID has to be greater than one")
)

// Mutation stores the strings corresponding to set and delete operations.
Expand All @@ -37,19 +37,21 @@ type Mutation struct {
Del []*api.NQuad
}

// Gets the uid corresponding
// ParseUid parses the given string into an UID. This method returns with an error
// if the string cannot be parsed or the parsed UID is zero.
func ParseUid(xid string) (uint64, error) {
// If string represents a UID, convert to uint64 and return.
uid, err := strconv.ParseUint(xid, 0, 64)
if err != nil {
return 0, err
}
if uid == 0 {
return 0, ErrInvalidUID
return 0, errInvalidUID
}
return uid, nil
}

// NQuad is an alias for the NQuad type in the API protobuf library.
type NQuad struct {
*api.NQuad
}
Expand Down Expand Up @@ -97,7 +99,7 @@ func byteVal(nq NQuad) ([]byte, types.TypeID, error) {
}

func toUid(subject string, newToUid map[string]uint64) (uid uint64, err error) {
if id, err := ParseUid(subject); err == nil || err == ErrInvalidUID {
if id, err := ParseUid(subject); err == nil || err == errInvalidUID {
return id, err
}
// It's an xid
Expand All @@ -119,13 +121,16 @@ func (nq NQuad) createEdgePrototype(subjectUid uint64) *pb.DirectedEdge {
}
}

// CreateUidEdge returns a Directed edge connecting the given subject and object UIDs.
func (nq NQuad) CreateUidEdge(subjectUid uint64, objectUid uint64) *pb.DirectedEdge {
out := nq.createEdgePrototype(subjectUid)
out.ValueId = objectUid
out.ValueType = pb.Posting_UID
return out
}

// CreateValueEdge returns a DirectedEdge with the given subject. The predicate, label,
// language, and facet values are derived from the NQuad.
func (nq NQuad) CreateValueEdge(subjectUid uint64) (*pb.DirectedEdge, error) {
var err error

Expand All @@ -136,6 +141,8 @@ func (nq NQuad) CreateValueEdge(subjectUid uint64) (*pb.DirectedEdge, error) {
return out, nil
}

// ToDeletePredEdge takes an NQuad of the form '* p *' and returns the equivalent
// directed edge. Returns an error if the NQuad does not have the expected form.
func (nq NQuad) ToDeletePredEdge() (*pb.DirectedEdge, error) {
if nq.Subject != x.Star && nq.ObjectValue.String() != x.Star {
return &emptyEdge, errors.Errorf("Subject and object both should be *. Got: %+v", nq)
Expand Down
21 changes: 14 additions & 7 deletions gql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ type GraphQuery struct {
IsEmpty bool
}

// RecurseArgs stores the arguments needed to process the @recurse directive.
type RecurseArgs struct {
Depth uint64
AllowLoop bool
}

// GroupByAttr stores the arguments needed to process the @groupby directive.
type GroupByAttr struct {
Attr string
Alias string
Expand All @@ -101,15 +103,15 @@ type pair struct {
Val string
}

// Internal structure for doing dfs on fragments.
// fragmentNode is an internal structure for doing dfs on fragments.
type fragmentNode struct {
Name string
Gq *GraphQuery
Entered bool // Entered in dfs.
Exited bool // Exited in dfs.
}

// Key is fragment names.
// fragmentMap is used to associate fragment names to their corresponding fragmentNode.
type fragmentMap map[string]*fragmentNode

const (
Expand All @@ -119,6 +121,7 @@ const (
ListVar = 3
)

// VarContext stores information about the vars needed to complete a query.
type VarContext struct {
Name string
Typ int // 1 for UID vars, 2 for value vars
Expand All @@ -142,6 +145,7 @@ type FilterTree struct {
Func *Function
}

// Arg stores an argument to a function.
type Arg struct {
Value string
IsValueVar bool // If argument is val(a)
Expand Down Expand Up @@ -194,10 +198,12 @@ var mathOpPrecedence = map[string]int{
"!=": 5,
}

// IsAggregator returns true if the function name is an aggregation function.
func (f *Function) IsAggregator() bool {
return isAggregator(f.Name)
}

// IsPasswordVerifier returns true if the function name is "checkpwd".
func (f *Function) IsPasswordVerifier() bool {
return f.Name == "checkpwd"
}
Expand Down Expand Up @@ -267,6 +273,7 @@ func convertToVarMap(variables map[string]string) (vm varMap) {
return vm
}

// Request stores the query text and the variable mapping.
type Request struct {
Str string
Variables map[string]string
Expand Down Expand Up @@ -2496,12 +2503,12 @@ func isSortkey(k string) bool {
return k == "orderasc" || k == "orderdesc"
}

type Count int
type countType int

const (
notSeen Count = iota // default value
seen // when we see count keyword
seenWithPred // when we see a predicate within count.
notSeen countType = iota // default value
seen // when we see count keyword
seenWithPred // when we see a predicate within count.
)

func validateEmptyBlockItem(it *lex.ItemIterator, val string) error {
Expand Down Expand Up @@ -2533,7 +2540,7 @@ func godeep(it *lex.ItemIterator, gq *GraphQuery) error {
if gq == nil {
return it.Errorf("Bad nesting of predicates or functions")
}
var count Count
var count countType
var alias, varName string
curp := gq // Used to track current node, for nesting.
for it.Next() {
Expand Down

0 comments on commit 5ea2553

Please sign in to comment.