MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / select_codec

Function select_codec

nodedb-columnar/src/writer/segment_writer.rs:189–227  ·  view source on GitHub ↗

Select the best codec for a column type using nodedb-codec's auto-detection. Always returns a `ResolvedColumnCodec` — `Auto` is consumed here and never forwarded downstream.

(col_type: &ColumnType)

Source from the content-addressed store, hash-verified

187/// Always returns a `ResolvedColumnCodec` — `Auto` is consumed here and
188/// never forwarded downstream.
189fn select_codec(col_type: &ColumnType) -> ResolvedColumnCodec {
190 let hint = match col_type {
191 ColumnType::Int64 => ColumnTypeHint::Int64,
192 ColumnType::Float64 => ColumnTypeHint::Float64,
193 ColumnType::Timestamp | ColumnType::Timestamptz | ColumnType::SystemTimestamp => {
194 ColumnTypeHint::Timestamp
195 }
196 ColumnType::String | ColumnType::Geometry | ColumnType::Regex => ColumnTypeHint::String,
197 ColumnType::Bool
198 | ColumnType::Bytes
199 | ColumnType::Decimal { .. }
200 | ColumnType::Uuid
201 | ColumnType::Ulid => {
202 return ResolvedColumnCodec::Lz4;
203 }
204 ColumnType::Json
205 | ColumnType::Array
206 | ColumnType::Set
207 | ColumnType::Range
208 | ColumnType::Record => {
209 return ResolvedColumnCodec::Lz4;
210 }
211 ColumnType::Duration => ColumnTypeHint::Int64, // i64 microseconds
212 ColumnType::Vector(_) => {
213 return ResolvedColumnCodec::Lz4;
214 }
215 // ColumnType is #[non_exhaustive]; unknown types default to Lz4
216 // general-purpose compression until a dedicated codec is registered.
217 _ => {
218 return ResolvedColumnCodec::Lz4;
219 }
220 };
221 // detect_codec resolves Auto via the type hint and always returns a
222 // concrete codec. Map any unexpected Auto back to a safe default
223 // (Lz4) rather than panicking in library code.
224 nodedb_codec::detect_codec(ColumnCodec::Auto, hint)
225 .try_resolve()
226 .unwrap_or(ResolvedColumnCodec::Lz4)
227}
228
229#[cfg(test)]
230mod tests {

Callers 1

select_codec_for_profileFunction · 0.85

Calls 2

detect_codecFunction · 0.85
try_resolveMethod · 0.80

Tested by

no test coverage detected