Hydrate an index-field option value to construct something like:: { 'index_field': { 'DoubleOptions': { 'DefaultValue': 0.0 } } }
(params, container, cli_type, key, value)
| 29 | |
| 30 | |
| 31 | def index_hydrate(params, container, cli_type, key, value): |
| 32 | """ |
| 33 | Hydrate an index-field option value to construct something like:: |
| 34 | |
| 35 | { |
| 36 | 'index_field': { |
| 37 | 'DoubleOptions': { |
| 38 | 'DefaultValue': 0.0 |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | """ |
| 43 | if 'IndexField' not in params: |
| 44 | params['IndexField'] = {} |
| 45 | |
| 46 | if 'IndexFieldType' not in params['IndexField']: |
| 47 | raise ParamValidationError('You must pass the --type option.') |
| 48 | |
| 49 | # Find the type and transform it for the type options field name |
| 50 | # E.g: int-array => IntArray |
| 51 | _type = params['IndexField']['IndexFieldType'] |
| 52 | _type = ''.join([i.capitalize() for i in _type.split('-')]) |
| 53 | |
| 54 | # ``index_field`` of type ``latlon`` is mapped to ``Latlon``. |
| 55 | # However, it is defined as ``LatLon`` in the model so it needs to |
| 56 | # be changed. |
| 57 | if _type == 'Latlon': |
| 58 | _type = 'LatLon' |
| 59 | |
| 60 | # Transform string value to the correct type? |
| 61 | if key.split(SEP)[-1] == 'DefaultValue': |
| 62 | value = DEFAULT_VALUE_TYPE_MAP.get(_type, lambda x: x)(value) |
| 63 | |
| 64 | # Set the proper options field |
| 65 | if _type + 'Options' not in params['IndexField']: |
| 66 | params['IndexField'][_type + 'Options'] = {} |
| 67 | |
| 68 | params['IndexField'][_type + 'Options'][key.split(SEP)[-1]] = value |
| 69 | |
| 70 | |
| 71 | FLATTEN_CONFIG = { |
nothing calls this directly
no test coverage detected