kriti-sc commented on code in PR #2889:
URL: https://github.com/apache/iggy/pull/2889#discussion_r3142136391


##########
core/connectors/sinks/delta_sink/src/sink.rs:
##########
@@ -0,0 +1,179 @@
+/* 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 crate::DeltaSink;
+use crate::SinkState;
+use crate::coercions::{coerce, create_coercion_tree};
+use crate::storage::build_storage_options;
+use async_trait::async_trait;
+use deltalake::writer::{DeltaWriter, JsonWriter};
+use iggy_connector_sdk::{
+    ConsumedMessage, Error, MessagesMetadata, Payload, Sink, TopicMetadata,
+    owned_value_to_serde_json,
+};
+use tracing::{debug, error, info};
+
+// TODO: Expose metrics for observability purposes
+
+#[async_trait]
+impl Sink for DeltaSink {
+    async fn open(&mut self) -> Result<(), Error> {
+        info!(
+            "Opening Delta Lake sink connector with ID: {} for table: {}",
+            self.id, self.config.table_uri
+        );
+
+        let table_url = url::Url::parse(&self.config.table_uri).map_err(|e| {
+            error!("Failed to parse table URI '{}': {e}", 
self.config.table_uri);
+            Error::InitError(format!("Invalid table URI: {e}"))
+        })?;
+
+        info!("Parsed table URI: {}", table_url);
+
+        let storage_options = build_storage_options(&self.config).map_err(|e| {
+            error!("Invalid storage configuration: {e}");
+            Error::InitError(format!("Invalid storage configuration: {e}"))
+        })?;
+
+        let table =
+            match deltalake::open_table_with_storage_options(table_url, 
storage_options).await {
+                Ok(table) => table,
+                Err(e) => {
+                    error!("Failed to load Delta table: {e}");
+                    return Err(Error::InitError(format!("Failed to load Delta 
table: {e}")));
+                }
+            };
+
+        let kernel_schema = table
+            .snapshot()
+            .map_err(|e| {
+                error!("Failed to get table snapshot: {e}");
+                Error::InitError(format!("Failed to get table snapshot: {e}"))
+            })?
+            .schema();
+        let coercion_tree = create_coercion_tree(&kernel_schema);

Review Comment:
   This concern, while possible, is a narrow possibility, because JsonWriter 
would also be outdated if the schema changes and therefore new fields would 
just be ignored. This scenario would happen if the coercion tree was stale but 
state.tables got updated with the new schema. 
   
   I have added a TODO to track this issue. 



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