{"record":{"id":"b7162128d8e191f3","repo":"risingwavelabs/risingwave","slug":"match-recognize-within-deadline-has-type-but-th","errorCode":null,"errorMessage":"MATCH_RECOGNIZE WITHIN deadline has type {} but the ORDER BY column has type {}; the two are compared directly","messagePattern":"MATCH_RECOGNIZE WITHIN deadline has type (.+?) but the ORDER BY column has type (.+?); the two are compared directly","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/stream/src/from_proto/match_recognize.rs","lineNumber":193,"sourceCode":"        // (`ScalarRefImpl::default_cmp` panics across variants — an actor crash loop that recovery\n        // replays), and the span predicate is a boolean. The binder guarantees both\n        // (`lower_within`); re-state it here so a skewed or corrupt plan fails at build time.\n        let order_key_type = input\n            .schema()\n            .fields\n            .get(order_key_indices[0])\n            .map(|f| f.data_type())\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"MATCH_RECOGNIZE ORDER BY column {} is out of range for an input of {} columns\",\n                    order_key_indices[0],\n                    input.schema().len()\n                )\n            })?;\n        if let Some(deadline) = &within_deadline\n            && deadline.return_type() != order_key_type\n        {\n            return Err(anyhow::anyhow!(\n                \"MATCH_RECOGNIZE WITHIN deadline has type {} but the ORDER BY column has type {}; \\\n                 the two are compared directly\",\n                deadline.return_type(),\n                order_key_type,\n            )\n            .into());\n        }\n        if let Some(predicate) = &within\n            && predicate.return_type() != DataType::Boolean\n        {\n            return Err(anyhow::anyhow!(\n                \"MATCH_RECOGNIZE WITHIN span predicate has type {}, expected boolean\",\n                predicate.return_type(),\n            )\n            .into());\n        }\n\n        let vnode_bitmap = params.vnode_bitmap.clone().map(std::sync::Arc::new);","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/stream/src/from_proto/match_recognize.rs#L175-L211","documentation":"WITHIN compares the ORDER BY column value directly against the deadline expression, so both must have the same type. The decoder found a `within_deadline` whose return type differs from the ORDER BY column type and rejects the plan. Emitting it anyway would produce a runtime comparison/cast error or wrong semantics.","triggerScenarios":"`new_boxed_executor` decodes a MatchRecognizeNode where `within_deadline.return_type() != order_key_type`, e.g. deadline is TIMESTAMP while ORDER BY column is TIMESTAMPTZ or BIGINT.","commonSituations":"A SQL query with `WITHIN` whose deadline expression type does not match the ORDER BY column, e.g. `ORDER BY ts ... WITHIN INTERVAL '1 hour'` where `ts` is a BIGINT epoch; frontend bugs producing mismatched types.","solutions":["Cast the ORDER BY column or the deadline so both types match, e.g. `ORDER BY to_timestamp(ts)` or `WITHIN (deadline)::timestamptz`.","Adjust the WITHIN literal to the column's type (e.g. numeric bound for a BIGINT column).","If types look equal in SQL but the plan differs, report a binder type-coercion bug."],"exampleFix":"-- before\nSELECT * FROM m MATCH_RECOGNIZE ( ORDER BY ts WITHIN INTERVAL '1 hour' ... ) -- ts is BIGINT\n-- after\nSELECT * FROM m MATCH_RECOGNIZE ( ORDER BY to_timestamp(ts) WITHIN INTERVAL '1 hour' ... )","handlingStrategy":"validation","validationCode":"-- SQL-level guard: ensure the WITHIN deadline type matches the ORDER BY column type\nSELECT column_name, data_type FROM information_schema.columns\nWHERE table_name = 'm' AND column_name = 'ts'; -- compare with your deadline type","typeGuard":null,"tryCatchPattern":"// Defensive pre-check on decoded plan\nif let Some(d) = &within_deadline && d.return_type() != order_key_type {\n    return Err(anyhow!(\"WITHIN deadline type {} != ORDER BY type {}\", d.return_type(), order_key_type));\n}","preventionTips":["Cast the ORDER BY column to the deadline's type in SQL (e.g. to_timestamp for epoch columns).","Verify column types with information_schema before writing WITHIN clauses.","Add binder tests asserting deadline/order-key type unification."],"tags":["streaming","match-recognize","type-mismatch","within-clause"],"backgroundTag":"type-mismatch","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}