Convert single field mapping to multi field mapping
@param {object} mapping - single field mapping
@return {object} multi field mapping
558094
function singleToMulti(mapping) {
  const newMapping = {};
  Object.entries(mapping.mapping).forEach(m => {
    newMapping[m[0]] = [m[1]];
  });
  return {
    created: mapping.created,
    fields: [mapping.field],
    key: mapping.key,
    mapping: newMapping
  };
}
992358
function getMappingType(mapping) {
  if (is.array(mapping)) {
    return every(isMixed, mapping) ? 'mixed' : 'array';
  }
  if (is.object(mapping)) return 'map';
  return 'unknown';
}
346536
private Map<String, Object> flatten(Map<String, Object> map) {
		Map<String, Object> result = new LinkedHashMap<>();
		flatten(null, result, map);
		return result;
	}
522671
def convert_mapping(self, mapping):
        """"""
        if isinstance(mapping, dict):
            return self.convert_items(iteritems(mapping))
        return self.convert_items(mapping)
707308
function flattenFields(fields) {
	const fieldsObj = {};
	fields.forEach(function(field) {
		if (!fields.hasOwnProperty(field.name)) {
			fieldsObj[field.name] = field.value;
		}
	});
	return fieldsObj;
}
880458
public Schema mapper(String field, Mapper mapper) {
        if (mappers == null) {
            mappers = new LinkedHashMap<>();
        }
        mappers.put(field, mapper);
        return this;
    }
443793
function _mainMap(data, schema, options) {
    options = options || {};
    var mapping = _map(data, schema, options);
    if (options.removeChanged) {
        var mappedFields = _getMappedFields(schema);
        mappedFields.forEach(function (field) {
            _removeMappedFields(mapping, field);
        });
        mapping = _cleanArrays(mapping);
    }
    return mapping;
}
1339467
@SuppressWarnings("unchecked")
  Map<String, Object> flatten(Map<String, Object> source) {
    Map<String, Object> result = new LinkedHashMap<>();

    for (String key : source.keySet()) {
      Object value = source.get(key);

      if (value instanceof Map) {
        Map<String, Object> subMap = flatten((Map<String, Object>) value);

        for (String subkey : subMap.keySet()) {
          result.put(key + "." + subkey, subMap.get(subkey));
        }
      } else if (value instanceof Collection) {
        StringBuilder joiner = new StringBuilder();
        String separator = "";

        for (Object element : ((Collection) value)) {
          Map<String, Object> subMap = flatten(Collections.singletonMap(key, element));
          joiner
              .append(separator)
              .append(subMap.entrySet().iterator().next().getValue().toString());

          separator = ",";
        }

        result.put(key, joiner.toString());
      } else {
        result.put(key, value);
      }
    }

    return result;
  }
558002
def _merge_mapping(a, b):
    
    for name, b_details in b.items():
        a_details = a[literal_field(name)]
        if a_details.properties and not a_details.type:
            a_details.type = "object"
        if b_details.properties and not b_details.type:
            b_details.type = "object"

        if a_details:
            a_details.type = _merge_type[a_details.type][b_details.type]

            if b_details.type in ES_STRUCT:
                _merge_mapping(a_details.properties, b_details.properties)
        else:
            a[literal_field(name)] = deepcopy(b_details)

    return a
419684
@SuppressWarnings("unchecked")
	private void mergeMap (Map<String, Object> dest, Object source) throws YamlReaderException {
		if (source instanceof Collection) {
			for (Object item : ((Collection<Object>)source))
				mergeMap(dest, item);
		} else if (source instanceof Map) {
			Map<String, Object> map = (Map<String, Object>)source;
			for (Map.Entry<String, Object> entry : map.entrySet()) {
				if (!dest.containsKey(entry.getKey())) dest.put(entry.getKey(), entry.getValue());

			}
		} else
			throw new YamlReaderException("Expected a mapping or a sequence of mappings for a '<<' merge field but found: "
				+ source.getClass().getSimpleName());

	}
622519
public function mapOneToOne(array $mapping)
    {
        $mapping['type'] = self::ONE_TO_ONE;
        $mapping = $this->_validateAndCompleteOneToOneMapping($mapping);
        $this->_storeAssociationMapping($mapping);
    }
903544
public Map<String, FieldType> flatten() {
        if (fields == null || fields.length == 0) {
            return Collections.<String, FieldType> emptyMap();
        }

        Map<String, FieldType> map = new LinkedHashMap<String, FieldType>();

        for (Field nestedField : fields) {
            addSubFieldToMap(map, nestedField, null);
        }

        return map;
    }
992474
public static GroupMapping mapping(Map.Entry<String, Mapping<?>>... fields) {
        return new GroupMapping(Arrays.asList(fields));
    }
72423
protected function cacheMapping($mapping)
    {
        $mapping = array_filter($mapping);
        if ($mapping && !empty($mapping)) {
            $cache = SS_Cache::factory('gridfieldimporter');
            $cache->save(serialize($mapping), $this->cacheKey());
        }
    }
1126767
function apply(data, mapping) {
  const mp = mapping.hasOwnProperty('field') ? singleToMulti(mapping) : mapping;
  data.records
    .filter(rcd => mp.mapping.hasOwnProperty(rcd[mp.key]))
    .forEach(rcd => {
      mp.fields.forEach((fd, i) => {
        rcd[fd.key] = mp.mapping[rcd[mp.key]][i];
      });
    });
  data.fields =  _(data.fields)
    .concat(mp.fields)
    .uniqBy('key')
    .value();
}
306443
public static Map<String,Object> addFieldParam(Map<String,Object> map, Field field)
    {
        if (!field.isNull())
            map.put(field.getFieldName(), field.toString());
        return map;
    }
508798
protected function getMapping($mappings)
    {
        $properties = array();

        foreach ($mappings as $propertyName => $fieldMapping) {
            if (isset($fieldMapping['fieldName'])) {
                $propertyName = $fieldMapping['fieldName'];
            }

            if (isset($fieldMapping['type'])) {
                $properties[$propertyName]['type'] = $fieldMapping['type'];
 
                if ($fieldMapping['type'] == 'attachment' && isset($fieldMapping['fields'])) {
                    $callback = function ($field) {
                        unset($field['type']);
                        return $field;
                    };
                    $properties[$propertyName]['fields'] = array_map($callback, $this->getMapping($fieldMapping['fields']));
                }

                if ($fieldMapping['type'] == 'multi_field' && isset($fieldMapping['fields'])) {
                    $properties[$propertyName]['fields'] = $this->getMapping($fieldMapping['fields']);
                }
  
                if (in_array($fieldMapping['type'], array('nested', 'object')) && isset($fieldMapping['properties'])) {
                    $properties[$propertyName]['properties'] = $this->getMapping($fieldMapping['properties']);
                }
            }

            if (isset($fieldMapping['path'])) {
                $properties[$propertyName]['path'] = $fieldMapping['path'];
            }

            if (isset($fieldMapping['includeInAll'])) {
                $properties[$propertyName]['include_in_all'] = $fieldMapping['includeInAll'];
            }

            if (isset($fieldMapping['nullValue'])) {
                $properties[$propertyName]['null_value'] = $fieldMapping['nullValue'];
            }

            if (isset($fieldMapping['store'])) {
                $properties[$propertyName]['store'] = $fieldMapping['store'];
            }

            if (isset($fieldMapping['index'])) {
                $properties[$propertyName]['index'] = $fieldMapping['index'];
            }

            if (isset($fieldMapping['boost'])) {
                $properties[$propertyName]['boost'] = $fieldMapping['boost'];
            }

            if (isset($fieldMapping['analyzer'])) {
                $properties[$propertyName]['analyzer'] = $fieldMapping['analyzer'];
            }

            if (isset($fieldMapping['indexName'])) {
                $properties[$propertyName]['index_name'] = $fieldMapping['indexName'];
            }

            if (isset($fieldMapping['geohash'])) {
                $properties[$propertyName]['geohash'] = $fieldMapping['geohash'];
            }

            if (isset($fieldMapping['geohash_precision'])) {
                $properties[$propertyName]['geohash_precision'] = $fieldMapping['geohash_precision'];
            }

            if (isset($fieldMapping['geohash_prefix'])) {
                $properties[$propertyName]['geohash_prefix'] = $fieldMapping['geohash_prefix'];
            }
        }

        return $properties;
    }