Skip to content

fix: to_i64 and to_u64 function support rounded numeric conversion#100

Merged
sundy-li merged 3 commits intodatabendlabs:mainfrom
b41sh:fix-cast-integer
Mar 27, 2026
Merged

fix: to_i64 and to_u64 function support rounded numeric conversion#100
sundy-li merged 3 commits intodatabendlabs:mainfrom
b41sh:fix-cast-integer

Conversation

@b41sh
Copy link
Copy Markdown
Member

@b41sh b41sh commented Mar 26, 2026

This PR refines integer conversion behavior for JSON numbers by separating exact integer extraction from rounded numeric coercion.

Changes

  • Restored Number::as_i128, Number::as_i64, and Number::as_u64 to exact-integer semantics.
  • Added Number::to_i128, Number::to_i64, and Number::to_u64 for rounded numeric conversion.
  • Updated RawJsonb::to_i64 and RawJsonb::to_u64 to round numeric values before conversion.
  • Added support for rounding stringified floats in RawJsonb::to_i64 and RawJsonb::to_u64.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts integer conversion semantics for JSON numbers by distinguishing exact integer extraction (as_*) from rounded numeric coercion (to_*), and updates scalar conversion helpers and tests accordingly.

Changes:

  • Restored Number::{as_i128,as_i64,as_u64} to exact-integer-only behavior and introduced Number::{to_i128,to_i64,to_u64} for rounded conversion.
  • Updated RawJsonb::{to_i64,to_u64} to round numeric values before conversion and added parsing support for stringified floats.
  • Expanded integration/unit tests to cover exact-vs-rounded behavior for numeric conversions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/it/functions.rs Adds/updates integration tests for exact integer extraction and rounded coercions (including stringified floats).
src/number.rs Implements exact integer extraction helpers and new rounded conversion APIs for Number, plus supporting tests.
src/functions/scalar.rs Updates RawJsonb scalar conversion docs and changes to_{i64,u64} to use the new rounded conversion + string-float parsing helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/functions/scalar.rs Outdated
Comment thread src/number.rs Outdated
Comment thread tests/it/functions.rs
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@b41sh b41sh requested a review from sundy-li March 27, 2026 06:40
@sundy-li sundy-li merged commit 9621ebc into databendlabs:main Mar 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants