Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 committed Jan 16, 2019
1 parent dce641a commit cd8864a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions document/field/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const (
TimeType
)

var (
// NumValidFieldTypes returns the number of valid field types.
NumValidFieldTypes = len(validTypes)
)

// IsValid returns true if this is a valid value type.
func (t ValueType) IsValid() bool {
_, exists := validTypes[t]
Expand Down
17 changes: 9 additions & 8 deletions storage/mutable_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ func (s *mutableSeg) QueryRaw(
s.RUnlock()
return nil, err
}

numDocuments := s.mutableSegmentBase.NumDocuments()
s.RUnlock()

defer func() {
for i := range queryFields {
if queryFields[i] != nil {
Expand All @@ -194,9 +198,6 @@ func (s *mutableSeg) QueryRaw(
}
}()

numDocuments := s.mutableSegmentBase.NumDocuments()
s.RUnlock()

// Validate that the fields to order results by have one and only one field type.
hasEmptyResult, err := validateOrderByClauses(allowedFieldTypes, q.OrderBy)
if err != nil {
Expand All @@ -206,10 +207,10 @@ func (s *mutableSeg) QueryRaw(
return nil, nil
}

if queryFields[1] == nil {
if queryFields[rawDocSourceFieldIdx] == nil {
return nil, errNoRawDocSourceField
}
rawDocSourceField, ok := queryFields[1].StringField()
rawDocSourceField, ok := queryFields[rawDocSourceFieldIdx].StringField()
if !ok {
return nil, errNoStringValuesInRawDocSourceField
}
Expand Down Expand Up @@ -369,8 +370,8 @@ func (s *mutableSeg) collectFieldsForRawQueryWithLock(
fieldTypes = make([]field.ValueTypeSet, numFieldsForQuery)
fieldIndexMap = make([]int, numFieldsForQuery)
queryFields = make([]indexfield.DocsField, 0, numFieldsForQuery)
allAllowedFieldTypes := q.AllowedFieldTypes
for fieldHash, fm := range allAllowedFieldTypes {

for fieldHash, fm := range q.AllowedFieldTypes {
builder, exists := s.fields[fieldHash]
if !exists {
// Field does not exist.
Expand All @@ -387,7 +388,7 @@ func (s *mutableSeg) collectFieldsForRawQueryWithLock(
break
}
} else {
fieldTypeSet = make(field.ValueTypeSet, 6)
fieldTypeSet = make(field.ValueTypeSet, field.NumValidFieldTypes)
for _, ft := range fm.AllowedTypesBySourceIdx {
fieldTypeSet.MergeInPlace(ft)
}
Expand Down
7 changes: 6 additions & 1 deletion storage/segment_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import (
xerrors "github.com/m3db/m3x/errors"
)

const (
timestampFieldIdx = 0
rawDocSourceFieldIdx = 1
)

// validateOrderByClauses validates the fields and types specified in the query
// orderBy clauses are valid.
func validateOrderByClauses(
Expand Down Expand Up @@ -45,7 +50,7 @@ func applyFilters(
queryFields []indexfield.DocsField,
numTotalDocs int32,
) (index.DocIDSetIterator, error) {
timestampFieldIdx := fieldIndexMap[0]
timestampFieldIdx := fieldIndexMap[timestampFieldIdx]
timestampField, exists := queryFields[timestampFieldIdx].TimeField()
if !exists {
return nil, errNoTimeValuesInTimestampField
Expand Down

0 comments on commit cd8864a

Please sign in to comment.