tpchgen/
lib.rs

1//! Rust TPCH Data Generator
2//!
3//! This crate provides a native Rust implementation of functions and utilities
4//! necessary for generating the TPC-H benchmark dataset in several popular
5//! formats.
6//!
7//! # Example: TBL output format
8//! ```
9//! # use tpchgen::generators::LineItemGenerator;
10//! // Create Generator for the LINEITEM table at Scale Factor 1 (SF 1)
11//! let scale_factor = 1.0;
12//! let part = 1;
13//! let num_parts = 1;
14//! let generator = LineItemGenerator::new(scale_factor, part, num_parts);
15//!
16//! // Output the first 3 rows in classic TPCH TBL format
17//! // (the generators are normal rust iterators and combine well with the Rust ecosystem)
18//! let lines: Vec<_> = generator.iter()
19//!    .take(3)
20//!    .map(|line| line.to_string()) // use Display impl to get TBL format
21//!    .collect::<Vec<_>>();
22//!  assert_eq!(
23//!   lines.join("\n"),"\
24//!   1|155190|7706|1|17|21168.23|0.04|0.02|N|O|1996-03-13|1996-02-12|1996-03-22|DELIVER IN PERSON|TRUCK|egular courts above the|\n\
25//!   1|67310|7311|2|36|45983.16|0.09|0.06|N|O|1996-04-12|1996-02-28|1996-04-20|TAKE BACK RETURN|MAIL|ly final dependencies: slyly bold |\n\
26//!   1|63700|3701|3|8|13309.60|0.10|0.02|N|O|1996-01-29|1996-03-05|1996-01-31|TAKE BACK RETURN|REG AIR|riously. regular, express dep|"
27//!   );
28//! ```
29//!
30//! The TPC-H dataset is composed of several tables with foreign key relations
31//! between them. For each table we implement and expose a generator that uses
32//! the iterator API to produce structs e.g [`LineItem`] that represent a single
33//! row.
34//!
35//! For each struct type we expose several facilities that allow fast conversion
36//! to Tbl and Csv formats but can also be extended to support other output formats.
37//!
38//! This crate currently supports the following output formats:
39//!
40//! - TBL: The `Display` impl of the row structs produces the TPCH TBL format.
41//! - CSV: the [`csv`] module has formatters for CSV output (e.g. [`LineItemCsv`]).
42//!
43//! [`LineItem`]: generators::LineItem
44//! [`LineItemCsv`]: csv::LineItemCsv
45//!
46//! The library was designed to be easily integrated in existing Rust projects as
47//! such it avoids exposing a malleable API and purposely does not have any dependencies
48//! on other Rust crates. It is focused entirely on the core
49//! generation logic.
50//!
51//! If you want an easy way to generate the TPC-H dataset for usage with external
52//! see the [`tpchgen-cli`](https://github.com/alamb/tpchgen-rs/tree/main/tpchgen-cli)
53//! tool instead.
54pub mod csv;
55pub mod dates;
56pub mod decimal;
57pub mod distribution;
58pub mod generators;
59pub mod q_and_a;
60pub mod random;
61pub mod text;