Skip to content

Commit

Permalink
Merge pull request #21 from soma-smart/random_integer_provider
Browse files Browse the repository at this point in the history
Create random integer provider
  • Loading branch information
hugues31 authored Feb 16, 2024
2 parents 5238424 + bcf9f8a commit 513143e
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 52 deletions.
92 changes: 50 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
[package]
name = "fakelake"
version = "1.0.0"
version = "1.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
arrow-array = "49.0.0"
arrow-schema = "49.0.0"
arrow-array = "50.0.0"
arrow-schema = "50.0.0"
chrono = "0.4.31"
clap = { version = "4.4.10", features = ["derive"] }
env_logger = "0.10"
fastrand = "2.0.1"
log = "0.4"
once_cell = "1.8"
parquet = "49.0.0"
parquet = "50.0.0"
rayon = "1.8.0"
yaml-rust = "0.4"

[dev-dependencies]
assert_cmd = "2.0"
cargo-tarpaulin = "0.27.2"
cargo-tarpaulin = "0.27.3"
mockall = "0.12.1"
predicates = "2.1"
regex = "1.5"
regex = "1.5"
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<img alt="FakeLake" src="images/logo.svg?raw=true">
</p>

[![GitHub Release](https://img.shields.io/github/v/release/soma-smart/Fakelake?label=Release)](https://github.com/soma-smart/Fakelake/releases)
[![Static Badge](https://img.shields.io/badge/doc-lgreen?logo=readthedocs&logoColor=black)](https://soma-smart.github.io/Fakelake/)

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/soma-smart/Fakelake/build.yml?logo=github&logoColor=black&label=Build)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/soma-smart/Fakelake/test.yml?logo=github&logoColor=black&label=Tests)
![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/soma-smart/Fakelake/total?label=Downloads)
![GitHub Repo stars](https://img.shields.io/github/stars/soma-smart/Fakelake)

<details>
<summary>Table of Contents</summary>
<ol>
Expand Down Expand Up @@ -36,13 +44,12 @@
<a href="#license">License</a>
</li>
</ol>
</details>

</details><br>

# What is FakeLake ?
FakeLake is a command line tool that generates fake data from a YAML schema. It can generate millions of rows in seconds, and is order of magnitude faster than popular Python generators (<a href="#benchmark">see benchmarks</a>).

FakeLake is actively developed and maintained by [SOMA](https://www.linkedin.com/company/soma-smart/mycompany/) in Paris 🇲🇫🦊.
FakeLake is actively developed and maintained by [SOMA](https://www.linkedin.com/company/soma-smart/mycompany/) in Paris 🦊.
```mermaid
flowchart TD
Expand Down
15 changes: 15 additions & 0 deletions docs/columns/providers/random.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ Create a random date with:
[Options](../options.md) are also possible.
### Number
##### i32
```yaml
- name: score
provider: Random.Number.i32
min: -100
max: 100
```
Create a random 32 bits integer with:
- an optional parameter **min**. Default is the minimum 32bits integer.
- an optional parameter **max**. Default is the maximum 32bits integer.
[Options](../options.md) are also possible.
### String
##### alphanumeric
```yaml
Expand Down
3 changes: 2 additions & 1 deletion src/providers/random/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::errors::FakeLakeError;
use crate::providers::provider::Provider;

use super::{date, string};
use super::{date, number, string};

use yaml_rust::Yaml;

Expand All @@ -11,6 +11,7 @@ pub fn get_corresponding_provider(
) -> Result<Box<dyn Provider>, FakeLakeError> {
match provider_split.next() {
Some("date") => date::builder::get_corresponding_provider(provider_split, column),
Some("number") => number::builder::get_corresponding_provider(provider_split, column),
Some("string") => string::builder::get_corresponding_provider(provider_split, column),
_ => Err(FakeLakeError::BadYAMLFormat("".to_string())),
}
Expand Down
1 change: 1 addition & 0 deletions src/providers/random/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod builder;

pub mod date;
pub mod number;
pub mod string;
49 changes: 49 additions & 0 deletions src/providers/random/number/builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use crate::errors::FakeLakeError;
use crate::providers::provider::Provider;

use super::i32::I32Provider;

use yaml_rust::Yaml;

pub fn get_corresponding_provider(
mut provider_split: std::str::Split<'_, char>,
column: &Yaml,
) -> Result<Box<dyn Provider>, FakeLakeError> {
match provider_split.next() {
Some("i32") => Ok(Box::new(I32Provider::new_from_yaml(column))),
_ => Err(FakeLakeError::BadYAMLFormat("".to_string())),
}
}

#[cfg(test)]
mod tests {
use super::get_corresponding_provider;

use yaml_rust::YamlLoader;

#[test]
fn given_i32_should_return_provider() {
let provider_name = "i32";
let yaml_str = format!("name: random_int{}provider: {}", '\n', provider_name);
let column = &YamlLoader::load_from_str(yaml_str.as_str()).unwrap()[0];

let provider_split = provider_name.split('.');
match get_corresponding_provider(provider_split, column) {
Ok(_) => (),
_ => panic!(),
}
}

#[test]
fn given_wrong_provider_should_return_error() {
let provider_name = "not_a_provider";
let yaml_str = format!("name: not{}provider: {}", '\n', provider_name);
let column = &YamlLoader::load_from_str(yaml_str.as_str()).unwrap()[0];

let provider_split = provider_name.split('.');
match get_corresponding_provider(provider_split, column) {
Err(_) => (),
_ => panic!(),
}
}
}
Loading

0 comments on commit 513143e

Please sign in to comment.