mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-28 13:44:03 +00:00
`ensure_simple_source_delta_sink_keys_are_produced` compared sink key column names against the query's raw output schema, before `ColumnMatcherRewriter` had a chance to match a sink column to an output column by position. That rejected valid definitions: an explicit sink `(host, val, sink_ts TIME INDEX)` with `PRIMARY KEY(host)` and `SELECT host, val, ts FROM source` maps `ts` to `sink_ts` by position, so the key is a stable function of the source row and a replay still overwrites the same rows. Judge the plan a round actually executes instead. The rewritten plan is produced by `gen_plan_with_matching_schema_and_values`, the same helper the round path and `validate_sink_table_schema_with_values` use. A key column the projection does not produce is still rejected; a key column the projection produces through a value generated per round, such as `now()` (a `Volatility::Stable` scalar function), is now rejected with a message that says so, since such a replay would write the same source rows under new keys. Add a regression test covering the positional mapping the review reported; it fails against the previous name-based check. Promote `is_merge_mode_last_non_null` to `pub(crate)` so the check reuses it rather than duplicating the predicate. Signed-off-by: discord9 <discord9@163.com> Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>