risingwave_common::types::fields

Trait Fields

source
pub trait Fields {
    const PRIMARY_KEY: Option<&'static [usize]>;

    // Required methods
    fn fields() -> Vec<(&'static str, DataType)>;
    fn into_owned_row(self) -> OwnedRow;

    // Provided method
    fn data_chunk_builder(capacity: usize) -> DataChunkBuilder { ... }
}
Expand description

A struct can implements Fields when if can be represented as a relational Row.

§Derivable

This trait can be automatically derived with #[derive(Fields)]. Type of the fields must implement WithDataType and ToOwnedDatum.


#[derive(Fields)]
struct Data {
    v1: i16,
    v2: i32,
}

You can add #[primary_key] attribute to one of the fields to specify the primary key of the table.


#[derive(Fields)]
struct Data {
    #[primary_key]
    v1: i16,
    v2: i32,
}

If the primary key is composite, you can add #[primary_key(...)] attribute to the struct to specify the order of the fields.


#[derive(Fields)]
#[primary_key(v2, v1)]
struct Data {
    v1: i16,
    v2: i32,
}

Required Associated Constants§

source

const PRIMARY_KEY: Option<&'static [usize]>

The primary key of the table.

  • None if the primary key is not applicable.
  • Some(&[]) if the primary key is empty, i.e., there’ll be at most one row in the table.

Required Methods§

source

fn fields() -> Vec<(&'static str, DataType)>

Return the schema of the struct.

source

fn into_owned_row(self) -> OwnedRow

Convert the struct to an OwnedRow.

Provided Methods§

source

fn data_chunk_builder(capacity: usize) -> DataChunkBuilder

Create a DataChunkBuilder with the schema of the struct.

Object Safety§

This trait is not object safe.

Implementors§