use sqlparser::ast::{DiscardObject, Statement};
use sqlparser::tokenizer::{Location, TokenWithSpan};
use std::sync::Arc;
#[derive(Debug)]
pub struct LocatedStatement {
pub statement: Statement,
pub source: Option<Arc<[TokenWithSpan]>>,
pub(crate) function_projection: bool,
pub(crate) synthetic_select: bool,
pub(crate) recovered_functions: Vec<crate::SqlFunctionCallFact>,
pub(crate) policy_arbiter: Option<crate::source::PolicyArbiter>,
pub complete: bool,
pub(crate) policy_start: Option<Location>,
pub(crate) partition_complete: bool,
pub chunk_tokens: Option<Arc<[TokenWithSpan]>>,
pub recovery_failure: Option<super::super::super::types::SqlUnanalyzableStatement>,
}
impl LocatedStatement {
#[doc(hidden)]
pub fn policy_start(&self) -> Location {
self.policy_start.unwrap_or_else(Location::empty)
}
#[doc(hidden)]
pub fn complete_for_inventory(&self) -> bool {
self.complete || self.partition_complete
}
pub(super) fn plain(statement: Statement) -> Self {
Self {
statement,
source: None,
function_projection: false,
synthetic_select: false,
recovered_functions: Vec::new(),
policy_arbiter: None,
complete: false,
policy_start: None,
partition_complete: false,
chunk_tokens: None,
recovery_failure: None,
}
}
pub(super) fn failed_source(sql: &str, line: usize, column: usize, ordinal: usize) -> Self {
Self {
recovery_failure: Some(super::recover::failed_source(sql, line, column, ordinal)),
..Self::functions(
Statement::Discard {
object_type: DiscardObject::ALL,
},
false,
)
}
}
pub(super) fn functions(statement: Statement, synthetic_select: bool) -> Self {
Self {
function_projection: true,
synthetic_select,
..Self::plain(statement)
}
}
}