use nodedb_physical::physical_plan::{ColumnarOp, DocumentOp, KvOp, PhysicalPlan, TimeseriesOp};
use nodedb_types::{CollectionType, ColumnarProfile, DocumentMode, SystemTimeScope};
use crate::control::state::SharedState;
use crate::types::{DatabaseId, TenantId};
const COMPLETE_SCAN: usize = usize::MAX;
pub fn full_scan_plan_for_collection(
state: &SharedState,
database_id: DatabaseId,
tenant_id: TenantId,
collection: &str,
) -> crate::Result<Option<PhysicalPlan>> {
let catalog = state.credentials.catalog();
let stored = match catalog.get_collection(database_id, tenant_id.as_u64(), collection)? {
Some(s) => s,
None => return Ok(None),
};
let plan = match &stored.collection_type {
CollectionType::Document(DocumentMode::Schemaless)
| CollectionType::Document(DocumentMode::Strict(_)) => {
PhysicalPlan::Document(DocumentOp::Scan {
collection: collection.into(),
limit: COMPLETE_SCAN,
offset: 0,
sort_keys: Vec::new(),
filters: Vec::new(),
distinct: false,
projection: Vec::new(),
computed_columns: Vec::new(),
window_functions: Vec::new(),
system_time: SystemTimeScope::Current,
valid_at_ms: None,
prefilter: None,
})
}
CollectionType::KeyValue(_) => PhysicalPlan::Kv(KvOp::Scan {
collection: collection.into(),
cursor: Vec::new(),
count: COMPLETE_SCAN,
filters: Vec::new(),
match_pattern: None,
sort_keys: Vec::new(),
surrogate_ceiling: None,
}),
CollectionType::Columnar(ColumnarProfile::Plain)
| CollectionType::Columnar(ColumnarProfile::Spatial { .. }) => {
PhysicalPlan::Columnar(ColumnarOp::Scan {
collection: collection.into(),
projection: Vec::new(),
limit: COMPLETE_SCAN,
filters: Vec::new(),
rls_filters: Vec::new(),
sort_keys: Vec::new(),
system_time: SystemTimeScope::Current,
valid_at_ms: None,
prefilter: None,
computed_columns: Vec::new(),
})
}
CollectionType::Columnar(ColumnarProfile::Timeseries { .. }) => {
PhysicalPlan::Timeseries(TimeseriesOp::Scan {
collection: collection.into(),
time_range: (0, i64::MAX),
projection: Vec::new(),
limit: COMPLETE_SCAN,
filters: Vec::new(),
bucket_interval_ms: 0,
group_by: Vec::new(),
aggregates: Vec::new(),
gap_fill: String::new(),
computed_columns: Vec::new(),
rls_filters: Vec::new(),
system_time: SystemTimeScope::Current,
valid_at_ms: None,
})
}
};
Ok(Some(plan))
}