refactor: use std::from_chars instead of stoi/stoll/stod#556
Open
HuaHuaY wants to merge 1 commit intoapache:mainfrom
Open
refactor: use std::from_chars instead of stoi/stoll/stod#556HuaHuaY wants to merge 1 commit intoapache:mainfrom
HuaHuaY wants to merge 1 commit intoapache:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors numeric parsing to prefer std::from_chars-based parsing and consolidates call sites onto a single StringUtils helper, reducing reliance on exception-throwing std::stoi/stoll/stod in parsing paths.
Changes:
- Replace
StringUtils::ParseIntwith a new templatedStringUtils::ParseNumberand update call sites across the codebase. - Switch various parsing sites (JSON/type parsing, transform parsing, metrics parsing, schema utilities) to use
ParseNumberinstead ofstoi/stod/directfrom_chars. - Minor tweak to error helper overload in
result.h(takestd::stringby value and move).
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/iceberg/util/string_util.h | Introduces ParseNumber to centralize numeric parsing via std::from_chars. |
| src/iceberg/util/decimal.cc | Uses ParseNumber<uint64_t> in decimal digit-group parsing. |
| src/iceberg/util/config.h | Replaces stoll/stod with ParseNumber for default config conversions. |
| src/iceberg/update/update_properties.cc | Switches format-version parsing to ParseNumber<int32_t>. |
| src/iceberg/update/snapshot_update.cc | Switches summary integer parsing to ParseNumber<int64_t>. |
| src/iceberg/transform.cc | Switches regex param parsing from stoi to ParseNumber<int32_t>. |
| src/iceberg/snapshot.cc | Switches snapshot property parsing to ParseNumber<int64_t>. |
| src/iceberg/result.h | Adjusts error factory overload to move std::string messages. |
| src/iceberg/parquet/parquet_writer.cc | Switches codec level parsing to ParseNumber<int32_t>. |
| src/iceberg/parquet/parquet_schema_util.cc | Switches field-id parsing to ParseNumber<int32_t>; adjusts includes. |
| src/iceberg/metrics_config.cc | Switches truncate length parsing to ParseNumber<int32_t>. |
| src/iceberg/json_serde.cc | Switches fixed/decimal param parsing from stoi to ParseNumber<int32_t>. |
| src/iceberg/avro/avro_writer.cc | Switches codec level parsing to ParseNumber<int32_t>. |
| src/iceberg/avro/avro_schema_util.cc | Switches attribute id parsing to ParseNumber<int32_t>; cleans up includes/formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
663af14 to
8c2b509
Compare
8c2b509 to
d29ea9b
Compare
zhjwpku
approved these changes
Feb 7, 2026
Collaborator
zhjwpku
left a comment
There was a problem hiding this comment.
std::from_chars can parse floating point number, so +1 for changing ParseInt to ParseNumber.
Thanks for working on this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.