Skip to content
Snippets Groups Projects
Commit 4c26730a authored by Leah Tacke genannt Unterberg's avatar Leah Tacke genannt Unterberg
Browse files

actually fixed into_mappings.py

parent d926517d
Branches
No related tags found
No related merge requests found
from mitm_tooling.extraction.sql.data_models import SourceDBType
from mitm_tooling.extraction.sql.mapping import ConceptMapping, ForeignRelation
from mitm_tooling.representation import Header, SQLRepresentationSchema
from mitm_tooling.representation.sql_representation import has_type_tables
def sql_rep_into_mappings(header: Header, sql_rep_schema: SQLRepresentationSchema) -> list[ConceptMapping]:
mitm_def = header.mitm_def
cms = []
for he in header.header_entries:
if (type_t := sql_rep_schema.type_tables[he.concept][he.type_name]) is not None:
concept_properties, relations = mitm_def.get(he.concept)
concept_properties, relations = mitm_def.get(he.concept)
base_table = None
if (type_t := sql_rep_schema.type_tables.get(he.concept, {}).get(he.type_name)) is not None:
base_table = type_t
elif (concept_t := sql_rep_schema.concept_tables.get(he.concept)) is not None:
base_table = concept_t
if base_table is not None:
cms.append(
ConceptMapping(
mitm=header.mitm,
concept=he.concept,
base_table=(SourceDBType.OriginalDB, type_t.schema, type_t.name),
kind_col='kind' if 'kind' in type_t.columns else None,
base_table=(SourceDBType.OriginalDB, base_table.schema, base_table.name),
kind_col='kind' if 'kind' in base_table.columns else None,
type_col=concept_properties.typing_concept,
identity_columns=list(relations.identity.keys()),
inline_relations=list(relations.inline.keys()),
......@@ -22,10 +28,10 @@ def sql_rep_into_mappings(header: Header, sql_rep_schema: SQLRepresentationSchem
fk_name: ForeignRelation(
fk_columns=list(fk_info.fk_relations.keys()),
referred_table=(SourceDBType.OriginalDB,
concept_t.schema,
concept_t.name),
target_concept_t.schema,
target_concept_t.name),
) for fk_name, fk_info in relations.foreign.items() if
(concept_t := sql_rep_schema.concept_tables.get(fk_info.target_concept)) is not None
(target_concept_t := sql_rep_schema.concept_tables.get(fk_info.target_concept)) is not None
},
attributes=list(he.attributes),
attribute_dtypes=list(he.attribute_dtypes),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment