pvary commented on code in PR #12774:
URL: https://github.com/apache/iceberg/pull/12774#discussion_r2066022181


##########
data/src/main/java/org/apache/iceberg/data/ObjectModelRegistry.java:
##########
@@ -0,0 +1,224 @@
+/*
+ * 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.iceberg.data;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.common.DynMethods;
+import org.apache.iceberg.encryption.EncryptedOutputFile;
+import org.apache.iceberg.io.AppenderBuilder;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.io.ObjectModel;
+import org.apache.iceberg.io.ReadBuilder;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.relocated.com.google.common.base.Objects;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Registry which provides the available {@link ReadBuilder}s and writer 
builders ({@link
+ * org.apache.iceberg.data.AppenderBuilder}, {@link DataWriterBuilder}, {@link
+ * EqualityDeleteWriterBuilder}, {@link PositionDeleteWriterBuilder}). Based 
on the `file format`
+ * and the requested `object model name` the registry returns the correct 
reader and writer
+ * builders. These builders could be used to generate the readers and writers.
+ *
+ * <p>The available {@link ObjectModel}s are registered by the {@link
+ * #registerObjectModel(ObjectModel)} method. These {@link ObjectModel}s will 
be used to create the
+ * {@link ReadBuilder}s and the {@link AppenderBuilder}s. The former ones are 
returned directly, the
+ * later ones are wrapped in the appropriate writer builder implementations.
+ */
+public final class ObjectModelRegistry {
+  private static final Logger LOG = 
LoggerFactory.getLogger(ObjectModelRegistry.class);
+  // The list of classes which are used for registering the reader and writer 
builders
+  private static final List<String> CLASSES_TO_REGISTER = ImmutableList.of();
+
+  private static final Map<Key, ObjectModel<?>> OBJECT_MODELS = 
Maps.newConcurrentMap();
+
+  /**
+   * Registers a new object model.
+   *
+   * @param objectModel the object model
+   * @throws IllegalArgumentException if an object model for the given {@code 
format} and {@code
+   *     objectModelName} combination already exists
+   */
+  @SuppressWarnings("CatchBlockLogException")
+  public static void registerObjectModel(ObjectModel<?> objectModel) {
+    try {
+      Key key = new Key(objectModel.format(), objectModel.name());
+      if (OBJECT_MODELS.containsKey(key)) {
+        throw new IllegalArgumentException(
+            String.format(
+                "Object model %s clashes with %s. Both serves %s",
+                objectModel.getClass(), OBJECT_MODELS.get(key), key));
+      }
+
+      OBJECT_MODELS.put(key, objectModel);
+    } catch (RuntimeException e) {
+      // failing to register an object model is normal and does not require a 
stack trace
+      LOG.info(
+          "Unable to use register object model {} for data files: {}", 
objectModel, e.getMessage());

Review Comment:
   Fixed. Thx!



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