datafusion_openlineage/context.rs
1//! The DataFusion-specific context-provider seam.
2//!
3//! The context *data* ([`LineageContext`]) and its environment conventions live
4//! in [`openlineage_client`]; this module adds the DataFusion-flavored
5//! [`LineageContextProvider`] trait, whose [`context`](LineageContextProvider::context)
6//! method receives the query's [`SessionState`]. A different engine would define
7//! its own provider over its own request type.
8
9use async_trait::async_trait;
10use datafusion::execution::context::SessionState;
11
12pub use openlineage_client::LineageContext;
13
14/// Supplies per-query [`LineageContext`]. Implemented by the host integration.
15#[async_trait]
16pub trait LineageContextProvider: std::fmt::Debug + Send + Sync {
17 /// Returns the [`LineageContext`] for a query, given its session state.
18 async fn context(&self, session_state: &SessionState) -> LineageContext;
19}
20
21/// Returns a fixed [`LineageContext`] for every query. Use
22/// `StaticContextProvider::default()` for callers with no orchestration context.
23#[derive(Debug, Default)]
24pub struct StaticContextProvider(pub LineageContext);
25
26#[async_trait]
27impl LineageContextProvider for StaticContextProvider {
28 async fn context(&self, _session_state: &SessionState) -> LineageContext {
29 self.0.clone()
30 }
31}