use super::{
BudgetedVec, BufferedIndexedSpill, ExecResult, IndexedSpill, Produced, ProductionControl,
};
use crate::spill::format::encode_constant_record_with_control;
use uqa_core::Value;
impl BufferedIndexedSpill {
pub(crate) fn push_constant_with_control(
&mut self,
value: &Value,
control: &ProductionControl<'_>,
) -> ExecResult<()> {
super::super::check_publication(control)?;
let record = encode_constant_record_with_control(value, control)?;
if let Some(disk) = &mut self.disk {
return disk.push_encoded_with_control(&record, control);
}
if self.rows.reserve(1).is_ok() {
if let Ok(resident) = self.rows.budget().reserve(record.capacity()) {
super::super::check_publication(control)?;
let (record, request) = record.into_parts();
self.rows
.push(record)
.map_err(|error| super::spill_error(error.to_string()))?;
self.payload.absorb(resident);
drop(request);
return Ok(());
}
}
self.spill_constant(record, control)
}
fn spill_constant(
&mut self,
record: Produced<Vec<u8>>,
control: &ProductionControl<'_>,
) -> ExecResult<()> {
super::super::check_publication(control)?;
let mut disk = IndexedSpill::new(self.schema.clone())?;
for previous in self.rows.iter() {
disk.push_encoded_with_control(previous, control)?;
}
disk.push_encoded_with_control(&record, control)?;
super::super::check_publication(control)?;
let memory = self.rows.budget().clone();
self.rows = BudgetedVec::new(&memory);
self.payload = memory.empty_reservation();
self.disk = Some(disk);
Ok(())
}
}