粒度理论:数据管道中的类型级粒度正确性
Grain Theory: Type-Level Granularity Correctness in Data Pipelines
AI总结:
提出粒度理论,通过类型论框架将粒度提升为可组合属性,在数据管道设计时验证粒度正确性,避免扇出陷阱和深坑陷阱。
摘要:
数据转换正确性是数据工程中的一个基本挑战:如何在生产数据上执行之前验证管道产生正确结果?现有实践依赖于对物化数据的迭代测试。错误的一个常见原因是缺乏对粒度(数据的详细程度)的形式化推理,因此转换无意中改变了粒度,导致扇出陷阱(度量重复)和深坑陷阱(数据丢失)等病态现象。我们引入粒度理论,这是一个类型论框架,将粒度提升为任何代数数据类型的可组合属性。它分为两个阶段。首先,数据的指称:粒度本身,由不可约性和同构性定义,不涉及函数依赖;三种粒度关系形成一个有界格,其公理恢复了乘积类型上的Armstrong公理;实体键作为派生粒度;以及由粒度决定的行为类——共同构成类型级三元组(G[R], EK[R], BC[R])。其次,转换的指称:每个转换$h$都有一个粒度提升$φ(h)$。对于关系代数下的乘积类型集合,我们证明了一个等值连接粒度推理定理,并提出了CalcG,一个可判定算法,该算法在管道DAG上组合粒度提升。核心定理——粒度同态——将这两个阶段联系在一起:粒度投影与转换可交换,并且粒度提升可复合($φ(h_2 \circ h_1) = φ(h_2) \circ φ(h_1)$)。因此,粒度正确性可以在设计时验证,在任何代码或查询运行之前。作为推论,扇出陷阱表现为模式可检测的粒度关系违反;深坑陷阱定位到特定的排序链模式;而行为类违反,例如在错误集合类型上的时间点查询,成为编译时类型错误。所有定理均在Lean 4中机械验证。
英文摘要:
Data pipelines fail silently when a transformation changes the grain of the data, the level of detail each element represents, without the designer intending it; fan traps and chasm traps are the familiar symptoms. Dimensional modeling has used grain informally since the 1990s. We define grain by irreducibility and isomorphism alone, with no appeal to functional dependencies, and compute it compositionally over products, sums and the inductive and coinductive fixed points, so it is defined on arrays, event streams and the other nested and recursive types where dependency theory has no referent, and the grain of a type's entity is its entity key, where collections of different grain integrate. Grain is more than a key: one structure under different declared grains denotes different things. The grain ordering is a partial order on types, axiomatized by Armstrong-style axioms whose completeness transfers on product types. For the relational algebra we prove inference rules, chief among them an equi-join theorem computing the exact, minimal grain. Grain projection commutes with transformation and grain lifts compose, and the algorithm CalcG decides pipeline grain-correctness at design time, from the schema alone, in time linear in the pipeline. The errors then follow from a single comparison: a grain the calculus computes, set against a grain the design intends, stands in exactly one relation to it in the grain ordering, and that position names the failure. Fan traps, dropped grain fields, ungrounded multi-version reads, wrong-grain aggregations and behavioral-class violations are the instances of this classification; chasm traps, a data-instance failure the theory does not model, are localized but not decided. The theory is mechanized in Lean 4.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。