Skip to content

Commit 8895d80

Browse files
committed
ensure_monotonic in monotonic top-k
This commit adds a monotonicity check with the EnsureMonotonic operator to the rendering of monotonic top-k. This step increases the consistency of the rendering code across monotonic top-k, monotonic top-1, and monotonic hierarchical reductions.
1 parent 1ea51ef commit 8895d80

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

‎src/compute/src/render/top_k.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ where
101101
);
102102
}
103103

104+
let debug_name = self.debug_name.to_string();
105+
let (collection, errs) = collection.ensure_monotonic(move |data, diff| {
106+
warn!(
107+
"[customer-data] MonotonicTopK expected monotonic input but \
108+
received {data:?} with diff {diff:?} in dataflow {debug_name}"
109+
);
110+
error!("Non-monotonic input to MonotonicTopK");
111+
let m = "tried to build monotonic top-k on non-monotonic input".to_string();
112+
(DataflowError::from(EvalError::Internal(m)), 1)
113+
});
114+
err_collection = err_collection.concat(&errs);
115+
104116
// For monotonic inputs, we are able to thin the input relation in two stages:
105117
// 1. First, we can do an intra-timestamp thinning which has the advantage of
106118
// being computed in a streaming fashion, even for the initial snapshot.

‎test/testdrive/negative-multiplicities.td‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,20 @@ contains:Invalid data in source, saw non-positive accumulation
6666

6767
# verify that some reduction in a collation plan catches a negative
6868
# multiplicity.
69-
! SELECT
70-
data,
71-
COUNT(DISTINCT data),
72-
STRING_AGG(data::text || '1', ','),
73-
MIN(data),
74-
MAX(DISTINCT data),
75-
SUM(data),
76-
STRING_AGG(data::text || '2', ',')
77-
FROM data
78-
GROUP BY data
69+
> CREATE VIEW collation AS
70+
SELECT
71+
data,
72+
COUNT(DISTINCT data),
73+
STRING_AGG(data::text || '1', ',') AS data_1,
74+
MIN(data),
75+
MAX(DISTINCT data),
76+
SUM(data),
77+
STRING_AGG(data::text || '2', ',') AS data_2
78+
FROM data
79+
GROUP BY data;
80+
81+
> CREATE DEFAULT INDEX ON collation;
82+
83+
! SELECT * FROM collation;
7984
# Case-insensitive match for both 'Non' and 'non'
8085
contains:on-positive accumulation

0 commit comments

Comments
 (0)