EdgarModesto23 commented on code in PR #2191: URL: https://github.com/apache/iggy/pull/2191#discussion_r2377311397
########## core/connectors/sinks/iceberg_sink/src/lib.rs: ########## @@ -0,0 +1,249 @@ +/* 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 core::fmt; +use std::collections::HashMap; + +use async_trait::async_trait; + +use iceberg::Catalog; +use iceberg_catalog_glue::{GlueCatalog, GlueCatalogConfig}; +use iceberg_catalog_rest::{RestCatalog, RestCatalogConfig}; +use iggy_connector_sdk::{ + ConsumedMessage, Error, MessagesMetadata, Sink, TopicMetadata, sink_connector, +}; +use serde::{Deserialize, Serialize}; +use tracing::{error, info}; + +use crate::router::{DynamicRouter, Router, StaticRouter}; + +mod router; + +#[derive(Debug, Serialize, Deserialize)] +#[allow(non_camel_case_types)] +pub enum IcebergSinkTypes { + rest, + glue, +} + +#[derive(Debug, Serialize, Deserialize)] +#[allow(non_camel_case_types)] +pub enum IcebergSinkStoreClass { + s3, + fs, + gcs, + azdls, + oss, +} + +impl fmt::Display for IcebergSinkStoreClass { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match self { + IcebergSinkStoreClass::s3 => "s3", + IcebergSinkStoreClass::fs => "fs", + IcebergSinkStoreClass::gcs => "gcs", + IcebergSinkStoreClass::oss => "oss", + IcebergSinkStoreClass::azdls => "azdls", + }; + write!(f, "{}", s) + } +} + +impl fmt::Display for IcebergSinkTypes { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match self { + IcebergSinkTypes::rest => "rest", + IcebergSinkTypes::glue => "glue", + }; + write!(f, "{}", s) + } +} + +sink_connector!(IcebergSink); + +#[derive(Debug)] +pub struct IcebergSink { + id: u32, + config: IcebergSinkConfig, + props: HashMap<String, String>, + router: Option<Box<dyn Router>>, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct IcebergSinkConfig { + pub tables: Vec<String>, + pub catalog_type: IcebergSinkTypes, + pub warehouse: String, + pub uri: String, + pub dynamic_routing: bool, + pub dynamic_route_field: String, + pub store_url: String, + pub store_access_key_id: String, + pub store_secret_access_key: String, + pub store_region: String, + pub store_class: IcebergSinkStoreClass, +} + +fn slice_user_table(table: &str) -> Vec<String> { + table.split('.').map(|s| s.to_string()).collect() +} + +impl IcebergSink { + #[inline(always)] + fn get_props_s3(&self) -> Result<HashMap<String, String>, Error> { + let mut props: HashMap<String, String> = HashMap::new(); + props.insert("s3.region".to_string(), self.config.store_region.clone()); + props.insert( + "s3.access-key-id".to_string(), + self.config.store_access_key_id.clone(), + ); + props.insert( + "s3.secret-access-key".to_string(), + self.config.store_secret_access_key.clone(), + ); + props.insert("s3.endpoint".to_string(), self.config.store_url.clone()); + Ok(props) + } + + pub fn new(id: u32, config: IcebergSinkConfig) -> Self { + let props = HashMap::new(); + let router = None; + + IcebergSink { + id, + config, + router, + props, + } + } + + #[inline(always)] + fn get_rest_catalog(&self) -> RestCatalog { + let catalog_config = RestCatalogConfig::builder() + .uri(self.config.uri.clone()) + .props(self.props.clone()) + .warehouse(self.config.warehouse.clone()) + .build(); + + RestCatalog::new(catalog_config) + } + + //#[inline(always)] Review Comment: This was the original code for having support for hms catalogs but later I commented it out because it's correct afaik but the current build for the i[ceberg-hms catalog is broken](https://docs.rs/crate/iceberg-catalog-hms/0.6.0), so I didn't really knew what to do with it. I'll remove it and add it later on when they fix it if that sounds good. -- 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]
