datum-sql 0.10.3

DataFusion and Arrow SQL front end for Datum streams
Documentation
//! Connector adapters for `datum-sql`.
//!
//! These adapters keep connector metadata outside Arrow row data. The per-batch
//! envelope carries only source position and schema revision; time, watermarks,
//! barriers, and checkpoint epochs belong to later control-envelope work.

use arrow::record_batch::RecordBatch;

#[cfg(feature = "cdc")]
pub mod cdc;
#[cfg(feature = "mq")]
pub mod mq;

/// Side metadata for one emitted SQL batch.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BatchEnvelope<P> {
    source_position: P,
    schema_revision: u64,
}

impl<P> BatchEnvelope<P> {
    /// Creates a batch envelope from source position metadata and schema revision.
    #[must_use]
    pub const fn new(source_position: P, schema_revision: u64) -> Self {
        Self {
            source_position,
            schema_revision,
        }
    }

    /// Returns the source position metadata.
    #[must_use]
    pub const fn source_position(&self) -> &P {
        &self.source_position
    }

    /// Returns the schema revision associated with the batch.
    #[must_use]
    pub const fn schema_revision(&self) -> u64 {
        self.schema_revision
    }

    /// Consumes the envelope and returns the source position metadata.
    #[must_use]
    pub fn into_source_position(self) -> P {
        self.source_position
    }
}

/// A data batch paired with connector-side metadata.
#[derive(Debug, Clone, PartialEq)]
pub struct EnvelopedBatch<T, P> {
    batch: T,
    envelope: BatchEnvelope<P>,
}

impl<T, P> EnvelopedBatch<T, P> {
    /// Creates a batch with connector-side metadata.
    #[must_use]
    pub const fn new(batch: T, envelope: BatchEnvelope<P>) -> Self {
        Self { batch, envelope }
    }

    /// Returns the payload batch.
    #[must_use]
    pub const fn batch(&self) -> &T {
        &self.batch
    }

    /// Returns the connector metadata envelope.
    #[must_use]
    pub const fn envelope(&self) -> &BatchEnvelope<P> {
        &self.envelope
    }

    /// Consumes this value and returns only the payload batch.
    #[must_use]
    pub fn into_batch(self) -> T {
        self.batch
    }

    /// Consumes this value and returns payload plus envelope.
    #[must_use]
    pub fn into_parts(self) -> (T, BatchEnvelope<P>) {
        (self.batch, self.envelope)
    }
}

/// Append-only Arrow batch with connector-side metadata.
pub type EnvelopedRecordBatch<P> = EnvelopedBatch<RecordBatch, P>;