Commit 2f7a128
authored
fix(schema-compiler): Handle measures with dimension-only member expressions (#9335)
`fullKeyQueryAggregate` is using measure.cube() a lot, like for grouping measures to key cube
This can be wrong for measure targeting view: we want to attach measure to subquery for its definition cube, and there should be no subquery for view itself
It's expected that `fullKeyQueryAggregateMeasures` would resolve and prepare all measures from its original form in query to actual leaf measures in cubes, then build subqueries with those, and then `joinFullKeyQueryAggregate` would use `renderedReference` to point to these leaf measures
Hard case is a measure that:
* targeting view
* is a member expression
* references only dimensions from that view
Measure like that are "leaf" - there's nowhere to push it, member expression has to be directly in leaf subquery
If measure references dimension from a single cube it can be multiplied (think `SUM(${view.deep_dimension})`)
So, three points:
* it must be accounted for in `multipliedMeasures`
* it must be attached to a proper cube subquery
* it must use `renderedReference` correctly
`collectRootMeasureToHieararchy` will not drop such measure completely. Now it will check is there's 0 measures collected, try to collect all referenced members to gather used cubes and detect multiplication, and add new measure in hierarchy.
Because new returned measure is patched, it will be attached to correct cube subquery in `fullKeyQueryAggregate`
Then `outerMeasuresJoinFullKeyQueryAggregate` needs to generate proper alias for it, so outer unpatched measure would pick up alias from inner patched one
Another special case of those measures are zero reference measures. It's member expression has no reference to any member at all, and it NOT a `COUNT(*)`. Like a `SUM(1)`. Measures like that are considered regular, and are calculated on top of join tree.1 parent b5701e3 commit 2f7a128
File tree
2 files changed
+791
-6
lines changed- packages/cubejs-schema-compiler
- src/adapter
- test/integration/postgres
2 files changed
+791
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1055 | 1055 | | |
1056 | 1056 | | |
1057 | 1057 | | |
1058 | | - | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
1059 | 1065 | | |
1060 | | - | |
1061 | 1066 | | |
1062 | 1067 | | |
1063 | 1068 | | |
| |||
1692 | 1697 | | |
1693 | 1698 | | |
1694 | 1699 | | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
1695 | 1749 | | |
1696 | 1750 | | |
1697 | 1751 | | |
| |||
1710 | 1764 | | |
1711 | 1765 | | |
1712 | 1766 | | |
1713 | | - | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
1714 | 1779 | | |
1715 | 1780 | | |
1716 | 1781 | | |
| |||
1977 | 2042 | | |
1978 | 2043 | | |
1979 | 2044 | | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
1980 | 2053 | | |
1981 | | - | |
1982 | | - | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
1983 | 2066 | | |
1984 | 2067 | | |
1985 | 2068 | | |
| 2069 | + | |
1986 | 2070 | | |
1987 | | - | |
| 2071 | + | |
1988 | 2072 | | |
1989 | 2073 | | |
1990 | 2074 | | |
| |||
0 commit comments