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
impl Transform
Sourcepub fn to_human_string(
&self,
field_type: &Type,
value: Option<&Literal>,
) -> String
pub fn to_human_string( &self, field_type: &Type, value: Option<&Literal>, ) -> String
Returns a human-readable String representation of a transformed value.
Sourcepub fn result_type(&self, input_type: &Type) -> Result<Type>
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.
Sourcepub fn preserves_order(&self) -> bool
pub fn preserves_order(&self) -> bool
Whether the transform preserves the order of values.
Sourcepub fn dedup_name(&self) -> String
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.
Sourcepub fn satisfies_order_of(&self, other: &Self) -> bool
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).
Sourcepub fn strict_project(
&self,
name: &str,
predicate: &BoundPredicate,
) -> Result<Option<Predicate>>
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)
Sourcepub fn project(
&self,
name: &str,
predicate: &BoundPredicate,
) -> Result<Option<Predicate>>
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<'de> Deserialize<'de> for Transform
impl<'de> Deserialize<'de> for Transform
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Copy for Transform
impl Eq for Transform
impl StructuralPartialEq for Transform
Auto Trait Implementations§
impl Freeze for Transform
impl RefUnwindSafe for Transform
impl Send for Transform
impl Sync for Transform
impl Unpin for Transform
impl UnwindSafe for Transform
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: AsAny + ?Sized,
impl<T> Downcast for Twhere
T: AsAny + ?Sized,
§fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
Any.§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
Any.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.