fix(warehouses/accelerator): Electricity ingest: Skip files that cannot be processed.#169
Conversation
Occasional gaps in the data is better than no data at all.
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis PR updates merge handling for Iceberg tables with improved error handling, introduces merge_key configuration support in tests with expanded coverage, and modifies exception handling and merge strategy in the electricity SharePoint data pipeline. Changes
Poem
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
warehouses/accelerator/extract_load/electricity_sharepoint/extract_and_load.py (1)
120-124: Consider usinglogging.exceptionfor better diagnostics.The broad exception catch aligns with the PR objective to skip problematic files. However, using
LOGGER.exception()instead ofLOGGER.error()would automatically include the stack trace, which is valuable for diagnosing the root cause of failures later.except Exception as exc: - LOGGER.error( - f"'Error loading {file_name} ({len(file_bytes)} bytes)'. File skipped.\nDetails: {str(exc)}" - ) + LOGGER.exception( + f"Error loading {file_name} ({len(file_bytes)} bytes). File skipped." + ) return Noneelt-common/src/elt_common/dlt_destinations/pyiceberg/pyiceberg.py (1)
434-437: Consider the impact of logging full table data on error.Logging the entire existing table data (
table.scan().to_arrow()) could be problematic for large tables — this may cause performance issues, excessive log sizes, or even memory exhaustion. Consider limiting the output or only logging this at DEBUG level.except ValueError as exc: - logger.info(f"----- Existing data ------\n{table.scan().to_arrow()}") - logger.info(f"----- New data ------\n{table_data}") - raise exc + logger.debug(f"----- Existing data (first 10 rows) ------\n{table.scan().to_arrow().slice(0, 10)}") + logger.debug(f"----- New data (first 10 rows) ------\n{table_data.slice(0, 10)}") + raiseelt-common/tests/e2e_tests/elt_common/dlt_destinations/pyiceberg/test_pyiceberg_pipeline.py (2)
36-38: Add type hint formerge_keyparameter.For consistency with
primary_key, add a type hint tomerge_key.def resource_factory( - data: List[Dict[str, Any]] | None = None, primary_key: str | None = "id", merge_key=None + data: List[Dict[str, Any]] | None = None, primary_key: str | None = "id", merge_key: str | None = None ):
254-255: Consider matching a more specific exception type.Using
pytest.raises(Exception)is quite broad. If the destination raises a specific exception (e.g.,DestinationTerminalExceptionorValueError), matching it would make the test more precise and guard against passing due to unrelated errors.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge base: Disabled due to data retention organization setting
📒 Files selected for processing (3)
elt-common/src/elt_common/dlt_destinations/pyiceberg/pyiceberg.py(1 hunks)elt-common/tests/e2e_tests/elt_common/dlt_destinations/pyiceberg/test_pyiceberg_pipeline.py(5 hunks)warehouses/accelerator/extract_load/electricity_sharepoint/extract_and_load.py(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
elt-common/src/elt_common/dlt_destinations/pyiceberg/pyiceberg.py (1)
elt-common/tests/unit_tests/dlt_destinations/pyiceberg/test_helpers.py (1)
dlt_schema(23-30)
🪛 Ruff (0.14.8)
warehouses/accelerator/extract_load/electricity_sharepoint/extract_and_load.py
120-120: Do not catch blind exception: Exception
(BLE001)
121-123: Use logging.exception instead of logging.error
Replace with exception
(TRY400)
122-122: Use explicit conversion flag
Replace with conversion flag
(RUF010)
🔇 Additional comments (3)
elt-common/src/elt_common/dlt_destinations/pyiceberg/pyiceberg.py (1)
414-421: LGTM! Join columns derived from merge_key when no primary key exists.The logic correctly falls back to extracting columns marked with
merge_key=Truewhen the table schema has no identifier fields. This enables merge operations using either primary_key or merge_key configuration.elt-common/tests/e2e_tests/elt_common/dlt_destinations/pyiceberg/test_pyiceberg_pipeline.py (2)
179-185: Good test coverage for both primary_key and merge_key scenarios.The parameterisation ensures merge operations work correctly whether the identifier is specified via
primary_keyormerge_key.
236-256: Good addition of negative test case.This test ensures that merge operations fail gracefully when neither primary_key nor merge_key is provided, which validates the error handling in the destination layer.
It seems to now conflict with something on GitHub Actions.
Summary
Catch errors loading the electricity consumption data. Users would rather some occasional gaps (that can be backfilled) rather than data loading that just stops.
Refs #166
Summary by CodeRabbit
Release Notes
Bug Fixes
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.