Enum Transform

Source
pub enum Transform {
    Identity,
    Bucket(u32),
    Truncate(u32),
    Year,
    Month,
    Day,
    Hour,
    Void,
    Unknown,
}
Expand description

Transform is used to transform predicates to partition predicates, in addition to transforming data values.

Deriving partition predicates from column predicates on the table data is used to separate the logical queries from physical storage: the partitioning can change and the correct partition filters are always derived from column predicates.

This simplifies queries because users don’t have to supply both logical predicates and partition predicates.

All transforms must return null for a null input value.

Variants§

§

Identity

Source value, unmodified

  • Source type could be any type.
  • Return type is the same with source type.
§

Bucket(u32)

Hash of value, mod N.

Bucket partition transforms use a 32-bit hash of the source value. The 32-bit hash implementation is the 32-bit Murmur3 hash, x86 variant, seeded with 0.

Transforms are parameterized by a number of buckets, N. The hash mod N must produce a positive value by first discarding the sign bit of the hash value. In pseudo-code, the function is:

def bucket_N(x) = (murmur3_x86_32_hash(x) & Integer.MAX_VALUE) % N
  • Source type could be int, long, decimal, date, time, timestamp, timestamptz, string, uuid, fixed, binary.
  • Return type is int.
§

Truncate(u32)

Value truncated to width W

For int:

  • v - (v % W) remainders must be positive
  • example: W=10: 1 → 0, -1 → -10
  • note: The remainder, v % W, must be positive.

For long:

  • v - (v % W) remainders must be positive
  • example: W=10: 1 → 0, -1 → -10
  • note: The remainder, v % W, must be positive.

For decimal:

  • scaled_W = decimal(W, scale(v)) v - (v % scaled_W)
  • example: W=50, s=2: 10.65 → 10.50

For string:

  • Substring of length L: v.substring(0, L)

  • example: L=3: iceberg → ice

  • note: Strings are truncated to a valid UTF-8 string with no more than L code points.

  • Source type could be int, long, decimal, string

  • Return type is the same with source type.

§

Year

Extract a date or timestamp year, as years from 1970

  • Source type could be date, timestamp, timestamptz
  • Return type is int
§

Month

Extract a date or timestamp month, as months from 1970-01-01

  • Source type could be date, timestamp, timestamptz
  • Return type is int
§

Day

Extract a date or timestamp day, as days from 1970-01-01

  • Source type could be date, timestamp, timestamptz
  • Return type is int
§

Hour

Extract a timestamp hour, as hours from 1970-01-01 00:00:00

  • Source type could be timestamp, timestamptz
  • Return type is int
§

Void

Always produces null

The void transform may be used to replace the transform in an existing partition field so that the field is effectively dropped in v1 tables.

  • Source type could be any type..
  • Return type is Source type.
§

Unknown

Used to represent some customized transform that can’t be recognized or supported now.

Implementations§

Source§

impl Transform

Source

pub fn to_human_string( &self, field_type: &Type, value: Option<&Literal>, ) -> String

Returns a human-readable String representation of a transformed value.

Source

pub fn result_type(&self, input_type: &Type) -> Result<Type>

Get the return type of transform given the input type. Returns None if it can’t be transformed.

Source

pub fn preserves_order(&self) -> bool

Whether the transform preserves the order of values.

Source

pub fn dedup_name(&self) -> String

Return the unique transform name to check if similar transforms for the same source field are added multiple times in partition spec builder.

Source

pub fn satisfies_order_of(&self, other: &Self) -> bool

Whether ordering by this transform’s result satisfies the ordering of another transform’s result.

For example, sorting by day(ts) will produce an ordering that is also by month(ts) or year(ts). However, sorting by day(ts) will not satisfy the order of hour(ts) or identity(ts).

Source

pub fn strict_project( &self, name: &str, predicate: &BoundPredicate, ) -> Result<Option<Predicate>>

Strictly projects a given predicate according to the transformation specified by the Transform instance.

This method ensures that the projected predicate is strictly aligned with the transformation logic, providing a more precise filtering mechanism for transformed data.

§Example

Suppose, we have row filter a = 10, and a partition spec bucket(a, 37) as bs, if one row matches a = 10, then its partition value should match bucket(10, 37) as bs, and we project a = 10 to bs = bucket(10, 37)

Source

pub fn project( &self, name: &str, predicate: &BoundPredicate, ) -> Result<Option<Predicate>>

Projects a given predicate according to the transformation specified by the Transform instance.

This allows predicates to be effectively applied to data that has undergone transformation, enabling efficient querying and filtering based on the original, untransformed data.

§Example

Suppose, we have row filter a = 10, and a partition spec bucket(a, 37) as bs, if one row matches a = 10, then its partition value should match bucket(10, 37) as bs, and we project a = 10 to bs = bucket(10, 37)

Trait Implementations§

Source§

impl Clone for Transform

Source§

fn clone(&self) -> Transform

Returns a copy 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 Transform

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Transform

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Transform

Source§

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

Formats the value using the given formatter. Read more
Source§

impl FromStr for Transform

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Transform

Source§

fn eq(&self, other: &Transform) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Transform

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Transform

Source§

impl Eq for Transform

Source§

impl StructuralPartialEq for Transform

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
§

impl<T> AsAny for T
where T: Any,

§

fn as_any(&self) -> &(dyn Any + 'static)

§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

§

fn type_name(&self) -> &'static str

Gets the type name of self
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
§

impl<T> Downcast for T
where T: AsAny + ?Sized,

§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

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
§

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> Same for T

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T> ToStringFallible for T
where T: Display,

§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> MaybeSend for T
where T: Send,