osv 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/osv/src/csv/builder.rs +1 -3
- data/ext/osv/src/csv/parser.rs +33 -25
- data/lib/osv/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a6579b30fb8761382666c3fcfa434d9234c3ebf508cad7b3045b9f4ebc2f8b7
|
4
|
+
data.tar.gz: afb793b1df201e876e955ed75904c729aa353bdee3ae374085902efdd4601603
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4318353ec8b32f026d3a3c8675a26b6a6545faba213bba28ada9b0ab7d978ea8d7dd6a8e202aaefb765040cc0d54990fd94f8263bbf4ecd6a4150ab9f48e7cc6
|
7
|
+
data.tar.gz: d0c590105f070773f82a2e00c0c069439c55055cfe958e7eb3bcf443a83fb1d3dd1f099b93f2835a30797024451666e42f18aeaa361432824d18f77cfaa4748f
|
data/ext/osv/src/csv/builder.rs
CHANGED
@@ -80,7 +80,6 @@ impl<'a, T: RecordParser + Send + 'static> RecordReaderBuilder<'a, T> {
|
|
80
80
|
|
81
81
|
pub fn build(self) -> Result<RecordReader<T>, Error> {
|
82
82
|
let readable = self.get_reader()?;
|
83
|
-
|
84
83
|
let mut reader = csv::ReaderBuilder::new()
|
85
84
|
.has_headers(self.has_headers)
|
86
85
|
.delimiter(self.delimiter)
|
@@ -88,14 +87,13 @@ impl<'a, T: RecordParser + Send + 'static> RecordReaderBuilder<'a, T> {
|
|
88
87
|
.from_reader(readable);
|
89
88
|
|
90
89
|
let headers = RecordReader::<T>::get_headers(self.ruby, &mut reader, self.has_headers)?;
|
91
|
-
let headers_clone = headers.clone();
|
92
90
|
let null_string = self.null_string;
|
93
91
|
|
94
92
|
let (sender, receiver) = kanal::bounded(self.buffer);
|
95
93
|
let handle = thread::spawn(move || {
|
96
94
|
let mut record = csv::StringRecord::new();
|
97
95
|
while let Ok(true) = reader.read_record(&mut record) {
|
98
|
-
let row = T::parse(&
|
96
|
+
let row = T::parse(&headers, &record, &null_string);
|
99
97
|
if sender.send(row).is_err() {
|
100
98
|
break;
|
101
99
|
}
|
data/ext/osv/src/csv/parser.rs
CHANGED
@@ -2,42 +2,50 @@ use std::collections::HashMap;
|
|
2
2
|
|
3
3
|
pub trait RecordParser {
|
4
4
|
type Output;
|
5
|
-
|
6
|
-
|
5
|
+
fn parse<'a>(
|
6
|
+
headers: &'a [String],
|
7
|
+
record: &csv::StringRecord,
|
8
|
+
null_string: &str,
|
9
|
+
) -> Self::Output;
|
7
10
|
}
|
8
11
|
|
9
12
|
impl RecordParser for HashMap<String, Option<String>> {
|
10
13
|
type Output = Self;
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
fn parse<'a>(
|
15
|
+
headers: &'a [String],
|
16
|
+
record: &csv::StringRecord,
|
17
|
+
null_string: &str,
|
18
|
+
) -> Self::Output {
|
19
|
+
let mut map = HashMap::with_capacity(headers.len());
|
20
|
+
for (header, field) in headers.iter().zip(record.iter()) {
|
21
|
+
map.insert(
|
22
|
+
header.clone(),
|
23
|
+
if field == null_string {
|
18
24
|
None
|
19
25
|
} else {
|
20
26
|
Some(field.to_string())
|
21
|
-
}
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
},
|
28
|
+
);
|
29
|
+
}
|
30
|
+
map
|
25
31
|
}
|
26
32
|
}
|
27
33
|
|
28
34
|
impl RecordParser for Vec<Option<String>> {
|
29
35
|
type Output = Self;
|
30
|
-
|
31
|
-
|
32
|
-
record
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
fn parse<'a>(
|
37
|
+
_headers: &'a [String],
|
38
|
+
record: &csv::StringRecord,
|
39
|
+
null_string: &str,
|
40
|
+
) -> Self::Output {
|
41
|
+
let mut vec = Vec::with_capacity(record.len());
|
42
|
+
for field in record.iter() {
|
43
|
+
vec.push(if field == null_string {
|
44
|
+
None
|
45
|
+
} else {
|
46
|
+
Some(field.to_string())
|
47
|
+
});
|
48
|
+
}
|
49
|
+
vec
|
42
50
|
}
|
43
51
|
}
|
data/lib/osv/version.rb
CHANGED