@@ -1094,7 +1094,7 @@ statement ok
10941094CREATE TABLE fanout_minmax_people (id INT, age INT);
10951095
10961096statement ok
1097- INSERT INTO fanout_minmax_people VALUES (1, 30), (2, 25), (3, 40 ), (4, 15);
1097+ INSERT INTO fanout_minmax_people VALUES (1, 30), (2, 25), (3, 35 ), (4, 15), (5, 50 );
10981098
10991099statement ok
11001100CREATE TABLE fanout_minmax_tasks (id INT, task TEXT);
@@ -1107,15 +1107,15 @@ CREATE VIEW fanout_minmax_v AS
11071107SELECT *, MIN(age) AS MEASURE youngest, MAX(age) AS MEASURE oldest
11081108FROM fanout_minmax_people;
11091109
1110- # Correct: MIN=15 (id=4, no tasks ), MAX=40
1111- # Joined-only (wrong): MIN=25, MAX=40
1110+ # Correct: MIN=15 (id=4, unmatched ), MAX=50 (id=5, unmatched)
1111+ # Joined-only (wrong): MIN=25, MAX=35
11121112
11131113query II
11141114SEMANTIC SELECT AGGREGATE(youngest), AGGREGATE(oldest)
11151115FROM fanout_minmax_v p
11161116JOIN fanout_minmax_tasks t ON p.id = t.id;
11171117----
1118- 15 40
1118+ 15 50
11191119
11201120# -- Test 9: non-additive (ratio) measure immune to fan-out --
11211121# A ratio measure cannot be re-aggregated by summing. The measure must
@@ -1156,33 +1156,36 @@ JOIN fanout_product_regions pr ON p.product = pr.product;
115611560.5222222222222223
11571157
11581158# -- Test 10: COUNT DISTINCT measure immune to fan-out --
1159- # Join orders to a line-items table that fans out the order rows.
1160- # Each order has 1-3 line items, so orders are duplicated in the join.
1161- # COUNT(DISTINCT product) must still be 3, not affected by duplication.
1159+ # Add an order with a unique product from a customer not in the join target.
1160+ # If the measure evaluates over joined rows only, that product is lost.
11621161
11631162statement ok
1164- CREATE TABLE fanout_line_items (order_id INT, line TEXT);
1163+ CREATE TABLE fanout_cd_orders (order_id INT, cust_id INT, product TEXT);
11651164
11661165statement ok
1167- INSERT INTO fanout_line_items VALUES
1168- (101, 'L1'), (101, 'L2'),
1169- (102, 'L1'),
1170- (103, 'L1'), (103, 'L2'), (103, 'L3'),
1171- (104, 'L1'),
1172- (105, 'L1'), (105, 'L2'),
1173- (106, 'L1');
1166+ INSERT INTO fanout_cd_orders VALUES
1167+ (1, 1, 'Widget'), (2, 1, 'Gadget'),
1168+ (3, 2, 'Widget'),
1169+ (4, 99, 'Thingamajig');
11741170
11751171statement ok
1176- CREATE VIEW fanout_orders_cd_v AS
1172+ CREATE TABLE fanout_cd_custs (cust_id INT, name TEXT);
1173+
1174+ statement ok
1175+ INSERT INTO fanout_cd_custs VALUES (1, 'Alice'), (1, 'Alice2'), (2, 'Bob');
1176+
1177+ statement ok
1178+ CREATE VIEW fanout_cd_orders_v AS
11771179SELECT *, COUNT(DISTINCT product) AS MEASURE distinct_products
1178- FROM fanout_orders ;
1180+ FROM fanout_cd_orders ;
11791181
1180- # 11 joined rows from 6 orders, but distinct products stays 3.
1182+ # Correct: 3 distinct products (Widget, Gadget, Thingamajig)
1183+ # Joined-only (wrong): 2 (Widget, Gadget -- cust_id=99 has no match)
11811184
11821185query I
11831186SEMANTIC SELECT AGGREGATE(distinct_products)
1184- FROM fanout_orders_cd_v o
1185- JOIN fanout_line_items li ON o.order_id = li.order_id ;
1187+ FROM fanout_cd_orders_v o
1188+ JOIN fanout_cd_custs c ON o.cust_id = c.cust_id ;
11861189----
118711903
11881191
0 commit comments