Format a single partition field value to its string representation.
(
row: &BinaryRow,
pos: usize,
data_type: &DataType,
default_partition_name: &str,
legacy: bool,
)
| 185 | |
| 186 | /// Format a single partition field value to its string representation. |
| 187 | fn format_partition_value( |
| 188 | row: &BinaryRow, |
| 189 | pos: usize, |
| 190 | data_type: &DataType, |
| 191 | default_partition_name: &str, |
| 192 | legacy: bool, |
| 193 | ) -> crate::Result<String> { |
| 194 | if row.is_null_at(pos) { |
| 195 | return Ok(default_partition_name.to_string()); |
| 196 | } |
| 197 | |
| 198 | let value = match data_type { |
| 199 | DataType::Boolean(_) => row.get_boolean(pos)?.to_string(), |
| 200 | DataType::TinyInt(_) => row.get_byte(pos)?.to_string(), |
| 201 | DataType::SmallInt(_) => row.get_short(pos)?.to_string(), |
| 202 | DataType::Int(_) => row.get_int(pos)?.to_string(), |
| 203 | DataType::BigInt(_) => row.get_long(pos)?.to_string(), |
| 204 | |
| 205 | DataType::Char(_) | DataType::VarChar(_) => { |
| 206 | let s = row.get_string(pos)?; |
| 207 | if s.trim().is_empty() { |
| 208 | return Ok(default_partition_name.to_string()); |
| 209 | } |
| 210 | s.to_string() |
| 211 | } |
| 212 | |
| 213 | DataType::Date(_) => { |
| 214 | if legacy { |
| 215 | // Legacy: field.toString() on the epoch-day Integer → raw int value. |
| 216 | row.get_int(pos)?.to_string() |
| 217 | } else { |
| 218 | format_date(row.get_int(pos)?) |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | DataType::Decimal(d) => { |
| 223 | let unscaled = row.get_decimal_unscaled(pos, d.precision())?; |
| 224 | format_decimal_plain(unscaled, d.scale()) |
| 225 | } |
| 226 | |
| 227 | DataType::Timestamp(t) => { |
| 228 | let (millis, nano_of_milli) = row.get_timestamp_raw(pos, t.precision())?; |
| 229 | let dt = millis_to_naive_datetime(millis, nano_of_milli); |
| 230 | if legacy { |
| 231 | format_timestamp_legacy(dt) |
| 232 | } else { |
| 233 | format_timestamp_non_legacy(dt, t.precision()) |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | DataType::LocalZonedTimestamp(t) => { |
| 238 | let (millis, nano_of_milli) = row.get_timestamp_raw(pos, t.precision())?; |
| 239 | if legacy { |
| 240 | // Legacy: Timestamp.toString() → toLocalDateTime().toString(), |
| 241 | // which does NOT apply timezone conversion. |
| 242 | let dt = millis_to_naive_datetime(millis, nano_of_milli); |
| 243 | format_timestamp_legacy(dt) |
| 244 | } else { |
no test coverage detected