risingwave_common::hash::key

Trait HashKeySer

source
pub trait HashKeySer<'a>: ScalarRef<'a> {
    // Required method
    fn serialize_into(self, buf: impl BufMut);

    // Provided methods
    fn exact_size() -> Option<usize> { ... }
    fn estimated_size(self) -> usize { ... }
}
Expand description

Extension of scalars to be serialized into hash keys.

The exact_size and estimated_size methods are used to estimate the size of the serialized hash key, so that we can pre-allocate the buffer for it.

  • override exact_size if the serialized size is known for this scalar type;
  • override estimated_size if the serialized size varies for different values of this scalar type, but we can estimate it.

NOTE: The hash key encoding algorithm needs to respect the implementation of Hash and Eq on scalar types, which is exactly the same behavior of the data types under GROUP BY or PARTITION BY in PostgreSQL. For example, Decimal(1.0) vs Decimal(1.00), or Interval(24 hour) vs Interval(1 day) are considered equal here.

This means that…

  • delegating to the value encoding can be incorrect for some types, as they reflect the in-memory representation faithfully;
  • delegating to the memcmp encoding should be always safe, but they put extra effort to also preserve the property of Ord.

So for some scalar types we have to maintain a separate implementation here. For those that can be delegated to other encoding algorithms, we can use macros of impl_memcmp_encoding_hash_key_serde! and impl_value_encoding_hash_key_serde! here.

Required Methods§

source

fn serialize_into(self, buf: impl BufMut)

Serialize the scalar into the given buffer.

Provided Methods§

source

fn exact_size() -> Option<usize>

Returns Some if the serialized size is known for this scalar type.

source

fn estimated_size(self) -> usize

Returns the estimated serialized size for this scalar.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl HashKeySer<'_> for bool

source§

fn serialize_into(self, buf: impl BufMut)

source§

fn exact_size() -> Option<usize>

source§

impl HashKeySer<'_> for i16

source§

fn serialize_into(self, buf: impl BufMut)

source§

fn exact_size() -> Option<usize>

source§

impl HashKeySer<'_> for i32

source§

fn serialize_into(self, buf: impl BufMut)

source§

fn exact_size() -> Option<usize>

source§

impl HashKeySer<'_> for i64

source§

fn serialize_into(self, buf: impl BufMut)

source§

fn exact_size() -> Option<usize>

source§

impl<'a> HashKeySer<'a> for <Box<str> as Scalar>::ScalarRefType<'a>

source§

fn serialize_into(self, buf: impl BufMut)

source§

fn estimated_size(self) -> usize

source§

impl<'a> HashKeySer<'a> for <Box<[u8]> as Scalar>::ScalarRefType<'a>

source§

fn serialize_into(self, buf: impl BufMut)

source§

fn estimated_size(self) -> usize

Implementors§