Skip to content

Commit f518eab

Browse files
committed
improving the solution
1 parent 6492293 commit f518eab

File tree

4 files changed

+51
-100
lines changed

4 files changed

+51
-100
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pregel-rs"
3-
version = "0.0.11"
3+
version = "0.0.12"
44
authors = [ "Ángel Iglesias Préstamo <angel.iglesias.prestamo@gmail.com>" ]
55
description = "A Graph library written in Rust for implementing your own algorithms in a Pregel fashion"
66
documentation = "https://docs.rs/crate/pregel-rs/latest"

README.md

+41-41
Original file line numberDiff line numberDiff line change
@@ -6,73 +6,73 @@
66
[![documentation](https://img.shields.io/docsrs/pregel-rs/latest)](https://docs.rs/pregel-rs/latest/pregel_rs/)
77

88
`pregel-rs` is a Graph processing library written in Rust that features
9-
a Pregel-based Framework for implementing your own algorithms in a
10-
message-passing fashion. It is designed to be efficient and scalable,
9+
a Pregel-based Framework for implementing your own algorithms in a
10+
message-passing fashion. It is designed to be efficient and scalable,
1111
making it suitable for processing large-scale graphs.
1212

1313
## Features
1414

1515
- _Pregel-based framework_: `pregel-rs` is a powerful graph processing model
16-
that allows users to implement graph algorithms in a message-passing fashion,
17-
where computation is performed on vertices and messages are passed along edges.
18-
`pregel-rs` provides a framework that makes it easy to implement graph
19-
algorithms using this model.
16+
that allows users to implement graph algorithms in a message-passing fashion,
17+
where computation is performed on vertices and messages are passed along edges.
18+
`pregel-rs` provides a framework that makes it easy to implement graph
19+
algorithms using this model.
2020

21-
- _Rust-based implementation_: `pregel-rs` is implemented in Rust, a systems
22-
programming language known for its safety, concurrency, and performance.
23-
Rust's strong type system and memory safety features help ensure that `pregel-rs`
24-
is robust and reliable.
21+
- _Rust-based implementation_: `pregel-rs` is implemented in Rust, a systems
22+
programming language known for its safety, concurrency, and performance.
23+
Rust's strong type system and memory safety features help ensure that `pregel-rs`
24+
is robust and reliable.
2525

2626
- _Efficient and scalable_: `pregel-rs` designed to be efficient and scalable,
27-
making it suitable for processing large-scale graphs. It uses parallelism and
28-
optimization techniques to minimize computation and communication overhead,
29-
allowing it to handle graphs with millions or even billions of vertices and edges.
30-
For us to achieve this, we have built it on top of [polars](https://github.com/pola-rs/polars)
31-
a blazingly fast DataFrames library implemented in Rust using Apache Arrow
32-
Columnar Format as the memory model.
33-
34-
- _Graph abstraction_: `pregel-rs` provides a graph abstraction that makes
35-
it easy to represent and manipulate graphs in Rust. It supports both directed and
36-
undirected graphs, and provides methods for adding, removing, and querying vertices
37-
and edges.
27+
making it suitable for processing large-scale graphs. It uses parallelism and
28+
optimization techniques to minimize computation and communication overhead,
29+
allowing it to handle graphs with millions or even billions of vertices and edges.
30+
For us to achieve this, we have built it on top of [polars](https://github.com/pola-rs/polars)
31+
a blazingly fast DataFrames library implemented in Rust using Apache Arrow
32+
Columnar Format as the memory model.
33+
34+
- _Graph abstraction_: `pregel-rs` provides a graph abstraction that makes
35+
it easy to represent and manipulate graphs in Rust. It supports both directed and
36+
undirected graphs, and provides methods for adding, removing, and querying vertices
37+
and edges.
3838

3939
- _Customizable computation_: `pregel-rs` allows users to implement their own
40-
computation logic by defining vertex computation functions. This gives users the
41-
flexibility to implement their own graph algorithms and customize the behavior
42-
of `pregel-rs` to suit their specific needs.
40+
computation logic by defining vertex computation functions. This gives users the
41+
flexibility to implement their own graph algorithms and customize the behavior
42+
of `pregel-rs` to suit their specific needs.
4343

4444
## Getting started
4545

4646
To get started with `pregel-rs`, you can follow these steps:
4747

4848
1. _Install Rust_: `pregel-rs` requires Rust to be installed on your system.
49-
You can install Rust by following the instructions on the official Rust website:
50-
https://www.rust-lang.org/tools/install
49+
You can install Rust by following the instructions on the official Rust website:
50+
https://www.rust-lang.org/tools/install
5151

5252
2. _Create a new Rust project_: Once Rust is installed, you can create a new Rust
53-
project using the Cargo package manager, which is included with Rust. You can
54-
create a new project by running the following command in your terminal:
53+
project using the Cargo package manager, which is included with Rust. You can
54+
create a new project by running the following command in your terminal:
5555

5656
```sh
5757
cargo new my_pregel_project
5858
```
5959

60-
3. _Add `pregel-rs` as a dependency_: Next, you need to add `pregel-rs` as a
61-
dependency in your `Cargo.toml` file, which is located in the root directory
62-
of your project. You can add the following line to your `Cargo.toml` file:
60+
3. _Add `pregel-rs` as a dependency_: Next, you need to add `pregel-rs` as a
61+
dependency in your `Cargo.toml` file, which is located in the root directory
62+
of your project. You can add the following line to your `Cargo.toml` file:
6363

6464
```toml
6565
[dependencies]
66-
pregel-rs = "0.0.11"
66+
pregel-rs = "0.0.12"
6767
```
6868

6969
4. _Implement your graph algorithm_: Now you can start implementing your graph
70-
algorithm using the `pregel-rs` framework. You can define your vertex computation
71-
functions and use the graph abstraction provided by `pregel-rs` to manipulate the graph.
70+
algorithm using the `pregel-rs` framework. You can define your vertex computation
71+
functions and use the graph abstraction provided by `pregel-rs` to manipulate the graph.
7272

7373
5. _Build and run your project_: Once you have implemented your graph algorithm, you
74-
can build and run your project using the Cargo package manager. You can build your
75-
project by running the following command in your terminal:
74+
can build and run your project using the Cargo package manager. You can build your
75+
project by running the following command in your terminal:
7676

7777
```sh
7878
cargo build
@@ -87,14 +87,14 @@ cargo run
8787
## Acknowledgments
8888

8989
Read [Pregel: A System for Large-Scale Graph Processing](https://15799.courses.cs.cmu.edu/fall2013/static/papers/p135-malewicz.pdf)
90-
for a reference on how to implement your own Graph processing algorithms in a Pregel fashion. If you want to take some
90+
for a reference on how to implement your own Graph processing algorithms in a Pregel fashion. If you want to take some
9191
inspiration from some curated-sources, just explore the [/examples](https://github.com/angelip2303/graph-rs/tree/main/examples)
9292
folder of this repository.
9393

9494
## Related projects
9595

96-
1. [GraphX](https://github.com/apache/spark/tree/master/graphx) is a library enabling Graph processing in the context of
97-
Apache Spark.
96+
1. [GraphX](https://github.com/apache/spark/tree/master/graphx) is a library enabling Graph processing in the context of
97+
Apache Spark.
9898
2. [GraphFrames](https://github.com/graphframes/graphframes) is the DataFrame-based equivalent to GraphX.
9999

100100
## License
@@ -108,11 +108,11 @@ the Free Software Foundation, either version 3 of the License, or
108108

109109
This program is distributed in the hope that it will be useful,
110110
but WITHOUT ANY WARRANTY; without even the implied warranty of
111-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
111+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
112112
GNU General Public License for more details.
113113

114114
You should have received a copy of the GNU General Public License
115-
along with this program. If not, see <https://www.gnu.org/licenses/>.
115+
along with this program. If not, see <https://www.gnu.org/licenses/>.
116116

117117
**By contributing to this project, you agree to release your
118118
contributions under the same license.**

examples/pagerank.rs

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ fn main() -> Result<(), Box<dyn Error>> {
2626
.max_iterations(4)
2727
.with_vertex_column(Custom("rank"))
2828
.initial_message(lit(1.0 / num_vertices))
29+
.send_messages(
30+
MessageReceiver::Subject,
31+
Column::subject(Column::Custom("rank")) / Column::subject(Column::Custom("out_degree")),
32+
)
2933
.send_messages(
3034
MessageReceiver::Object,
3135
Column::subject(Custom("rank")) / Column::subject(Custom("out_degree")),

src/pregel.rs

+5-58
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,6 @@ impl<'a> SendMessage<'a> {
233233
/// each iteration of the algorithm. The vertex program can take as input the current
234234
/// state of the vertex, the messages received from its neighbors or and any other
235235
/// relevant information.
236-
///
237-
/// * `replace_nulls`: `replace_nulls` is an expression that defines how null values
238-
/// in the vertex DataFrame should be replaced. This is useful when the vertex
239-
/// DataFrame contains null values that need to be replaced during the execution of
240-
/// the Pregel algorithm. As an example, when not all vertices are connected to an
241-
/// edge, the edge DataFrame will contain null values in the `dst` column. These
242-
/// null values need to be replaced.
243-
///
244-
/// * `parquet_path` is a property of the `PregelBuilder` struct that represents
245-
/// the path to the Parquet file where the results of the Pregel computation
246-
/// will be stored.
247236
pub struct Pregel<'a> {
248237
/// The `graph` property is a `GraphFrame` struct that represents the
249238
/// graph data structure used in the Pregel algorithm. It contains information about
@@ -277,13 +266,6 @@ pub struct Pregel<'a> {
277266
/// current state of the vertex, the messages received from its neighbors or
278267
/// and any other relevant information.
279268
v_prog: FnBox<'a>,
280-
/// `replace_nulls` is an expression that defines how null values in the vertex
281-
/// DataFrame should be replaced. This is useful when the vertex DataFrame
282-
/// contains null values that need to be replaced during the execution of the
283-
/// Pregel algorithm. As an example, when not all vertices are connected to an
284-
/// edge, the edge DataFrame will contain null values in the `dst` column. These
285-
/// null values need to be replaced.
286-
replace_nulls: Expr,
287269
}
288270

289271
/// The `PregelBuilder` struct represents a builder for configuring the Pregel
@@ -325,13 +307,6 @@ pub struct Pregel<'a> {
325307
/// each iteration of the algorithm. The vertex program can take as input the current
326308
/// state of the vertex, the messages received from its neighbors or and any other
327309
/// relevant information.
328-
///
329-
/// /// * `replace_nulls`: `replace_nulls` is an expression that defines how null values
330-
/// in the vertex DataFrame should be replaced. This is useful when the vertex
331-
/// DataFrame contains null values that need to be replaced during the execution of
332-
/// the Pregel algorithm. As an example, when not all vertices are connected to an
333-
/// edge, the edge DataFrame will contain null values in the `dst` column. These
334-
/// null values need to be replaced.
335310
pub struct PregelBuilder<'a> {
336311
/// The `graph` property is a `GraphFrame` struct that represents the
337312
/// graph data structure used in the Pregel algorithm. It contains information about
@@ -365,13 +340,6 @@ pub struct PregelBuilder<'a> {
365340
/// current state of the vertex, the messages received from its neighbors or
366341
/// and any other relevant information.
367342
v_prog: FnBox<'a>,
368-
/// `replace_nulls` is an expression that defines how null values in the vertex
369-
/// DataFrame should be replaced. This is useful when the vertex DataFrame
370-
/// contains null values that need to be replaced during the execution of the
371-
/// Pregel algorithm. As an example, when not all vertices are connected to an
372-
/// edge, the edge DataFrame will contain null values in the `dst` column. These
373-
/// null values need to be replaced.
374-
replace_nulls: Expr,
375343
}
376344

377345
/// This code is defining an enumeration type `MessageReceiver` in Rust with
@@ -419,7 +387,6 @@ impl<'a> PregelBuilder<'a> {
419387
send_messages: Default::default(),
420388
aggregate_messages: Box::new(Default::default),
421389
v_prog: Box::new(Default::default),
422-
replace_nulls: Default::default(),
423390
}
424391
}
425392

@@ -665,27 +632,6 @@ impl<'a> PregelBuilder<'a> {
665632
self
666633
}
667634

668-
/// This function sets the value of a field called "replace_nulls" in a struct to a
669-
/// given expression and returns the modified struct.
670-
///
671-
/// Arguments:
672-
///
673-
/// * `replace_nulls`: `replace_nulls` is a parameter of type `Expr` that is used in
674-
/// a method of a struct. The method takes ownership of the struct (`self`) and the
675-
/// `replace_nulls` parameter, and sets the `replace_nulls` field of the struct to the
676-
/// value of the `replace_nulls` parameter.
677-
///
678-
/// Returns:
679-
///
680-
/// The `replace_nulls` method returns `Self`, which refers to the same struct
681-
/// instance that the method was called on. This allows for method chaining, where
682-
/// multiple methods can be called on the same struct instance in a single
683-
/// expression.
684-
pub fn replace_nulls(mut self, replace_nulls: Expr) -> Self {
685-
self.replace_nulls = replace_nulls;
686-
self
687-
}
688-
689635
/// The function returns a Pregel struct with the specified properties. This is,
690636
/// Pregel structs are to be created using the `Builder Pattern`, a creational
691637
/// design pattern that provides a way to construct complex structs in a
@@ -743,7 +689,6 @@ impl<'a> PregelBuilder<'a> {
743689
send_messages: self.send_messages,
744690
aggregate_messages: self.aggregate_messages,
745691
v_prog: self.v_prog,
746-
replace_nulls: self.replace_nulls,
747692
}
748693
}
749694
}
@@ -898,7 +843,6 @@ impl<'a> Pregel<'a> {
898843
col(Column::VertexId.as_ref()), // id column of the current_vertices DataFrame
899844
Column::msg(Some(Column::VertexId)), // msg.id column of the message_df DataFrame
900845
)
901-
.with_column(Column::msg(None).fill_null(self.replace_nulls.to_owned()))
902846
.select(&[
903847
col(Column::VertexId.as_ref()),
904848
v_prog().alias(self.vertex_column.as_ref()),
@@ -971,7 +915,11 @@ mod tests {
971915
.max_iterations(iterations)
972916
.with_vertex_column(Column::Custom("rank"))
973917
.initial_message(lit(1.0 / num_vertices))
974-
.replace_nulls(lit(0.0))
918+
.send_messages(
919+
MessageReceiver::Subject,
920+
Column::subject(Column::Custom("rank"))
921+
/ Column::subject(Column::Custom("out_degree")),
922+
)
975923
.send_messages(
976924
MessageReceiver::Object,
977925
Column::subject(Column::Custom("rank"))
@@ -1077,7 +1025,6 @@ mod tests {
10771025
v_prog: Box::new(|| {
10781026
max_exprs([col(Column::Custom("max_value").as_ref()), Column::msg(None)])
10791027
}),
1080-
replace_nulls: lit(0),
10811028
})
10821029
}
10831030

0 commit comments

Comments
 (0)