refactor: replace hand-rolled string→bool parsing with str_is_truthy/str_to_bool#8675
str_is_truthy/str_to_bool#8675Conversation
Add `str_to_bool` utility to `lance_core::utils::parse` and replace all hand-rolled string-to-boolean parsing throughout the codebase with the appropriate utility functions from `lance_core`. - Add `str_to_bool(val: &str) -> Option<bool>` to lance-core parse utils - Add unit tests for `str_to_bool` - Replace hand-rolled bool parsing in: - lance-core/src/datatypes/field.rs (2 places) - lance-encoding/src/array_encoding/strategy.rs - lance-index/src/scalar/fmindex.rs - lance-index/src/vector/bq/storage.rs - lance-index/src/vector/v3/shuffler.rs - lance-io/src/object_store/providers/aws.rs (2 places) - lance-io/src/object_store/providers/azure.rs - lance-io/src/object_store/providers/gcp.rs - lance-namespace-impls/src/credentials.rs (2 places) - lance-namespace-impls/src/dir.rs (7 places) - lance-namespace-impls/src/rest.rs (2 places) - lance-table/src/transaction/manifest_build.rs - lance/benches/concurrent_append.rs - lance/benches/manifest_commit.rs (2 places) - lance/src/dataset/schema_evolution.rs Co-authored-by: wjones127 <5488879+wjones127@users.noreply.github.com>
str_is_truthy/str_to_bool
|
ACTION NEEDED The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification. For details on the error please inspect the "PR Title Check" action. |
str_is_truthy/str_to_boolstr_is_truthy/str_to_bool
|
@copilot There is a failing test you need to addresss: |
…e") to fix failing test Co-authored-by: wjones127 <5488879+wjones127@users.noreply.github.com>
... Fixed in the latest commit. |
Consolidates scattered string-to-boolean parsing across the codebase into
lance_core::utils::parseutilities, eliminating inconsistent ad-hoc implementations.Changes
New utility:
str_to_bool(val: &str) -> Option<bool>— for cases where an unrecognized value should returnNoneso a caller-side default takes effect. Truthy:1/true/on/yes/y; falsy:0/false/off/no/n; everything else:None.Replaced hand-rolled patterns in 16 files across
lance-core,lance-encoding,lance-index,lance-io,lance-table,lance-namespace-impls, andlancecrates:v == "true"/v.to_lowercase() == "true"/v.eq_ignore_ascii_case("true")→str_is_truthy(v)matches!(s.to_lowercase().as_str(), "true" | "1" | "yes")→str_is_truthy(s)v.parse::<bool>().ok()(config properties) →str_to_bool(v)!matches!(v, "" | "0" | "false" | "off" | "no")→str_is_truthy(v.trim())Added unit tests for
str_to_boolcovering truthy, falsy, and unrecognized inputs.Intentionally unchanged
lance-arrow/src/schema.rs—lance-coredepends onlance-arrow; importing back would create a circular dependency.lance/src/dataset/fragment.rs— checks if a SQL predicate string is literally"true", a semantically distinct use case.lance/src/index/vector/details.rs— uses a genericparse::<T: FromStr>helper, not a string-bool-specific path.lance_core::utils::parse::str_is_truthy#8674