mbutrovich opened a new issue, #3813:
URL: https://github.com/apache/iceberg-rust/issues/3813

   ## Apache Iceberg Rust version
   
   `main` (`6cca8cdec6881d057581bdf9cc21c3ad426c0283`)
   
   ## Describe the bug
   
   Predicate binding converts each literal to the column type with `Datum::to` 
([predicate.rs#L419](https://github.com/apache/iceberg-rust/blob/6cca8cdec6881d057581bdf9cc21c3ad426c0283/crates/iceberg/src/expr/predicate.rs#L419)).
 The `int` and `long` arms match on the literal's storage and ignore its type 
([datum.rs#L1155-L1160](https://github.com/apache/iceberg-rust/blob/6cca8cdec6881d057581bdf9cc21c3ad426c0283/crates/iceberg/src/spec/values/datum.rs#L1155-L1160)).
 So a `date` literal converts to `int` or `long`, an `int` literal converts to 
`date`, and a `timestamp`, `timestamptz`, `timestamp_ns`, or `time` literal 
converts to `int`. None of these is in the [promotion 
table](https://github.com/apache/iceberg/blob/06f1574471c4603443a67f78af72e4e1d0aeacea/format/spec.md?plain=1#L408-L416),
 and the [expressions 
spec](https://github.com/apache/iceberg/blob/06f1574471c4603443a67f78af72e4e1d0aeacea/format/expressions-spec.md?plain=1#L127)
 says:
   
   > If the types cannot be aligned according to type promotion rules (for 
instance, `"goats" > -Infinity`), the predicate cannot be evaluated and 
implementations must fail.
   
   ## To Reproduce
   
   ```rust
   use std::sync::Arc;
   
   use iceberg::expr::{Bind, Reference};
   use iceberg::spec::{Datum, NestedField, PrimitiveType, Schema, Type};
   
   #[test]
   fn datum_to_ignores_source_type() {
       let int = Type::Primitive(PrimitiveType::Int);
       println!("{:?}", Datum::date(5).to(&int));
       println!("{:?}", 
Datum::date(5).to(&Type::Primitive(PrimitiveType::Long)));
       println!("{:?}", 
Datum::int(5).to(&Type::Primitive(PrimitiveType::Date)));
       println!("{:?}", Datum::timestamp_micros(5).to(&int));
       println!("{:?}", Datum::time_micros(5).unwrap().to(&int));
   
       let schema = Arc::new(
           Schema::builder()
               .with_fields(vec![NestedField::required(1, "int_col", 
int).into()])
               .build()
               .unwrap(),
       );
       let bound = Reference::new("int_col")
           .less_than(Datum::date(5))
           .bind(schema, true)
           .unwrap();
       println!("{bound}");
   }
   ```
   
   Output:
   
   ```text
   Ok(Datum { type: Int, literal: Int(5) })
   Ok(Datum { type: Long, literal: Long(5) })
   Ok(Datum { type: Date, literal: Int(5) })
   Ok(Datum { type: Int, literal: Int(5) })
   Ok(Datum { type: Int, literal: Int(5) })
   int_col < 5
   ```
   
   ## Expected behavior
   
   Each conversion above returns an error, the way 
`Datum::string("x").to(date)` already does ("Can't convert datum from string 
type to date type."). A `long` literal bound to an `int` column still converts, 
because its `AboveMax` and `BelowMin` results are how binding handles 
out-of-range literals.
   
   Only two tests depend on the current behavior. When the four arms at 
datum.rs#L1155-L1160 also require a matching source type, `cargo test -p 
iceberg --lib` fails only `spec::values::tests::test_datum_date_convert_to_int` 
and `spec::values::tests::test_datum_int_convert_to_date` (2355 passed, 2 
failed).
   
   ## Willingness to contribute
   
   I can contribute a fix for this bug independently


-- 
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]

Reply via email to