use uqa_core::{
memory::{Produced, ProductionControl, ProductionVec},
Value,
};
use uqa_sql::{
catalog::index::operator_classes::BoundBTreeOperatorClass,
expr::{with_btree_input, BTreeInput, SQLValueCatalog},
SQLError,
};
pub fn btree_input_binary_key_with_catalog_and_control(
binding: BoundBTreeOperatorClass<'_>,
value: &Value,
catalog: Option<&dyn SQLValueCatalog>,
control: &ProductionControl<'_>,
) -> Result<Produced<Vec<u8>>, SQLError> {
with_btree_input(binding, value, catalog, control, |input| match input {
BTreeInput::Value(value, ty) => super::canonical_typed_row_key_with_catalog_and_control(
std::iter::once((Some(value), Some(ty))),
catalog,
control,
),
BTreeInput::RecordImage(value) => {
super::record_image_key_with_catalog_and_control(value, catalog, control)
}
BTreeInput::Array(array) => {
let mut output = super::CatalogKeyOutput {
values: ProductionVec::new(*control),
enums: catalog,
sql_hash: true,
};
let result = (|| {
super::encode_len(1, &mut output)?;
super::encode_array_with_control(array, &mut output, control)
})();
result.map_err(super::sql_error)?;
Ok(output.values.finish()?)
}
})
}
#[cfg(test)]
mod tests;