| 192 | return result |
| 193 | |
| 194 | def _extract_schema(self, jsons: List[Dict[str, Any]], schema: Optional[Dict[str, Any]] = None, |
| 195 | prefix: str = '') -> Dict[str, Any]: |
| 196 | schema = schema or {} |
| 197 | for json_obj in jsons: |
| 198 | for key, value in json_obj.items(): |
| 199 | if isinstance(value, dict): |
| 200 | if (sub_schema := schema.get(key, {})) and not isinstance(sub_schema, dict): |
| 201 | raise ValueError(f'Key {key} already in schema with type {sub_schema} at {prefix}.') |
| 202 | schema[key] = self._extract_schema(value, sub_schema, prefix=f'{prefix}.{key}' if prefix else key) |
| 203 | else: |
| 204 | if key not in schema: schema[key] = type(value) |
| 205 | elif schema[key] != type(value): |
| 206 | raise ValueError(f'Key {key} already in schema with type {schema[key]} at {prefix}.') |
| 207 | return schema |
| 208 | |
| 209 | def _distinct_aggregate(self, jsons: List[Dict[str, Any]]) -> List[Dict[str, Any]]: |
| 210 | if len(jsons) <= 1: return jsons |