laskoviymishka commented on code in PR #3476:
URL: https://github.com/apache/iceberg-rust/pull/3476#discussion_r4349153084
##########
crates/iceberg/src/spec/values/tests.rs:
##########
@@ -187,6 +187,53 @@ fn json_double() {
);
}
+const FLOAT_VALUES: [f32; 6] = [
+ 100.1,
+ 123.456,
+ -123.456,
+ f32::MAX,
+ f32::MIN,
+ f32::from_bits(1),
+];
+
+#[test]
+fn raw_literal_json_number_to_float() {
+ for value in FLOAT_VALUES {
+ let raw: RawLiteral =
serde_json::from_str(&format!("{value:e}")).unwrap();
+
+ assert_eq!(
+ raw.try_into(&Primitive(PrimitiveType::Float)).unwrap(),
+ Some(Literal::float(value))
+ );
+ }
+}
+
+#[test]
+fn raw_literal_avro_double_to_float() {
+ for value in FLOAT_VALUES {
+ for double in [f64::from(value),
format!("{value:e}").parse().unwrap()] {
+ let raw: RawLiteral =
apache_avro::from_value(&Value::Double(double)).unwrap();
+
+ assert_eq!(
+ raw.try_into(&Primitive(PrimitiveType::Float)).unwrap(),
+ Some(Literal::float(value))
+ );
+ }
+ }
+}
+
+#[test]
+fn raw_literal_double_without_exact_float_narrows_to_nearest() {
Review Comment:
Could we also cover `Value::Double(f64::NAN)`, `INFINITY`, `NEG_INFINITY`
and `-0.0` next to this one? Their output is unchanged, because `main` only ran
the precision check on finite results ([serde.rs on
main](https://github.com/apache/iceberg-rust/blob/f83bec42298a1cf51a42ea2aee26c041a15db5b4/crates/iceberg/src/spec/values/serde.rs#L469-L483)).
Now that the arm is a bare cast, though, no test pins that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]