poc/create-alter-for-metrics:

### Commit Message

 Enhance error handling in `batch_builder.rs` and `error.rs`

 - **`batch_builder.rs`**:
   - Replaced `todo!` with specific error handling for invalid timestamp and field value types using `InvalidTimestampValueTypeSnafu` and `InvalidFieldValueTypeSnafu`.

 - **`error.rs`**:
   - Added new error variants `InvalidTimestampValueType` and `InvalidFieldValueType` with descriptive messages.
   - Updated `status_code` method to handle new error types with `StatusCode::Unexpected`.

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
This commit is contained in:
Lei, HUANG
2025-06-25 08:08:01 +00:00
parent 4e53c1531d
commit cf62767b98
2 changed files with 21 additions and 2 deletions

View File

@@ -296,14 +296,16 @@ impl BatchEncoder {
// process timestamp and field. We already know the position of timestamps and values in [TableBuilder].
let ValueData::TimestampMillisecondValue(ts) =
// safety: timestamp values cannot be null
row.value_at(0).value_data.as_ref().unwrap()
else {
todo!("return an error")
return error::InvalidTimestampValueTypeSnafu.fail();
};
self.timestamps.push(*ts);
// safety: field values cannot be null in prom remote write
let ValueData::F64Value(val) = row.value_at(1).value_data.as_ref().unwrap() else {
todo!("return an error")
return error::InvalidFieldValueTypeSnafu.fail();
};
self.value.push(*val);
}

View File

@@ -645,6 +645,20 @@ pub enum Error {
#[snafu(implicit)]
location: Location,
},
#[snafu(display(
"Invalid timestamp value type in row data, expected TimestampMillisecondValue"
))]
InvalidTimestampValueType {
#[snafu(implicit)]
location: Location,
},
#[snafu(display("Invalid field value type in row data, expected F64Value"))]
InvalidFieldValueType {
#[snafu(implicit)]
location: Location,
},
}
pub type Result<T, E = Error> = std::result::Result<T, E>;
@@ -771,6 +785,9 @@ impl ErrorExt for Error {
CommonMeta { source, .. } => source.status_code(),
Operator { source, .. } => source.status_code(),
EncodePrimaryKey { source, .. } => source.status_code(),
InvalidTimestampValueType { .. } | InvalidFieldValueType { .. } => {
StatusCode::Unexpected
}
}
}