Xuanwo commented on code in PR #42:
URL: https://github.com/apache/iceberg-rust/pull/42#discussion_r1308159187


##########
crates/iceberg/src/error.rs:
##########
@@ -44,6 +44,10 @@ pub enum ErrorKind {
     ///
     /// This error is returned when given iceberg feature is not supported.
     FeatureUnsupported,
+    /// Arrow compute error.
+    ///
+    /// Error returned by compute function in arrow.
+    ArrowCompute,

Review Comment:
   `ArrowCompute` is not an error code that can take actions. How about remove 
it or replace it by an actionable error code.
   
   



##########
crates/iceberg/src/transform/temporal.rs:
##########
@@ -0,0 +1,669 @@
+use super::TransformFunction;
+use crate::{Error, Result};
+use arrow::array::{
+    Array, Date64Array, TimestampMicrosecondArray, TimestampMillisecondArray,
+    TimestampNanosecondArray, TimestampSecondArray,
+};
+use arrow::compute::binary;
+use arrow::datatypes;
+use arrow::datatypes::DataType;
+use arrow::{
+    array::{ArrayRef, Date32Array, Int32Array},
+    compute::{month_dyn, year_dyn},
+};
+use chrono::Datelike;
+use std::sync::Arc;
+
+/// 719163 is the number of days from 0000-01-01 to 1970-01-01
+const EPOCH_DAY_FROM_CE: i32 = 719163;
+const DAY_PER_SECOND: f64 = 0.0000115741;
+const HOUR_PER_SECOND: f64 = 1_f64 / 3600.0;
+
+/// Extract a date or timestamp year, as years from 1970
+pub struct Year;
+
+impl TransformFunction for Year {
+    fn transform(&self, input: ArrayRef) -> Result<ArrayRef> {
+        let array = year_dyn(&input).map_err(|err| {
+            Error::new(
+                crate::ErrorKind::ArrowCompute,

Review Comment:
   `ArrowCompute` is not an error code that can take actions.
   
   The acutal error here is `{name} does not support`: 
https://arrow.apache.org/rust/src/arrow_arith/temporal.rs.html#452. But arrow 
will wrap all compute time error into `ArrowError::Compute`, so there is no 
good way for us to extract them. 
   
   How about using `Unexpected` here? There is no action for our users to take.



##########
crates/iceberg/src/transform/temporal.rs:
##########
@@ -0,0 +1,669 @@
+use super::TransformFunction;
+use crate::{Error, Result};
+use arrow::array::{
+    Array, Date64Array, TimestampMicrosecondArray, TimestampMillisecondArray,
+    TimestampNanosecondArray, TimestampSecondArray,
+};
+use arrow::compute::binary;
+use arrow::datatypes;
+use arrow::datatypes::DataType;
+use arrow::{
+    array::{ArrayRef, Date32Array, Int32Array},
+    compute::{month_dyn, year_dyn},
+};
+use chrono::Datelike;
+use std::sync::Arc;
+
+/// 719163 is the number of days from 0000-01-01 to 1970-01-01
+const EPOCH_DAY_FROM_CE: i32 = 719163;
+const DAY_PER_SECOND: f64 = 0.0000115741;
+const HOUR_PER_SECOND: f64 = 1_f64 / 3600.0;
+
+/// Extract a date or timestamp year, as years from 1970
+pub struct Year;
+
+impl TransformFunction for Year {
+    fn transform(&self, input: ArrayRef) -> Result<ArrayRef> {
+        let array = year_dyn(&input).map_err(|err| {
+            Error::new(
+                crate::ErrorKind::ArrowCompute,
+                format!("error in transformfunction: {}", err),

Review Comment:
   ```suggestion
                   format!("error in transform function: {}", err),
   ```



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to