Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement f32 data type #1145

Merged
merged 3 commits into from
Apr 26, 2023
Merged

implement f32 data type #1145

merged 3 commits into from
Apr 26, 2023

Conversation

pythonbrad
Copy link
Contributor

@pythonbrad pythonbrad commented Apr 10, 2023

Implementation of f32 for issue #623

@coveralls
Copy link

coveralls commented Apr 10, 2023

Pull Request Test Coverage Report for Build 4802818313

  • 1071 of 1079 (99.26%) changed or added relevant lines in 14 files are covered.
  • 8 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.2%) to 98.987%

Changes Missing Coverage Covered Lines Changed/Added Lines %
core/src/data/value/literal.rs 46 49 93.88%
core/src/executor/evaluate/function.rs 0 5 0.0%
Files with Coverage Reduction New Missed Lines %
core/src/executor/evaluate/function.rs 1 97.78%
core/src/executor/insert.rs 7 96.34%
Totals Coverage Status
Change from base Build 4777188706: 0.2%
Covered Lines: 43072
Relevant Lines: 43513

💛 - Coveralls

@pythonbrad pythonbrad marked this pull request as ready for review April 10, 2023 17:28
@panarch panarch added the enhancement New feature or request label Apr 11, 2023
@ChobobDev
Copy link
Contributor

I can't wait to see another data type being added to our project :)
Thanks in advance

@pythonbrad pythonbrad marked this pull request as draft April 13, 2023 11:56
@pythonbrad pythonbrad marked this pull request as draft April 13, 2023 11:56
@pythonbrad
Copy link
Contributor Author

@panarch , can i add tests not related to the f32 type but to other types?

@panarch
Copy link
Member

panarch commented Apr 13, 2023

@panarch , can i add tests not related to the f32 type but to other types?

Sure! but it would be good to make a separate PR, then I can do quick review and merge.

@pythonbrad
Copy link
Contributor Author

Ok, I think so

@pythonbrad pythonbrad marked this pull request as ready for review April 14, 2023 12:02
Comment on lines 534 to 535
Value::I32(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?,
Value::I64(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Value::I32(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?,
Value::I64(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?,
Value::I32(value) => *value as f32,
Value::I64(value) => *value as f32,

Could you please also change the f64 below? These types have a smaller range than f32.

Comment on lines 537 to 541
Value::U8(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?,
Value::U16(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?,
Value::U32(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?,
Value::U64(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?,
Value::U128(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?,
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@@ -872,6 +944,8 @@ mod tests {
test!(Value::U32(122), Ok(122));
test!(Value::U64(122), Ok(122));
test!(Value::U128(122), Ok(122));
test!(Value::F32(122.0_f32), Ok(122));
test!(Value::F64(122.9), Ok(122));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
test!(Value::F64(122.9), Ok(122));

There is duplicate code below. Could you please remove it?

(F64(a), _) => a.try_multiply(other),
(Decimal(a), _) => a.try_multiply(other),
(Interval(a), I8(b)) => Ok(Interval(*a * *b)),
(Interval(a), I16(b)) => Ok(Interval(*a * *b)),
(Interval(a), I32(b)) => Ok(Interval(*a * *b)),
(Interval(a), I64(b)) => Ok(Interval(*a * *b)),
(Interval(a), I128(b)) => Ok(Interval(*a * *b)),
(Interval(a), F32(b)) => Ok(Interval(*a * (*b) as f64)),
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason for casting? I think performing the operation with multiplication in f32 would be desirable.

@@ -478,6 +494,7 @@ impl Value {
(Interval(a), U32(b)) => Ok(Interval(*a / *b)),
(Interval(a), U64(b)) => Ok(Interval(*a / *b)),
(Interval(a), U128(b)) => Ok(Interval(*a / *b)),
(Interval(a), F32(b)) => Ok(Interval(*a / (*b as f64))),
Copy link
Member

Choose a reason for hiding this comment

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

ditto

test!(add F32(1.0_f32), F64(2.0) => F64(3.0));
test!(add F32(1.0_f32), I8(2) => F32(3.0_f32));
test!(add F32(1.0_f32), I32(2) => F32(3.0_f32));
test!(add F32(1.0_f32), I64(2) => F32(3.0_f32));
Copy link
Member

Choose a reason for hiding this comment

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

Some data types are empty (there are also other places that need to be organized, so it requires a cleanup. The code for organizing other places might be better handled in a separate PR).
ex) U8, U16, ... ?

test!(subtract I8(3), F32(2.0_f32) => F32(1.0_f32));
test!(subtract I32(3), F32(2.0_f32) => F32(1.0_f32));
test!(subtract I64(3), F32(2.0_f32) => F32(1.0_f32));
test!(subtract I128(3), F32(2.0_f32) => F32(1.0_f32));
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Member

Choose a reason for hiding this comment

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

This is not related to this PR. Please submit it as a separate PR or open an issue for it.

assert_eq!(U32(9).sqrt(), Ok(F32(3.0_f32)));
assert_eq!(U64(9).sqrt(), Ok(F32(3.0_f32)));
assert_eq!(U128(9).sqrt(), Ok(F32(3.0_f32)));
assert_eq!(F32(9.0_f32).sqrt(), Ok(F32(3.0_f32)));
Copy link
Member

Choose a reason for hiding this comment

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

It seems that there are no cases for (f64, f32) and (f32, f64).

Copy link
Member

@panarch panarch left a comment

Choose a reason for hiding this comment

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

Looks all nice!!
Just before the merge, could you add an integration test of float32 in test-suite?

ref.
https://github.com/gluesql/gluesql/tree/main/test-suite/src/data_type

@panarch panarch requested a review from ever0de April 25, 2023 13:52
@panarch panarch self-requested a review April 26, 2023 14:49
Copy link
Member

@panarch panarch left a comment

Choose a reason for hiding this comment

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

Looks all great!!
Thanks a lot 👍

@panarch panarch merged commit 05f717c into gluesql:main Apr 26, 2023
9 checks passed
@pythonbrad pythonbrad deleted the f32 branch April 27, 2023 05:35
This was referenced Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants