pub enum Column {
VertexId,
Subject,
Predicate,
Object,
Edge,
Msg,
Pregel,
Custom(&'static str),
}
Expand description
This defines an enumeration type ColumnIdentifier
in Rust. It has several
variants: VertexId
, Subject
, Predicate
, Object
, Edge
, Msg
, Pregel
,
and Custom
which takes a String
parameter. This enum can be used to represent
different types of columns in a data structure or database table for it to be used
in a Pregel program.
Variants§
VertexId
The VertexId
variant represents the column that contains the vertex IDs.
Subject
The Subject
variant represents the column that contains the source vertex IDs.
Predicate
The Predicate
variant represents the column that contains the IDs of the predicates.
Object
The Object
variant represents the column that contains the destination vertex IDs.
Edge
The Edge
variant represents the column that contains the edge IDs.
Msg
The Msg
variant represents the column that contains the messages sent to a vertex.
Pregel
The Pregel
variant represents the column that contains the messages sent to a vertex.
Custom(&'static str)
The Custom
variant represents a column that is not one of the predefined columns.
Implementations§
source§impl Column
impl Column
sourcepub fn subject(column_name: Column) -> Expr
pub fn subject(column_name: Column) -> Expr
This function returns an expression for a column identifier representing the source vertex in a Pregel graph.
Arguments:
column_name
:column_name
is a parameter of typeColumnIdentifier
. It is used to identify the name of a column in a table or data source. Thesubject
function takes this parameter and returns an expression that represents the value of the column with the given name.
Returns:
The function subject
returns an Expr
which represents a reference to the source
vertex ID column in a Pregel graph computation. The Expr
is created using the
col
function and the alias
method of the Pregel
struct to generate the
appropriate column name.
Examples found in repository?
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() -> Result<(), Box<dyn Error>> {
let edges = df![
Subject.as_ref() => [0, 1, 1, 2, 2, 3],
Object.as_ref() => [1, 0, 3, 1, 3, 2],
]?;
let vertices = df![
VertexId.as_ref() => [0, 1, 2, 3],
Custom("value").as_ref() => [3, 6, 2, 1],
]?;
let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
.max_iterations(4)
.with_vertex_column(Custom("max_value"))
.initial_message(col(Custom("value").as_ref()))
.send_messages(
MessageReceiver::Object,
Column::subject(Custom("max_value")),
)
.aggregate_messages(Column::msg(None).max())
.v_prog(max_exprs([
col(Custom("max_value").as_ref()),
Column::msg(None),
]))
.build();
Ok(println!("{}", pregel.run()?))
}
More examples
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
fn main() -> Result<(), Box<dyn Error>> {
let edges = df![
Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
]?;
let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;
let damping_factor = 0.85;
let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;
let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
.max_iterations(4)
.with_vertex_column(Custom("rank"))
.initial_message(lit(1.0 / num_vertices))
.send_messages(
MessageReceiver::Subject,
Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
)
.send_messages(
MessageReceiver::Object,
Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
)
.aggregate_messages(Column::msg(None).sum())
.v_prog(
Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
)
.build();
Ok(println!("{}", pregel.run()?))
}
sourcepub fn object(column_name: Column) -> Expr
pub fn object(column_name: Column) -> Expr
This function returns an expression for a column identifier representing the destination vertex in a Pregel graph.
Arguments:
column_name
:column_name
is a parameter of typeColumnIdentifier
which represents the name of a column in a table. It is used as an argument to theobject
function to create an expression that refers to the column with the given name in the context of a Pregel computation.
Returns:
The function object
returns an expression that represents the value of the column
with the given column_name
in the context of a Pregel
graph computation. The
expression is created using the col
function and the alias
method of the
Pregel
struct to ensure that the column name is properly qualified.
sourcepub fn edge(column_name: Column) -> Expr
pub fn edge(column_name: Column) -> Expr
This function returns an expression for a column name in a graph edge table.
Arguments:
column_name
:column_name
is a parameter of typeColumnIdentifier
which represents the name of a column in a graph edge table. Theedge
function returns an expression that refers to this column using thecol
function and thealias
function from thePregel
struct.
Returns:
The function edge
returns an Expr
which represents a reference to a column
in a graph edge table. The column name is passed as an argument to the function
and is used to construct the full column identifier using the Column::alias
method.
sourcepub fn msg(column_name: Option<Column>) -> Expr
pub fn msg(column_name: Option<Column>) -> Expr
This function returns an expression for a column name, either using a default value or a specified value.
Arguments:
column_name
: An optional parameter of typeColumnIdentifier
. It represents the name of a column in a table. If it isNone
, the function returns a reference to thePregel
column. If it isSome(column_name)
, the function returns a reference to a column with the name
Returns:
an Expr
which is either a reference to the ColumnIdentifier::Pregel
column
if column_name
is None
, or a reference to a column with an alias created by
Column::alias
if column_name
is Some
.
Examples found in repository?
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
fn main() -> Result<(), Box<dyn Error>> {
let edges = df![
Subject.as_ref() => [0, 1, 1, 2, 2, 3],
Object.as_ref() => [1, 0, 3, 1, 3, 2],
]?;
let vertices = df![
VertexId.as_ref() => [0, 1, 2, 3],
Custom("value").as_ref() => [3, 6, 2, 1],
]?;
let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
.max_iterations(4)
.with_vertex_column(Custom("max_value"))
.initial_message(col(Custom("value").as_ref()))
.send_messages(
MessageReceiver::Object,
Column::subject(Custom("max_value")),
)
.aggregate_messages(Column::msg(None).max())
.v_prog(max_exprs([
col(Custom("max_value").as_ref()),
Column::msg(None),
]))
.build();
Ok(println!("{}", pregel.run()?))
}
More examples
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
fn main() -> Result<(), Box<dyn Error>> {
let edges = df![
Subject.as_ref() => [0, 0, 1, 2, 3, 4, 4, 4],
Object.as_ref() => [1, 2, 2, 3, 3, 1, 2, 3],
]?;
let vertices = GraphFrame::from_edges(edges.clone())?.out_degrees()?;
let damping_factor = 0.85;
let num_vertices: f64 = vertices.column(VertexId.as_ref())?.len() as f64;
let pregel = PregelBuilder::new(GraphFrame::new(vertices, edges)?)
.max_iterations(4)
.with_vertex_column(Custom("rank"))
.initial_message(lit(1.0 / num_vertices))
.send_messages(
MessageReceiver::Subject,
Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
)
.send_messages(
MessageReceiver::Object,
Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),
)
.aggregate_messages(Column::msg(None).sum())
.v_prog(
Column::msg(None) * lit(damping_factor) + lit((1.0 - damping_factor) / num_vertices),
)
.build();
Ok(println!("{}", pregel.run()?))
}
Trait Implementations§
source§impl AsRef<str> for Column
impl AsRef<str> for Column
This is the implementation of the AsRef
trait for the Column
enum. This
allows instances of the Column
enum to be used as references to strings. The
as_ref
method returns a reference to a string that corresponds to the variant
of the Column
enum. If the variant is Custom
, the string is the custom
identifier provided as an argument to the variant. This allows the Column
enum to be used as a reference to a string in a Pregel program.
Examples
use polars::prelude::*;
use pregel_rs::pregel::Column::{Custom, VertexId};
let vertices = df![
VertexId.as_ref() => [0, 1, 2, 3],
Custom("value").as_ref() => [3, 6, 2, 1],
];
source§impl From<MessageReceiver> for Column
impl From<MessageReceiver> for Column
The above code is implementing the From
trait for the Column
enum, which
allows creating a Column
instance from a MessageReceiver
instance. The
match
statement maps the MessageReceiver
variants to the corresponding
Column
variants.