@@ -250,6 +250,18 @@ <h2 id="raises">Raises</h2>
250250 raise AttributeError(f"The defined action {action} is not implemented!") from e
251251 return action_method()
252252
253+ def _generate_table_metadata_legacy(self, table_schema: ts.TableSchema) -> dao.TableMetadata:
254+ """
255+ Generates a TableMetadata object for the table definition using a TableSchema object.
256+
257+ """
258+ table_metadata = dao.TableMetadata()
259+ if table_schema.description:
260+ table_metadata.add_table_description(table_schema.description)
261+ table_metadata.add_column_descriptions({field.name: field.description for field in table_schema.fields})
262+ table_metadata = self._add_field_data_types_to_table_metadata(table_schema, table_metadata)
263+ return table_metadata
264+
253265 def create_out_table_definition_from_schema(self, table_schema: ts.TableSchema, is_sliced: bool = False,
254266 destination: str = '', incremental: bool = None,
255267 enclosure: str = '"', delimiter: str = ',',
@@ -272,17 +284,33 @@ <h2 id="raises">Raises</h2>
272284 TableDefinition object initialized with all table metadata defined in a schema
273285
274286 """
275- table_metadata = self._generate_table_metadata(table_schema)
276- return self.create_out_table_definition(name=table_schema.csv_name,
277- columns=table_schema.field_names,
278- primary_key=table_schema.primary_keys,
279- table_metadata=table_metadata,
280- is_sliced=is_sliced,
281- destination=destination,
282- incremental=incremental,
283- enclosure=enclosure,
284- delimiter=delimiter,
285- delete_where=delete_where)
287+ if self._expects_legacy_manifest():
288+ table_metadata = self._generate_table_metadata_legacy(table_schema)
289+ table_def = self.create_out_table_definition(name=table_schema.csv_name,
290+ columns=table_schema.field_names,
291+ primary_key=table_schema.primary_keys,
292+ table_metadata=table_metadata,
293+ is_sliced=is_sliced,
294+ destination=destination,
295+ incremental=incremental,
296+ enclosure=enclosure,
297+ delimiter=delimiter,
298+ delete_where=delete_where)
299+ else:
300+ schema = self._generate_schema_definition(table_schema)
301+
302+ table_def = self.create_out_table_definition(name=table_schema.csv_name,
303+ primary_key=table_schema.primary_keys,
304+ schema=schema,
305+ is_sliced=is_sliced,
306+ destination=destination,
307+ incremental=incremental,
308+ enclosure=enclosure,
309+ delimiter=delimiter,
310+ delete_where=delete_where,
311+ description=table_schema.description)
312+
313+ return table_def
286314
287315 def get_table_schema_by_name(self, schema_name: str,
288316 schema_folder_path: Optional[str] = None) -> ts.TableSchema:
@@ -325,18 +353,24 @@ <h2 id="raises">Raises</h2>
325353 "from a schema. If a schema folder path is not defined, the schemas folder must be"
326354 " located in the 'src' directory of a component : src/schemas")
327355
328- def _generate_table_metadata (self, table_schema: ts.TableSchema) -> dao.TableMetadata :
356+ def _generate_schema_definition (self, table_schema: ts.TableSchema) -> Dict[str, dao.ColumnDefinition] :
329357 """
330358 Generates a TableMetadata object for the table definition using a TableSchema object.
331359
332360 """
333- table_metadata = dao.TableMetadata()
334- if table_schema.description:
335- table_metadata.add_table_description(table_schema.description)
336- table_metadata.add_column_descriptions({field.name: field.description for field in table_schema.fields})
337- table_metadata = self._add_field_data_types_to_table_metadata(table_schema, table_metadata)
338-
339- return table_metadata
361+ column_definitions = {}
362+ for field in table_schema.fields:
363+ if field.base_type:
364+ data_types = dao.BaseType(field.base_type,
365+ length=field.length,
366+ default=field.default)
367+ else:
368+ data_types = dao.BaseType()
369+ column_definitions[field.name] = dao.ColumnDefinition(data_types=data_types,
370+ nullable=field.nullable,
371+ description=field.description)
372+
373+ return column_definitions
340374
341375 @staticmethod
342376 def _add_field_data_types_to_table_metadata(table_schema: ts.TableSchema,
0 commit comments