From 6716b97a3932a25c470a3ecf7746fb9dd39983c8 Mon Sep 17 00:00:00 2001 From: Vikram Rangnekar Date: Sun, 7 Jun 2020 17:03:09 -0400 Subject: [PATCH] fix: duplicate fragment crash issue --- core/internal/qcode/parse.go | 40 +++++++----------------------------- core/internal/qcode/qcode.go | 1 - 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/core/internal/qcode/parse.go b/core/internal/qcode/parse.go index 5d1b87e..ce09932 100644 --- a/core/internal/qcode/parse.go +++ b/core/internal/qcode/parse.go @@ -330,8 +330,6 @@ func (p *Parser) parseFields(fields []Field) ([]Field, error) { return nil, fmt.Errorf("unexpected token: %s", p.peekNext()) } - // fm := make(map[uint64]struct{}) - for { if p.peek(itemEOF) { p.ignore() @@ -384,23 +382,10 @@ func (p *Parser) parseFields(fields []Field) ([]Field, error) { n := int32(len(fields)) fields = append(fields, fr.Fields...) - for i := int(n); i < len(fields); i++ { - f := &fields[i] - f.ID = int32(i) - - // var name string - - // if f.Alias != "" { - // name = f.Alias - // } else { - // name = f.Name - // } - - // if _, ok := fm[name]; ok { - // continue - // } else { - // fm[name] = struct{}{} - // } + for i := 0; i < len(fr.Fields); i++ { + k := (n + int32(i)) + f := &fields[k] + f.ID = int32(k) // If this is the top-level point the parent to the parent of the // previous field. @@ -415,6 +400,9 @@ func (p *Parser) parseFields(fields []Field) ([]Field, error) { f.ParentID += n } + f.Children = make([]int32, len(f.Children)) + copy(f.Children, fr.Fields[i].Children) + // Update all the children which is needed. for j := range f.Children { f.Children[j] += n @@ -433,20 +421,6 @@ func (p *Parser) parseFields(fields []Field) ([]Field, error) { return nil, err } - // var name string - - // if f.Alias != "" { - // name = f.Alias - // } else { - // name = f.Name - // } - - // if _, ok := fm[name]; ok { - // continue - // } else { - // fm[name] = struct{}{} - // } - if st.Len() == 0 { f.ParentID = -1 } else { diff --git a/core/internal/qcode/qcode.go b/core/internal/qcode/qcode.go index c65d0e6..c611eb0 100644 --- a/core/internal/qcode/qcode.go +++ b/core/internal/qcode/qcode.go @@ -450,7 +450,6 @@ func (com *Compiler) compileQuery(qc *QCode, op *Operation, role string) error { } col := Column{Name: f.Name, FieldName: fname} - s.Cols = append(s.Cols, col) }