alopex_dataframe/io/
options.rs1use crate::Expr;
2
3#[derive(Debug, Clone)]
5pub struct CsvReadOptions {
6 pub has_header: bool,
8 pub delimiter: u8,
10 pub quote_char: Option<u8>,
12 pub null_values: Vec<String>,
14 pub infer_schema_length: usize,
16 pub projection: Option<Vec<String>>,
18 pub predicate: Option<Expr>,
20}
21
22impl Default for CsvReadOptions {
23 fn default() -> Self {
24 Self {
25 has_header: true,
26 delimiter: b',',
27 quote_char: Some(b'"'),
28 null_values: Vec::new(),
29 infer_schema_length: 100,
30 projection: None,
31 predicate: None,
32 }
33 }
34}
35
36impl CsvReadOptions {
37 pub fn with_has_header(mut self, has_header: bool) -> Self {
39 self.has_header = has_header;
40 self
41 }
42
43 pub fn with_delimiter(mut self, delimiter: u8) -> Self {
45 self.delimiter = delimiter;
46 self
47 }
48
49 pub fn with_quote_char(mut self, quote_char: Option<u8>) -> Self {
51 self.quote_char = quote_char;
52 self
53 }
54
55 pub fn with_null_values<I, S>(mut self, values: I) -> Self
57 where
58 I: IntoIterator<Item = S>,
59 S: Into<String>,
60 {
61 self.null_values = values.into_iter().map(Into::into).collect();
62 self
63 }
64
65 pub fn with_infer_schema_length(mut self, infer_schema_length: usize) -> Self {
67 self.infer_schema_length = infer_schema_length;
68 self
69 }
70
71 pub fn with_projection<I, S>(mut self, columns: I) -> Self
73 where
74 I: IntoIterator<Item = S>,
75 S: Into<String>,
76 {
77 self.projection = Some(columns.into_iter().map(Into::into).collect());
78 self
79 }
80
81 pub fn with_predicate(mut self, predicate: Expr) -> Self {
83 self.predicate = Some(predicate);
84 self
85 }
86}
87
88#[derive(Debug, Clone)]
90pub struct ParquetReadOptions {
91 pub columns: Option<Vec<String>>,
93 pub row_groups: Option<Vec<usize>>,
95 pub batch_size: usize,
97 pub predicate: Option<Expr>,
99}
100
101impl Default for ParquetReadOptions {
102 fn default() -> Self {
103 Self {
104 columns: None,
105 row_groups: None,
106 batch_size: 65_536,
107 predicate: None,
108 }
109 }
110}
111
112impl ParquetReadOptions {
113 pub fn with_columns<I, S>(mut self, columns: I) -> Self
115 where
116 I: IntoIterator<Item = S>,
117 S: Into<String>,
118 {
119 self.columns = Some(columns.into_iter().map(Into::into).collect());
120 self
121 }
122
123 pub fn with_row_groups<I>(mut self, row_groups: I) -> Self
125 where
126 I: IntoIterator<Item = usize>,
127 {
128 self.row_groups = Some(row_groups.into_iter().collect());
129 self
130 }
131
132 pub fn with_batch_size(mut self, batch_size: usize) -> Self {
134 self.batch_size = batch_size;
135 self
136 }
137
138 pub fn with_predicate(mut self, predicate: Expr) -> Self {
140 self.predicate = Some(predicate);
141 self
142 }
143}