rdblue commented on a change in pull request #1432:
URL: https://github.com/apache/iceberg/pull/1432#discussion_r485980159



##########
File path: core/src/main/java/org/apache/iceberg/MetadataTableUtils.java
##########
@@ -0,0 +1,68 @@
+/*
+ * Licensed 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;
+
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.exceptions.NoSuchTableException;
+
+public final class MetadataTableUtils {
+  private MetadataTableUtils() {}
+
+  public static boolean isValidMetadataIdentifier(TableIdentifier identifier) {
+    return MetadataTableType.from(identifier.name()) != null &&
+        isValidIdentifier(TableIdentifier.of(identifier.namespace().levels()));
+  }
+
+  private static boolean isValidIdentifier(TableIdentifier tableIdentifier) {
+    // by default allow all identifiers
+    return true;
+  }
+
+  public static Table createMetadataTableInstance(TableOperations 
originTableOps,
+                                                  String fullTableName,
+                                                  MetadataTableType type) {
+    Table baseTableForMetadata = new BaseTable(originTableOps, fullTableName);
+    switch (type) {
+      case ENTRIES:
+        return new ManifestEntriesTable(originTableOps, baseTableForMetadata);
+      case FILES:
+        return new DataFilesTable(originTableOps, baseTableForMetadata);
+      case HISTORY:
+        return new HistoryTable(originTableOps, baseTableForMetadata);
+      case SNAPSHOTS:
+        return new SnapshotsTable(originTableOps, baseTableForMetadata);
+      case MANIFESTS:
+        return new ManifestsTable(originTableOps, baseTableForMetadata);
+      case PARTITIONS:
+        return new PartitionsTable(originTableOps, baseTableForMetadata);
+      case ALL_DATA_FILES:
+        return new AllDataFilesTable(originTableOps, baseTableForMetadata);
+      case ALL_MANIFESTS:
+        return new AllManifestsTable(originTableOps, baseTableForMetadata);
+      case ALL_ENTRIES:
+        return new AllEntriesTable(originTableOps, baseTableForMetadata);
+      default:
+        throw new NoSuchTableException("Unknown metadata table type: %s for 
%s", type, fullTableName);
+    }
+  }
+
+  public static Table createMetadataTableInstance(TableOperations 
originTableOps,
+                                                  TableIdentifier 
originTableIdentifier,
+                                                  MetadataTableType type) {
+    return createMetadataTableInstance(originTableOps,
+        BaseMetastoreCatalog.fullTableName(type.name(), originTableIdentifier),

Review comment:
       I think this is okay, but I agree it is a little strange. We can move it 
to a util class later if we want.




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

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to