{"record":{"id":"bfdc60bbce651d53","repo":"databendlabs/databend","slug":"not-implemented-bfdc60","errorCode":null,"errorMessage":"not implemented","messagePattern":"not implemented","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/sql/src/planner/plans/sort.rs","lineNumber":70,"sourceCode":"    }\n\n    pub fn replace_column(&mut self, old: Symbol, new: Symbol) {\n        for item in &mut self.items {\n            if item.index == old {\n                item.index = new\n            }\n        }\n\n        if let Some(projection) = &mut self.pre_projection {\n            for i in projection {\n                if *i == old {\n                    *i = new\n                }\n            }\n        }\n\n        if self.window_partition.is_some() {\n            unimplemented!()\n        };\n    }\n\n    pub fn replace_columns<F>(&mut self, mut replace: F) -> Result<()>\n    where F: FnMut(Symbol) -> Result<Symbol> {\n        for item in &mut self.items {\n            item.index = replace(item.index)?;\n        }\n\n        if let Some(projection) = &mut self.pre_projection {\n            for index in projection {\n                *index = replace(*index)?;\n            }\n        }\n\n        if self.window_partition.is_some() {\n            unimplemented!()\n        };","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/sql/src/planner/plans/sort.rs#L52-L88","documentation":"Panic from `unimplemented!()` in `Sort::replace_column` (src/query/sql/src/planner/plans/sort.rs:70). When rewriting column references in a sort plan, the case where the sort has a window partition is not handled, so the optimizer pass panics with 'not implemented' instead of remapping those columns.","triggerScenarios":"An optimizer rewrite calls `replace_column` on a `Sort` plan whose `window_partition` is `Some`, e.g. when substituting column indices in a query containing window functions (OVER PARTITION BY) under a sort node.","commonSituations":"Queries mixing ORDER BY with window functions during plan normalization/scalar substitution; development-time hits when extending expression rewrites to window plans.","solutions":["Avoid triggering the rewrite path for plans containing window partitions until supported (or gate the rewrite upstream).","Extend `replace_column` to iterate and remap `window_partition` expressions with the same closure used for `items`.","File/track a Databend issue; replace `unimplemented!()` with a proper internal error for a non-panicking failure.","Reproduce with a minimal ORDER BY + OVER (PARTITION BY) query and include it in the bug report."],"exampleFix":"// before\nif self.window_partition.is_some() {\n    unimplemented!()\n};\n// after\nif let Some(partition) = self.window_partition.as_mut() {\n    for expr in &mut partition.expressions {\n        *expr = replace_column_in_expr(expr, &mut replace)?;\n    }\n}","handlingStrategy":"try-catch","validationCode":"// guard before applying rewrite\nfn sort_has_window_partition(sort: &Sort) -> bool { sort.window_partition.is_some() }","typeGuard":"fn can_rewrite_sort(sort: &Sort) -> bool {\n    sort.window_partition.is_none()\n}","tryCatchPattern":"match sort.replace_column(old, new) {\n    Ok(()) => {},\n    Err(e) => return Err(e),\n    // a panic! here means window_partition is Some; catch_unwind or pre-check\n}","preventionTips":["Check window_partition before running column rewrites on Sort plans","Add tests covering ORDER BY + OVER (PARTITION BY) to rewrite passes","Prefer extending the rewrite to window partitions over skipping silently","Convert unimplemented!() to planner errors in local builds to fail fast"],"tags":["planner","optimizer","window-functions","unimplemented"],"backgroundTag":"method-not-implemented","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}