Skip to main content

RecordTransform

Enum RecordTransform 

Source
pub enum RecordTransform {
    Flatten {
        separator: String,
    },
    RenameKeys {
        pattern: String,
        replacement: String,
    },
    KeysToSnakeCase,
    Custom(Arc<dyn Fn(Value) -> Value + Send + Sync>),
}
Expand description

A transformation applied to every record fetched by a crate::stream::RestStream.

Transforms are applied in the order they are added via crate::config::RestStreamConfig::add_transform.

The three built-in variants are each guarded by a Cargo feature flag (all enabled by default — see module-level docs). RecordTransform::Custom is always available and accepts any closure.

Variants§

§

Flatten

Flatten nested JSON objects into a single-level map.

Nested key paths are joined with separator. Arrays are left as-is.

Requires feature transform-flatten (default).

§Example

{"user": {"id": 1, "addr": {"city": "NYC"}}}  →  (separator = "__")
{"user__id": 1, "user__addr__city": "NYC"}

Fields

§separator: String
§

RenameKeys

Apply a single regex substitution to every key in the record.

Keys in nested objects and objects inside arrays are also renamed recursively. pattern is a Rust regex; replacement may reference capture groups with $1, ${name}, etc. Chain multiple RenameKeys transforms for multi-step pipelines.

Requires feature transform-rename-keys (default).

§Example

pattern = r"^_sdc_", replacement = ""   →   strip "_sdc_" prefix

Fields

§pattern: String
§replacement: String
§

KeysToSnakeCase

Convert all keys to snake_case using the same algorithm as Meltano’s default key normaliser:

  1. Strip characters that are neither alphanumeric nor whitespace.
  2. Trim edges, then replace whitespace runs with _.
  3. Collapse consecutive underscores.
  4. Lowercase and trim leading/trailing underscores.

Requires feature transform-snake-case (default).

Input keyOutput key
"First Name""first_name"
"last-name""lastname"
"price ($)""price"
"ID""id"
§

Custom(Arc<dyn Fn(Value) -> Value + Send + Sync>)

A user-supplied transformation function.

The function receives each record as a Value and returns the (possibly modified) record. Construct one with RecordTransform::custom.

Always available — not guarded by any feature flag.

Implementations§

Source§

impl RecordTransform

Source

pub fn custom<F>(f: F) -> Self
where F: Fn(Value) -> Value + Send + Sync + 'static,

Create a custom transform from any function or closure.

The closure receives each record as a Value and must return a Value (the transformed record). It is called once per record and may perform any manipulation — adding fields, removing fields, renaming, type coercion, etc.

Custom transforms are always available regardless of feature flags.

§Example
use faucet_stream::RecordTransform;
use serde_json::{Value, json};

// Inject a constant "source" field into every record.
let stamp = RecordTransform::custom(|mut record| {
    if let Value::Object(ref mut map) = record {
        map.insert("_source".to_string(), json!("my-api"));
    }
    record
});

Trait Implementations§

Source§

impl Clone for RecordTransform

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RecordTransform

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more