vinishjail97 commented on code in PR #603:
URL: https://github.com/apache/incubator-xtable/pull/603#discussion_r1896194133


##########
xtable-api/src/main/java/org/apache/xtable/spi/sync/CatalogSync.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.
+ */
+ 
+package org.apache.xtable.spi.sync;
+
+import static 
org.apache.xtable.spi.sync.CatalogUtils.hasStorageDescriptorLocationChanged;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.extern.log4j.Log4j2;
+
+import org.apache.commons.lang3.StringUtils;
+
+import org.apache.xtable.model.InternalTable;
+import org.apache.xtable.model.catalog.CatalogTableIdentifier;
+import org.apache.xtable.model.sync.SyncResult;
+import org.apache.xtable.model.sync.SyncResult.CatalogSyncStatus;
+
+/** Provides the functionality to sync metadata from InternalTable to multiple 
target catalogs */
+@Log4j2
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class CatalogSync {
+  private static final CatalogSync INSTANCE = new CatalogSync();
+
+  public static CatalogSync getInstance() {
+    return INSTANCE;
+  }
+
+  public SyncResult syncTable(
+      Map<CatalogTableIdentifier, CatalogSyncClient> catalogSyncClients, 
InternalTable table) {
+    List<CatalogSyncStatus> results = new ArrayList<>();
+    Instant startTime = Instant.now();
+    catalogSyncClients.forEach(
+        ((tableIdentifier, catalogSyncClient) -> {
+          try {
+            results.add(syncCatalog(catalogSyncClient, tableIdentifier, 
table));
+            log.info(
+                "Catalog sync is successful for table {} with format {} using 
catalogSync {}",
+                table.getBasePath(),
+                table.getTableFormat(),
+                catalogSyncClient.getClass().getName());
+          } catch (Exception e) {
+            log.error(
+                "Catalog sync failed for table {} with format {} using 
catalogSync {}",
+                table.getBasePath(),
+                table.getTableFormat(),
+                catalogSyncClient.getClass().getName());
+            results.add(
+                getCatalogSyncFailureStatus(
+                    catalogSyncClient.getCatalogId(), 
catalogSyncClient.getClass().getName(), e));
+          }
+        }));
+    return SyncResult.builder()
+        .lastInstantSynced(table.getLatestCommitTime())
+        .syncStartTime(startTime)
+        .syncDuration(Duration.between(startTime, Instant.now()))
+        .catalogSyncStatusList(results)
+        .build();
+  }
+
+  private <TABLE> CatalogSyncStatus syncCatalog(
+      CatalogSyncClient<TABLE> catalogSyncClient,
+      CatalogTableIdentifier tableIdentifier,
+      InternalTable table) {
+    if (!catalogSyncClient.hasDatabase(tableIdentifier.getDatabaseName())) {
+      catalogSyncClient.createDatabase(tableIdentifier.getDatabaseName());
+    }

Review Comment:
   Using string as tableIdentifier makes these two line more complicated. 



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