Skip to content

Commit

Permalink
Merge pull request #48 from bgpkit/fix/47-nullable-column
Browse files Browse the repository at this point in the history
Properly write nullable values to sqlite
  • Loading branch information
digizeph authored Jun 2, 2023
2 parents 0c86d0d + 3350c70 commit c1e1c5e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/monocle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ fn main() {
for elem in receiver {
msg_count += 1;
msg_cache.push(elem);
if msg_cache.len() >= 500 {
if msg_cache.len() >= 100000 {
db.insert_elems(&msg_cache);
msg_cache.clear();
}
Expand Down
44 changes: 22 additions & 22 deletions src/msg_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use itertools::Itertools;
macro_rules! option_to_string {
($a:expr) => {
if let Some(v) = $a {
v.to_string()
format!("'{}'", v)
} else {
String::new()
"NULL".to_string()
}
};
}
Expand Down Expand Up @@ -58,14 +58,14 @@ impl MsgStore {
#[inline(always)]
fn option_to_string_communities(o: &Option<Vec<MetaCommunity>>) -> String {
if let Some(v) = o {
v.iter().join(" ")
format!("'{}'", v.iter().join(" "))
} else {
String::new()
"NULL".to_string()
}
}

pub fn insert_elems(&self, elems: &[BgpElem]) {
for elems in elems.chunks(100) {
for elems in elems.chunks(10000) {
let values = elems
.iter()
.map(|elem| {
Expand All @@ -77,23 +77,23 @@ impl MsgStore {
};
let origin_string = elem.origin_asns.as_ref().map(|asns| asns.get(0).unwrap());
format!(
"('{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}')",
elem.timestamp as u32,
t,
elem.peer_ip,
elem.peer_asn,
elem.prefix,
option_to_string!(&elem.next_hop),
option_to_string!(&elem.as_path),
option_to_string!(origin_string),
option_to_string!(&elem.origin),
option_to_string!(&elem.local_pref),
option_to_string!(&elem.med),
Self::option_to_string_communities(&elem.communities),
option_to_string!(&elem.atomic),
option_to_string!(&elem.aggr_asn),
option_to_string!(&elem.aggr_ip),
)
"('{}','{}','{}','{}','{}', {},{},{},{},{},{},{},{},{},{})",
elem.timestamp as u32,
t,
elem.peer_ip,
elem.peer_asn,
elem.prefix,
option_to_string!(&elem.next_hop),
option_to_string!(&elem.as_path),
option_to_string!(origin_string),
option_to_string!(&elem.origin),
option_to_string!(&elem.local_pref),
option_to_string!(&elem.med),
Self::option_to_string_communities(&elem.communities),
option_to_string!(&elem.atomic),
option_to_string!(&elem.aggr_asn),
option_to_string!(&elem.aggr_ip),
)
})
.join(", ")
.to_string();
Expand Down

0 comments on commit c1e1c5e

Please sign in to comment.