April 2026
Batch Ingestion by SQL
A batch pipeline that loads ERP data from a Google Cloud Storage folder into the Carol data platform — auto-discovering what to load and generating the BigQuery SQL from a single tenant id.

Overview
Batch ingestion of ERP (Protheus) data into the Carol data platform. A scheduled transfer drops files into a GCS landing folder; this module reads them once into a native BigQuery table, auto-detects which staging tables received data from GCS object metadata, and writes each staging for the customer tenant and every linked "unified" tenant with the MDM metadata Carol expects. The design goal is minimal input: give it a tenant id and it resolves everything else — which stagings landed, their connector, fields, crosswalks, and the tenant's unified tenants — automatically.
Engineering highlights
- Single-read ingestion — one generated SQL reads all landed files into a clustered, auto-expiring "mother" table, keeping each record as opaque JSON with its GCS metadata tags; a timestamp parameter windows by receipt time.
- Metadata-driven detection — staging table, connector, and batch identifiers come from GCS object custom metadata (via a BigLake object table), not file paths or content.
- Unified-tenant fan-out — for each linked tenant it emits a table with the field intersection, computes both MDM ids, and optionally packs dropped fields into a JSON column behind a per-tenant flag.
- Operational safety —
--dry-run,--detect-only, and--resumemodes; injected identifiers validated against strict regexes; every real run appends a summary row (record counts, job ids, timings) to a partitioned run-log table. - Offline test suite — 11 tests covering SQL generation, tenant/flag resolution, unified discovery, and the dry-run read/write split, with no BigQuery dependency.
Stack
Python 3.10+ · Google BigQuery · Google Cloud Storage · BigLake object tables · Google Workflows · Carol / Protheus (TOTVS) data platform
