use crate::core::AbsoluteRow;
use datafusion::common::{DataFusionError, Result};
pub(crate) fn checked_match_number(match_number: u64) -> Result<i64> {
i64::try_from(match_number).map_err(|_| {
DataFusionError::ResourcesExhausted(
"MATCH_RECOGNIZE match number cannot be represented as SQL BIGINT".into(),
)
})
}
pub(crate) fn absolute_row_from_usize(row: usize, context: &str) -> Result<AbsoluteRow> {
u64::try_from(row).map(AbsoluteRow::new).map_err(|_| {
DataFusionError::ResourcesExhausted(format!(
"MATCH_RECOGNIZE {context} {row} cannot be represented as an absolute u64 row"
))
})
}
pub(crate) fn absolute_row_to_usize(row: AbsoluteRow, context: &str) -> Result<usize> {
usize::try_from(row.as_u64()).map_err(|_| {
DataFusionError::ResourcesExhausted(format!(
"MATCH_RECOGNIZE {context} {row} cannot be represented as a usize row on this platform"
))
})
}