use std::sync::Arc;
use datafusion::arrow::datatypes::DataType;
use datafusion::common::{Result, ScalarValue, plan_err};
use datafusion::logical_expr::{
ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility,
};
use super::execution_slots::ExecutionSlots;
#[derive(Clone)]
pub(super) struct LixActiveBranchId {
slots: Arc<ExecutionSlots>,
}
impl LixActiveBranchId {
pub(super) fn new(slots: Arc<ExecutionSlots>) -> Self {
Self { slots }
}
}
impl PartialEq for LixActiveBranchId {
fn eq(&self, _other: &Self) -> bool {
true
}
}
impl Eq for LixActiveBranchId {}
impl std::hash::Hash for LixActiveBranchId {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.name().hash(state);
}
}
impl std::fmt::Debug for LixActiveBranchId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("LixActiveBranchId").finish()
}
}
impl ScalarUDFImpl for LixActiveBranchId {
fn name(&self) -> &'static str {
"lix_active_branch_id"
}
fn signature(&self) -> &Signature {
static SIGNATURE: std::sync::LazyLock<Signature> =
std::sync::LazyLock::new(|| Signature::nullary(Volatility::Stable));
&SIGNATURE
}
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
Ok(DataType::Utf8)
}
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {
if !args.args.is_empty() {
return plan_err!("lix_active_branch_id requires no arguments");
}
Ok(ColumnarValue::Scalar(ScalarValue::Utf8(
self.slots.active_branch_id(),
)))
}
}