You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/06/01 18:35:53 UTC

[GitHub] [iceberg] amogh-jahagirdar commented on a diff in pull request #4925: API: Add view interfaces

amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r887181038


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.catalog;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.exceptions.NoSuchViewException;
+import org.apache.iceberg.exceptions.NotFoundException;
+import org.apache.iceberg.view.View;
+import org.apache.iceberg.view.ViewDefinition;
+import org.apache.iceberg.view.ViewRepresentation;
+
+/**
+ * A Catalog API for view create, drop, and load operations.
+ */
+public interface ViewCatalog {
+
+  /**
+   * Return the name for this catalog.
+   *
+   * @return this catalog's name
+   */
+  default String name() {
+    return toString();
+  }
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for view
+   * @throws NotFoundException if the namespace is not found
+   */
+  List<TableIdentifier> listViews(Namespace namespace);
+
+  /**
+   * Load a view.
+   *
+   * @param identifier a view identifier
+   * @return instance of {@link View} implementation referred by {@code tableIdentifier}
+   * @throws NoSuchViewException if the view does not exist
+   */
+  View loadView(TableIdentifier identifier);
+
+  /**
+   * Check whether view exists.
+   *
+   * @param identifier a view identifier
+   * @return true if the table exists, false otherwise
+   */
+  default boolean viewExists(TableIdentifier identifier) {
+    try {
+      loadView(identifier);
+      return true;
+    } catch (NoSuchViewException e) {
+      return false;
+    }
+  }
+
+  /**
+   * Create a view.
+   *
+   * @param identifier a view identifier
+   * @param representations a list of view representations
+   * @param properties a string map of view properties
+   */
+  View createView(
+      TableIdentifier identifier,
+      List<ViewRepresentation> representations,
+      Map<String, String> properties);
+
+  /**
+   * Create a view with SQL definition.
+   *
+   * @param identifier a view identifier
+   * @param definition a view definition
+   * @param properties a string map of view properties
+   */
+  default View createView(
+      TableIdentifier identifier,
+      ViewDefinition definition,
+      Map<String, String> properties) {
+    return createView(identifier, Collections.singletonList(definition), properties);
+  }
+
+  /**
+   * Replace a view.
+   *
+   * @param identifier a view identifier
+   * @param representations a list of view representations
+   * @param properties a string map of view properties
+   */
+  View replaceView(
+      TableIdentifier identifier,
+      List<ViewRepresentation> representations,
+      Map<String, String> properties);
+
+  /**
+   * Replace a view's SQL definition.
+   *
+   * @param identifier a view identifier
+   * @param definition a view definition
+   * @param properties a string map of view properties
+   */
+  default View replaceView(
+      TableIdentifier identifier,
+      ViewDefinition definition,
+      Map<String, String> properties) {
+    return replaceView(identifier, Collections.singletonList(definition), properties);
+  }
+
+  /**
+   * Drop a view and delete all data and metadata files.
+   *
+   * @param identifier a view identifier
+   * @return true if the view was dropped, false if the view did not exist
+   */
+  default boolean dropView(TableIdentifier identifier) {
+    return dropView(identifier, true /* drop data and metadata files */);
+  }
+
+  /**
+   * Drop a view; optionally delete data and metadata files.
+   * <p>
+   * If purge is set to true the implementation should delete all data and metadata files.
+   *
+   * @param identifier a view identifier
+   * @param purge      if true, delete all data and metadata files in the view
+   * @return true if the view was dropped, false if the view did not exist
+   */
+  boolean dropView(TableIdentifier identifier, boolean purge);
+
+  /**
+   * Rename a view.
+   *
+   * @param from identifier of the view to rename
+   * @param to   new view identifier
+   * @throws NoSuchViewException    if the "from" view does not exist
+   * @throws AlreadyExistsException if the "to" view already exists
+   */
+  void renameView(TableIdentifier from, TableIdentifier to);
+
+  /**
+   * Invalidate cached view metadata from current catalog.
+   * <p>
+   * If the view is already loaded or cached, drop cached data. If the view does not exist or is not cached, do
+   * nothing.
+   *
+   * @param identifier a view identifier
+   */
+  default void invalidateView(TableIdentifier identifier) {

Review Comment:
   I'm still not sure if caching invalidation logic should be a part of this API but I do see that invalidateTable exists in the existing Catalog API. and i see this context https://github.com/apache/iceberg/pull/3837#issuecomment-1007809606 for why it was done this way. 



##########
api/src/main/java/org/apache/iceberg/exceptions/NoSuchViewException.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.exceptions;
+
+import com.google.errorprone.annotations.FormatMethod;
+
+/**
+ * Exception raised when attempting to load a view that does not exist.
+ */
+public class NoSuchViewException extends RuntimeException {
+  @FormatMethod

Review Comment:
   Nit: Newline before this



-- 
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-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org