Computes the table schema based on hints and column definitions passed during resource creation. `item` parameter is used to resolve table hints based on data. `meta` parameter is taken from Pipe and may further specify table name if variant is to be used
(self, item: TDataItem = None, meta: Any = None)
| 268 | return root_table_template, variant_name, default_table_name |
| 269 | |
| 270 | def compute_table_schema(self, item: TDataItem = None, meta: Any = None) -> TTableSchema: |
| 271 | """Computes the table schema based on hints and column definitions passed during resource creation. |
| 272 | `item` parameter is used to resolve table hints based on data. |
| 273 | `meta` parameter is taken from Pipe and may further specify table name if variant is to be used |
| 274 | """ |
| 275 | root_table_template, variant_name, default_table_name = self._get_root_table_template(meta) |
| 276 | |
| 277 | if not root_table_template: |
| 278 | return new_table(default_table_name, resource=self.name) |
| 279 | |
| 280 | # resolve a copy of a held template |
| 281 | root_table_template = self._clone_hints(root_table_template) |
| 282 | if "table_name" not in root_table_template: |
| 283 | root_table_template["table_name"] = default_table_name |
| 284 | |
| 285 | # if table template present and has dynamic hints, the data item must be provided. |
| 286 | if self._table_name_hint_fun and item is None: |
| 287 | raise DataItemRequiredForDynamicTableHints(self.name, "name") |
| 288 | |
| 289 | # resolve |
| 290 | resolved_template: TResourceHints = { |
| 291 | k: self._resolve_hint(k, item, v) |
| 292 | for k, v in root_table_template.items() |
| 293 | if k not in NATURAL_CALLABLES |
| 294 | } # type: ignore |
| 295 | |
| 296 | if "incremental" in root_table_template: |
| 297 | incremental = root_table_template["incremental"] |
| 298 | if isinstance(incremental, Incremental) and incremental is not Incremental.EMPTY: |
| 299 | resolved_template["incremental"] = incremental |
| 300 | |
| 301 | table_schema = self._hints_to_table_schema(resolved_template) |
| 302 | if not is_nested_table(table_schema): |
| 303 | table_schema["resource"] = self.name |
| 304 | if variant_name: |
| 305 | table_schema["variant_name"] = variant_name |
| 306 | migrate_complex_types(table_schema, warn=True) |
| 307 | validate_dict_ignoring_xkeys( |
| 308 | spec=TTableSchema, |
| 309 | doc=table_schema, |
| 310 | path=f"new_table/{self.name}", |
| 311 | ) |
| 312 | |
| 313 | return table_schema |
| 314 | |
| 315 | def get_nested_hints( |
| 316 | self, |
no test coverage detected