databendlabs/databend · error
Unsupported column type for length calculation
Error message
Unsupported column type for length calculation
What it means
The variable-size row encoder's length-calculation visitor computes encoded lengths before writing sort rows. Its default visit_typed_column arm raises unimplemented!("Unsupported column type for length calculation") for types it cannot measure. Sorting on such a column with the variable encoder is unsupported.
Solutions
- Cast the sort key to a supported type before ordering (e.g. col::string)
- Restructure the query to sort by a primitive column or expression
- Check the Databend release notes for sort-encoder support of the type; upgrade if added
- Implement the missing length-measurement arm in the variable encoder if you maintain the code
Example fix
// before SELECT * FROM t ORDER BY map_col; // after SELECT * FROM t ORDER BY map_col['key']::string;
Defensive patterns
Strategy: validation
Validate before calling
-- sql: keep variable-width sort keys to supported types (String primarily)
SELECT data_type FROM information_schema.columns
WHERE table_name = 't' AND column_name IN ('sort_col');
-- cast non-string variable keys: ORDER BY sort_col::string Type guard
fn variable_encodable(ty: &DataType) -> bool {
matches!(ty, DataType::String | DataType::Nullable(box inner)
if matches!(**inner, DataType::String))
|| matches!(ty, DataType::String)
} Prevention
- Cast complex sort keys to VARCHAR/numeric before ordering
- Prefer sorting on primitive columns in hot paths
- Verify sorter support for a type before adding it to window partition/order keys
When it happens
Trigger: A sort/ORDER BY (or window partition key) includes a column type whose encoded length cannot be computed by the variable encoder — types not routed to a proper visitor arm.
Common situations: ORDER BY on newly added or nested types (arrays, maps, variants) that only partially support variable encoding; optimizer selecting variable encoding for an unsupported type; version skew between data type support and sorter support.
Related errors
- Unsupported column type for encoding
- internal error: entered unreachable code
- {}
- Temp table id used up
- Invalid temp table desc
AI-assisted analysis of databendlabs/databend@288d84d76e (2026-09-11).
Data as JSON: /api/errors/9beee89e75213b90.
Report an issue: GitHub.
Appendix: source
Thrown at src/query/pipeline/transforms/src/processors/transforms/sorts/core/row_convert/variable.rs:482
self.visit_variable_length_data(column.iter(), encoded_len)
}
fn visit_string(&mut self, column: StringColumn) -> Result<()> {
self.visit_variable_length_data(column.iter(), |s, is_null| {
encoded_len(s.as_bytes(), is_null)
})
}
fn visit_variant(&mut self, column: BinaryColumn) -> Result<()> {
self.visit_variable_length_data(column.iter(), encoded_len)
}
fn visit_typed_column<T: ValueType>(
&mut self,
_column: T::Column,
_data_type: &DataType,
) -> Result<()> {
unimplemented!("Unsupported column type for length calculation")
}
}
struct EncodeVisitor<'a> {
out: &'a mut BinaryColumnBuilder,
validity: (bool, Option<&'a Bitmap>),
field: &'a RowSortField,
}
impl EncodeVisitor<'_> {
fn visit_const_column(&mut self, scalar: &Scalar, data_type: &DataType) -> Result<()> {
let is_null = scalar.is_null();
debug_assert!(data_type.is_nullable_or_null() || !is_null);
match data_type.remove_nullable() {
DataType::Null => {}
DataType::Boolean => {
let scalar = if is_null {
falseView on GitHub (pinned to 288d84d76e)