rdblue commented on code in PR #7880:
URL: https://github.com/apache/iceberg/pull/7880#discussion_r1251265337


##########
core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java:
##########
@@ -287,6 +294,69 @@ public List<Namespace> listNamespaces(Namespace namespace) 
throws NoSuchNamespac
   public void close() throws IOException {
     namespaces.clear();
     tables.clear();
+    views.clear();
+  }
+
+  @Override
+  public List<TableIdentifier> listViews(Namespace namespace) {
+    if (!namespaceExists(namespace) && !namespace.isEmpty()) {
+      throw new NoSuchNamespaceException(
+          "Cannot list views for namespace. Namespace does not exist: %s", 
namespace);
+    }
+
+    return views.keySet().stream()
+        .filter(t -> namespace.isEmpty() || t.namespace().equals(namespace))
+        .sorted(Comparator.comparing(TableIdentifier::toString))
+        .collect(Collectors.toList());
+  }
+
+  @Override
+  public View loadView(TableIdentifier identifier) {
+    if (isValidIdentifier(identifier) && views.containsKey(identifier)) {
+      return new BaseView(newViewOps(identifier), fullTableName(name(), 
identifier));
+    }
+
+    throw new NoSuchViewException("Invalid view identifier: %s", identifier);
+  }
+
+  @Override
+  protected InMemoryViewOperations newViewOps(TableIdentifier identifier) {
+    return new InMemoryViewOperations(io, identifier);
+  }
+
+  @Override
+  public boolean dropView(TableIdentifier identifier) {
+    return null != views.remove(identifier);
+  }
+
+  @Override
+  public void renameView(TableIdentifier from, TableIdentifier to) {
+    if (from.equals(to)) {
+      return;
+    }
+
+    if (!namespaceExists(to.namespace())) {
+      throw new NoSuchNamespaceException(
+          "Cannot rename %s to %s. Namespace does not exist: %s", from, to, 
to.namespace());
+    }
+
+    if (!views.containsKey(from)) {
+      throw new NoSuchViewException("Cannot rename %s to %s. View does not 
exist", from, to);
+    }
+
+    if (tables.containsKey(to)) {
+      throw new AlreadyExistsException("Cannot rename %s to %s. Table already 
exists", from, to);
+    }
+
+    if (views.containsKey(to)) {
+      throw new AlreadyExistsException("Cannot rename %s to %s. View already 
exists", from, to);
+    }
+
+    String fromLocation = views.remove(from);
+    Preconditions.checkState(
+        null != fromLocation, "Cannot rename from %s to %s. Source view does 
not exist", from, to);

Review Comment:
   This is already checked above by `views.containsKey(from)`. I think it would 
make more sense to use `get` there and do the null check, then this can be 
skipped. Then the logic here can be:
   
   ```java
   views.put(to, fromView);
   views.remove(from);
   ```



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


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

Reply via email to