// Given a selection set, return the collection of fields (a mapping of response
// name to field ASTs and definitions) as well as a list of fragment names
// referenced via fragment spreads.
978994
func (rule *overlappingFieldsCanBeMergedRule) getFieldsAndFragmentNames(parentType Named, selectionSet *ast.SelectionSet) *fieldsAndFragmentNames {
	if cached, ok := rule.cacheMap[selectionSet]; ok && cached != nil {
		return cached
	}

	astAndDefs := astAndDefCollection{}
	fieldsOrder := []string{}
	fragmentNames := []string{}
	fragmentNamesMap := map[string]bool{}

	var collectFieldsAndFragmentNames func(parentType Named, selectionSet *ast.SelectionSet)
	collectFieldsAndFragmentNames = func(parentType Named, selectionSet *ast.SelectionSet) {
		for _, selection := range selectionSet.Selections {
			switch selection := selection.(type) {
			case *ast.Field:
				fieldName := ""
				if selection.Name != nil {
					fieldName = selection.Name.Value
				}
				var fieldDef *FieldDefinition
				if parentType, ok := parentType.(*Object); ok && parentType != nil {
					fieldDef, _ = parentType.Fields()[fieldName]
				}
				if parentType, ok := parentType.(*Interface); ok && parentType != nil {
					fieldDef, _ = parentType.Fields()[fieldName]
				}

				responseName := fieldName
				if selection.Alias != nil {
					responseName = selection.Alias.Value
				}

				fieldDefPairs, ok := astAndDefs[responseName]
				if !ok || fieldDefPairs == nil {
					fieldDefPairs = []*fieldDefPair{}
					fieldsOrder = append(fieldsOrder, responseName)
				}

				fieldDefPairs = append(fieldDefPairs, &fieldDefPair{
					ParentType: parentType,
					Field:      selection,
					FieldDef:   fieldDef,
				})
				astAndDefs[responseName] = fieldDefPairs
			case *ast.FragmentSpread:
				fieldName := ""
				if selection.Name != nil {
					fieldName = selection.Name.Value
				}
				if val, ok := fragmentNamesMap[fieldName]; !ok || !val {
					fragmentNamesMap[fieldName] = true
					fragmentNames = append(fragmentNames, fieldName)
				}
			case *ast.InlineFragment:
				typeCondition := selection.TypeCondition
				inlineFragmentType := parentType
				if typeCondition != nil {
					ttype, err := typeFromAST(*(rule.context.Schema()), typeCondition)
					if err == nil {
						inlineFragmentType, _ = ttype.(Named)
					}
				}
				collectFieldsAndFragmentNames(inlineFragmentType, selection.SelectionSet)
			}
		}
	}
	collectFieldsAndFragmentNames(parentType, selectionSet)

	cached := &fieldsAndFragmentNames{
		fieldMap:      astAndDefs,
		fieldsOrder:   fieldsOrder,
		fragmentNames: fragmentNames,
	}

	rule.cacheMap[selectionSet] = cached
	return cached
}
51238
func (ca Actions) Selection() []string {
	keys := make([]string, 0, len(ca))
	for _, a := range ca {
		keys = append(keys, a.Name)
	}
	return keys
}
1271149
func (c *Collection) FieldIndexKey(fieldName string) (string, error) {
	return c.spec.fieldIndexKey(fieldName)
}
62108
func (r *Result) FieldSchemata() map[FieldKey][]*spec.Schema {
	if r.cachedFieldSchemta != nil {
		return r.cachedFieldSchemta
	}

	ret := make(map[FieldKey][]*spec.Schema, len(r.fieldSchemata))
	for _, fs := range r.fieldSchemata {
		key := NewFieldKey(fs.obj, fs.field)
		if fs.schemata.one != nil {
			ret[key] = append(ret[key], fs.schemata.one)
		} else if len(fs.schemata.multiple) > 0 {
			ret[key] = append(ret[key], fs.schemata.multiple...)
		}
	}
	r.cachedFieldSchemta = ret
	return ret
}
578837
func (self *Collection) KeyFields() []Field {
	keys := []Field{
		Field{
			Name:     self.GetIdentityFieldName(),
			Type:     self.IdentityFieldType,
			Identity: true,
			Key:      true,
			Required: true,
		},
	}

	// append additional key fields
	for _, field := range self.Fields {
		if field.Key {
			keys = append(keys, field)
		}
	}

	return keys
}
989188
func (s *FieldService) GetList() ([]Field, *Response, error) {
	apiEndpoint := "rest/api/2/field"
	req, err := s.client.NewRequest("GET", apiEndpoint, nil)
	if err != nil {
		return nil, nil, err
	}

	fieldList := []Field{}
	resp, err := s.client.Do(req, &fieldList)
	if err != nil {
		return nil, resp, NewJiraError(resp, err)
	}
	return fieldList, resp, nil
}
1017988
func (m *Mapper) FieldsByName(v reflect.Value, names []string) []reflect.Value {
	v = reflect.Indirect(v)
	mustBe(v, reflect.Struct)

	tm := m.TypeMap(v.Type())
	vals := make([]reflect.Value, 0, len(names))
	for _, name := range names {
		fi, ok := tm.Names[name]
		if !ok {
			vals = append(vals, *new(reflect.Value))
		} else {
			vals = append(vals, FieldByIndexes(v, fi.Index))
		}
	}
	return vals
}
915616
func (e *enum) FieldsStr() string {
	var names []string
	for _, f := range e.Fields {
		names = append(names, f.Name)
	}
	return strings.Join(names, ", ")
}
21703
func (s *SearchService) Fields(fields ...string) *SearchService {
	s.searchSource = s.searchSource.Fields(fields...)
	return s
}
1245355
func (r *SearchRequest) NoStoredFields() *SearchRequest {
	r.searchSource = r.searchSource.NoStoredFields()
	return r
}
225695
func (mem *memNamedMapping) ListFields(name string) map[string][]string {
	mem.access.RLock()
	defer mem.access.RUnlock()

	fields := make(map[string][]string)

	item, found := mem.nameToIdx[name]
	if found {
		for field := range item.indexed {
			fields[field] = []string{}
			for _, value := range item.indexed[field] {
				fields[field] = append(fields[field], value)
			}
		}
	}

	return fields
}
259809
func (nr *nameResolver) createResultFields(field *ast.SelectField) (rfs []*ast.ResultField) {
	ctx := nr.currentContext()
	if field.WildCard != nil {
		if len(ctx.tables) == 0 {
			nr.Err = errors.New("no table used")
			return
		}
		tableRfs := []*ast.ResultField{}
		if field.WildCard.Table.L == "" {
			for _, v := range ctx.tables {
				tableRfs = append(tableRfs, v.GetResultFields()...)
			}
		} else {
			name := nr.tableUniqueName(field.WildCard.Schema, field.WildCard.Table)
			tableIdx, ok1 := ctx.tableMap[name]
			derivedTableIdx, ok2 := ctx.derivedTableMap[name]
			if !ok1 && !ok2 {
				nr.Err = errors.Errorf("unknown table %s.", field.WildCard.Table.O)
			}
			if ok1 {
				tableRfs = ctx.tables[tableIdx].GetResultFields()
			}
			if ok2 {
				tableRfs = append(tableRfs, ctx.tables[derivedTableIdx].GetResultFields()...)
			}

		}
		for _, trf := range tableRfs {
			trf.Referenced = true
			// Convert it to ColumnNameExpr
			cn := &ast.ColumnName{
				Schema: trf.DBName,
				Table:  trf.Table.Name,
				Name:   trf.ColumnAsName,
			}
			cnExpr := &ast.ColumnNameExpr{
				Name:  cn,
				Refer: trf,
			}
			ast.SetFlag(cnExpr)
			cnExpr.SetType(trf.Expr.GetType())
			rf := *trf
			rf.Expr = cnExpr
			rfs = append(rfs, &rf)
		}
		return
	}
	// The column is visited before so it must has been resolved already.
	rf := &ast.ResultField{ColumnAsName: field.AsName}
	innerExpr := getInnerFromParentheses(field.Expr)
	switch v := innerExpr.(type) {
	case *ast.ColumnNameExpr:
		rf.Column = v.Refer.Column
		rf.Table = v.Refer.Table
		rf.DBName = v.Refer.DBName
		rf.TableName = v.Refer.TableName
		rf.Expr = v
	default:
		rf.Column = &model.ColumnInfo{} // Empty column info.
		rf.Table = &model.TableInfo{}   // Empty table info.
		rf.Expr = v
	}
	if field.AsName.L == "" {
		switch x := innerExpr.(type) {
		case *ast.ColumnNameExpr:
			rf.ColumnAsName = model.NewCIStr(x.Name.Name.O)
		case *ast.ValueExpr:
			if innerExpr.Text() != "" {
				rf.ColumnAsName = model.NewCIStr(innerExpr.Text())
			} else {
				rf.ColumnAsName = model.NewCIStr(field.Text())
			}
		default:
			rf.ColumnAsName = model.NewCIStr(field.Text())
		}
	}
	rfs = append(rfs, rf)
	return
}
847416
func (v *Validator) Fields() []string {
	fields := []string{}
	for _, vr := range v.results {
		fields = append(fields, vr.field)
	}
	return fields
}
936133
func (set LiteralFieldSet) ContainsAll(i ...LiteralField) bool {
	for _, v := range i {
		if !set.Contains(v) {
			return false
		}
	}
	return true
}
878660
func (t *transpilerState) mapFields(in cursor) (cursor, error) {
	columns := t.stmt.ColumnNames()
	if len(columns) != len(t.stmt.Fields) {
		// TODO(jsternberg): This scenario should not be possible. Replace the use of ColumnNames with a more
		// statically verifiable list of columns when we process the fields from the select statement instead
		// of doing this in the future.
		panic("number of columns does not match the number of fields")
	}

	properties := make([]*semantic.Property, 0, len(t.stmt.Fields)+1)
	properties = append(properties, &semantic.Property{
		Key: &semantic.Identifier{Name: execute.DefaultTimeColLabel},
		Value: &semantic.MemberExpression{
			Object: &semantic.IdentifierExpression{
				Name: "r",
			},
			Property: execute.DefaultTimeColLabel,
		},
	})
	for i, f := range t.stmt.Fields {
		if ref, ok := f.Expr.(*influxql.VarRef); ok && ref.Val == "time" {
			// Skip past any time columns.
			continue
		}
		value, err := t.mapField(f.Expr, in)
		if err != nil {
			return nil, err
		}
		properties = append(properties, &semantic.Property{
			Key:   &semantic.Identifier{Name: columns[i]},
			Value: value,
		})
	}
	id := t.op("map", &transformations.MapOpSpec{
		Fn: &semantic.FunctionExpression{
			Block: &semantic.FunctionBlock{
				Parameters: &semantic.FunctionParameters{
					List: []*semantic.FunctionParameter{{
						Key: &semantic.Identifier{Name: "r"},
					}},
				},
				Body: &semantic.ObjectExpression{
					Properties: properties,
				},
			},
		},
		MergeKey: true,
	}, in.ID())
	return &mapCursor{id: id}, nil
}
1102306
func SelectResponseFromHTTPResponse(b []byte) (*SelectResponse, error) {
	j, err := BytesToJSON(&b)
	if err != nil {
		return nil, err
	}

	resp, err := BuildResponse(j)
	if err != nil {
		return nil, err
	}

	return resp, nil
}
1351032
func (scope *Scope) Fields() []*Field {
	if scope.fields == nil {
		var (
			fields             []*Field
			indirectScopeValue = scope.IndirectValue()
			isStruct           = indirectScopeValue.Kind() == reflect.Struct
		)

		for _, structField := range scope.GetModelStruct().StructFields {
			if isStruct {
				fieldValue := indirectScopeValue
				for _, name := range structField.Names {
					if fieldValue.Kind() == reflect.Ptr && fieldValue.IsNil() {
						fieldValue.Set(reflect.New(fieldValue.Type().Elem()))
					}
					fieldValue = reflect.Indirect(fieldValue).FieldByName(name)
				}
				fields = append(fields, &Field{StructField: structField, Field: fieldValue, IsBlank: isBlank(fieldValue)})
			} else {
				fields = append(fields, &Field{StructField: structField, IsBlank: true})
			}
		}
		scope.fields = &fields
	}

	return *scope.fields
}