The principle of automatic splicing sql

overview

Standard data warehouse design (at least there must be fact tables, dimension entities, and dimension tables), the topic layer is actually a snowflake wide table (multiple dimension tables associated with a single fact table), and the app layer is actually a constellation wide table (multiple Snowflake-shaped wide table union all), standard app logic, should be union all of multiple topic layers, and the left join operation only exists between the fact table and the dimension table.

Specific ideas

Based on the standard data warehouse, manual writing of SQL is actually a logical expansion of the physical fact table. The main logic can be summarized as the following two

  • [Dimension expansion] Based on the snowflake model, we logically expand the fact table according to the binding relationship between the fact table, dimension entities, and dimension tables.
    For example, in the figure below, [Fact Table] is bound to [Business Dimension Entity], and [Business Dimension Entity] is bound to [Business Dimension Table], and [Business Dimension Table] can be extended to [Business Cellular Dimension table], through multiple left joins, all the dimensions in the [merchant dimension table] and its extended dimension tables can be incorporated into the logical wide table.
  • [Indicator extension] Derived indicators can be expanded through the calculation method of original indicators + dimension values; calculated indicators can be expanded through four calculations.

insert image description here

After these two methods of expansion, we get a snowflake model logic wide table.
insert image description here

After completing the construction of the logical wide table of the snowflake model, we expand the calculation indicators across the wide table of the snowflake model on the basis of the consistent dimension. Then the logic wide table of the constellation model is obtained.

insert image description here

After the above-mentioned expansion, we have obtained two logical wide table models of the snowflake model and the constellation model logical wide table, which are collectively referred to as logical wide tables hereinafter.

Guess you like

Origin blog.csdn.net/u011624157/article/details/129137472