use std::path::Path;
use crate::query::engine::plan_query_with_tet_mmap_ex;
use crate::query::engine::spill_policy::SpillPathAllowlist;
use crate::query::types::{QueryDocument, QueryResponse, TetError};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ExecuteQueryOptions {
pub preview_max: Option<usize>,
}
impl Default for ExecuteQueryOptions {
fn default() -> Self {
Self {
preview_max: Some(0),
}
}
}
impl ExecuteQueryOptions {
#[must_use]
pub const fn execute_no_preview() -> Self {
Self {
preview_max: Some(0),
}
}
#[must_use]
pub const fn plan_only() -> Self {
Self { preview_max: None }
}
}
pub fn execute_query_json(
json: &str,
tet_path: &Path,
mmap: &[u8],
options: ExecuteQueryOptions,
spill_allowlist: Option<&SpillPathAllowlist>,
) -> Result<QueryResponse, TetError> {
let doc = crate::query::parse_query_json(json)?;
crate::query::validate_query(&doc)?;
execute_query_document(&doc, tet_path, mmap, options, spill_allowlist)
}
pub fn execute_query_document(
doc: &QueryDocument,
tet_path: &Path,
mmap: &[u8],
options: ExecuteQueryOptions,
spill_allowlist: Option<&SpillPathAllowlist>,
) -> Result<QueryResponse, TetError> {
let tet_path = tet_path.display().to_string();
plan_query_with_tet_mmap_ex(
doc,
Some(&tet_path),
mmap,
options.preview_max,
spill_allowlist,
)
}