Skip to content

Commit

Permalink
Merge pull request #1416 from jqnatividad/stats-atoi
Browse files Browse the repository at this point in the history
`stats`: use atoi to skip utf8 validation to directly convert &[u8] to integer validation
  • Loading branch information
jqnatividad authored Nov 14, 2023
2 parents fbd0726 + 69bfbe3 commit 43c73ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ panic = "abort"
[dependencies]
ahash = "0.8"
anyhow = { version = "1.0", optional = true }
atoi = "2"
bincode = "1.3"
byteorder = "1.5"
bytes = "1"
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,8 @@ impl Stats {
};
}
},
// do nothing for String type
TString => {},
TFloat | TInteger => {
if sample_type == TNull {
if self.which.include_nulls {
Expand All @@ -1069,8 +1071,6 @@ impl Stats {
}
}
},
// do nothing for String type
TString => {},
TDateTime | TDate => {
if sample_type == TNull {
if self.which.include_nulls {
Expand Down Expand Up @@ -1612,7 +1612,7 @@ impl TypedSum {
// so we don't panic on overflow/underflow, use saturating_add
self.integer = self
.integer
.saturating_add(from_bytes::<i64>(sample).unwrap());
.saturating_add(atoi::atoi::<i64>(sample).unwrap());
}
},
_ => {},
Expand Down Expand Up @@ -1685,13 +1685,13 @@ impl TypedMinMax {
self.integers.add(n as i64);
},
TInteger => {
let n = from_utf8(sample).unwrap().parse::<i64>().unwrap();
let n = atoi::atoi::<i64>(sample).unwrap();
self.integers.add(n);
#[allow(clippy::cast_precision_loss)]
self.floats.add(n as f64);
},
TDate | TDateTime => {
let n = from_utf8(sample).unwrap().parse::<i64>().unwrap();
let n = atoi::atoi::<i64>(sample).unwrap();
self.dates.add(n);
},
}
Expand Down

0 comments on commit 43c73ee

Please sign in to comment.