hubcio commented on code in PR #2191:
URL: https://github.com/apache/iggy/pull/2191#discussion_r2371896799


##########
core/connectors/sinks/iceberg_sink/src/router.rs:
##########
@@ -0,0 +1,438 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use std::collections::HashMap;
+use std::io::Cursor;
+use std::sync::Arc;
+
+use arrow_json::ReaderBuilder;
+
+use async_trait::async_trait;
+use iceberg::TableIdent;
+use iceberg::arrow::schema_to_arrow_schema;
+use iceberg::spec::{Literal, PrimitiveLiteral, PrimitiveType, Struct, 
StructType};
+use iceberg::table::Table;
+use iceberg::transaction::{ApplyTransactionAction, Transaction};
+use iceberg::writer::base_writer::data_file_writer::DataFileWriterBuilder;
+use iceberg::writer::file_writer::ParquetWriterBuilder;
+use iceberg::writer::{IcebergWriter, IcebergWriterBuilder};
+use iceberg::{
+    Catalog,
+    writer::file_writer::location_generator::{DefaultFileNameGenerator, 
DefaultLocationGenerator},
+};
+use iggy_connector_sdk::{ConsumedMessage, Error, MessagesMetadata, Payload, 
Schema};
+use parquet::file::properties::WriterProperties;
+use simd_json::base::ValueAsObject;
+use tracing::{error, info, warn};
+use uuid::Uuid;
+
+use crate::slice_user_table;
+
+pub fn primitive_type_to_literal(pt: &PrimitiveType) -> 
Result<PrimitiveLiteral, Error> {
+    match pt {
+        PrimitiveType::Boolean => Ok(PrimitiveLiteral::Boolean(false)),
+        PrimitiveType::Int => Ok(PrimitiveLiteral::Int(0)),
+        PrimitiveType::Long => Ok(PrimitiveLiteral::Long(0)),
+        PrimitiveType::Decimal { .. } => Ok(PrimitiveLiteral::Int128(0)),
+        PrimitiveType::Date => Ok(PrimitiveLiteral::Int(0)), // e.g. days 
since epoch
+        PrimitiveType::Time => Ok(PrimitiveLiteral::Long(0)), // microseconds 
since midnight
+        PrimitiveType::Timestamp => Ok(PrimitiveLiteral::Long(0)), // 
microseconds since epoch
+        PrimitiveType::Timestamptz => Ok(PrimitiveLiteral::Long(0)),
+        PrimitiveType::TimestampNs => Ok(PrimitiveLiteral::Long(0)),
+        PrimitiveType::TimestamptzNs => Ok(PrimitiveLiteral::Long(0)),
+        PrimitiveType::String => Ok(PrimitiveLiteral::String(String::new())),
+        PrimitiveType::Uuid => Ok(PrimitiveLiteral::Binary(vec![0; 16])),
+        PrimitiveType::Fixed(len) => Ok(PrimitiveLiteral::Binary(vec![0; *len 
as usize])),
+        PrimitiveType::Binary => Ok(PrimitiveLiteral::Binary(Vec::new())),
+        _ => {
+            error!("Partition type not supported");
+            Err(Error::InvalidConfig)
+        }
+    }
+}
+
+fn get_partition_type_value(default_partition_type: &StructType) -> 
Result<Option<Struct>, Error> {
+    let mut fields: Vec<Option<Literal>> = Vec::new();
+
+    if default_partition_type.fields().is_empty() {
+        return Ok(None);
+    };
+
+    for field in default_partition_type.fields() {
+        let t = field.field_type.as_primitive_type().unwrap();

Review Comment:
   please use expect, avoid unwraps when possible



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

Reply via email to