Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ Any field (column or relation) can be excluded from the data model entirely by s
The field will be absent from the target table schema and all data for it will be silently dropped during XML
parsing. This is useful for PII columns, large binary blobs, or fields that are irrelevant for analysis.

For a skipped relation, the child table is also pruned from the model unless it is referenced by another relation
elsewhere in the schema.
For a skipped relation, the child table and the tables beneath it are also pruned from the model, unless they are
referenced by another relation elsewhere in the schema.

Configuration: `"transform": "skip"`

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "xml2db"
version = "0.14.0"
version = "0.15.0"
authors = [
{ name="Commission de régulation de l'énergie", email="opensource@cre.fr" },
]
Expand Down
17 changes: 10 additions & 7 deletions src/xml2db/table/transformed_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@ def simplify_table(self) -> Tuple[dict, dict]:
out_fields.append(("col", field_name, field))

else:
# skip before simplifying the child table, which would keep the tables beneath it
field_config = self.config.get("fields", {}).get(field_name, {})
if field_config.get("transform") == "skip":
if field_type == "rel1":
del self.relations_1[field_name]
elif field_type == "reln":
del self.relations_n[field_name]
continue

# simplify child table
(
types_transforms_child,
Expand All @@ -317,13 +326,7 @@ def simplify_table(self) -> Tuple[dict, dict]:

# check if children can be "elevated" to the upper level
transform = self._get_field_transform(field_type, field_name)
if transform == "skip":
if field_type == "rel1":
del self.relations_1[field_name]
elif field_type == "reln":
del self.relations_n[field_name]
# don't add to out_fields, don't set keep_table, don't add to fields_transforms
elif transform is not None:
if transform is not None:
if field_type == "rel1":
elevated_fields = self._elevate_relation_1(
field_name, transform
Expand Down
5 changes: 5 additions & 0 deletions tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def test_field_skip_relation():
"item": {
"fields": {
"delivery": {"transform": "skip"},
"product": {"transform": "skip"},
}
}
}
Expand All @@ -198,6 +199,10 @@ def test_field_skip_relation():

# deliveryType has no other parents, so it should be pruned from the model
assert "deliveryType" not in model.tables
# types only reachable through a skipped field are pruned as well
assert "producttype" not in model.tables
assert "intfeaturetype" not in model.tables
assert "stringfeaturetype" not in model.tables

# parsing works even for XML files that contain <delivery>; delivery data is silently dropped
doc = model.parse_xml(str(os.path.join(models_path, "orders", "xml", "order3.xml")))
Expand Down
Loading