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 04:03:19 UTC

[GitHub] [iceberg] jzhuge opened a new pull request, #4925: API: Add view interfaces

jzhuge opened a new pull request, #4925:
URL: https://github.com/apache/iceberg/pull/4925

   Co-authored-by: anjalinorwood@gmail.com


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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014765577


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.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.ViewBuilder;
+
+/** A Catalog API for view create, drop, and load operations. */
+public interface ViewCatalog {
+
+  /**
+   * Return the name for this catalog.
+   *
+   * @return this catalog's name
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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;
+    }
+  }
+
+  /**
+   * Instantiate a builder to create or replace a SQL view.

Review Comment:
   should `SQL view` be just `view`?



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1033019371


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();
+
+  /** The default catalog when the view is created. */
+  String defaultCatalog();
+
+  /** The default namespace when the view is created. */
+  Namespace defaultNamespace();
+
+  /**
+   * The output column names of the query that creates this view. The field aliases are not applied.
+   */
+  List<String> queryColumnNames();

Review Comment:
   @jzhuge, I think that we need the schema stored and accessible, and I think that should be the pre-alias schema that is derived from the SQL query.
   
   Storing the pre-alias column names isn't sufficient because engines may choose to validate more than just the top-level columns that are selected. For example, an engine may want to validate that the type of an `id` column is still a bigint and not, for example, a string. The same logic also applies to nested types for evolution.
   
   The most strict validation of a view is to ensure that the SQL currently produces the same schema, or one that can be cast to the same schema.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r996473118


##########
api/src/main/java/org/apache/iceberg/view/SqlViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a {@link View} with only SQL view representation.
+ *
+ * <p>Call {@link ViewCatalog#buildSqlView} to create a new builder.
+ */
+public interface SqlViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  SqlViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view sql.
+   *
+   * @param sql view sql
+   * @return this for method chaining
+   */
+  SqlViewBuilder withSql(String sql);

Review Comment:
   I'd prefer `withQuery` because I think that is more clear that the SQL should be a `SELECT` statement.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r998509103


##########
api/src/main/java/org/apache/iceberg/view/ViewRepresentation.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.view;
+
+import java.util.Locale;
+
+public interface ViewRepresentation {

Review Comment:
   Added interface `SQLViewRepresentation` that extends this interface.



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r975856140


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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,

Review Comment:
   Also I think we'll need to pass in a Schema @jzhuge ? 



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r959050316


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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,

Review Comment:
   +1 definitely need a builder



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


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

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015685367


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();

Review Comment:
   Maybe what we need is an API to add supported dialects to the metadata? It is up to each catalog implementation to add their dialects, and view definitions can be associated with a dialect ID.



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014899413


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();
+
+  /** The default catalog when the view is created. */
+  String defaultCatalog();
+
+  /** The default namespace when the view is created. */
+  Namespace defaultNamespace();

Review Comment:
   similar question, should this just be `namespace()`?



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r887181924


##########
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 line 28



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


[GitHub] [iceberg] nastra commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
nastra commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1143417466

   @jzhuge I think you wanted to link to #4657 here :)


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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890529386


##########
api/src/main/java/org/apache/iceberg/view/ViewUpdateProperties.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.Map;
+import org.apache.iceberg.PendingUpdate;
+
+/**
+ * API for updating view properties.
+ * <p>
+ * Apply returns the updated view properties as a map for validation.
+ * <p>
+ * When committing, these changes will be applied to the current view metadata.
+ * Commit conflicts will be resolved by applying the pending changes to the new view metadata.
+ */
+public interface ViewUpdateProperties extends PendingUpdate<Map<String, String>> {

Review Comment:
   +1, this is the naming convention we follow for UpdateProperties for table properties. I was originally thinking we extend UpdateProperties for this case as well, but it may be better to keep them independent otherwise it ties us into an interface contract we may not 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.

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


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

Posted by GitBox <gi...@apache.org>.
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


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

Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890517868


##########
api/src/main/java/org/apache/iceberg/view/ViewUpdateProperties.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.Map;
+import org.apache.iceberg.PendingUpdate;
+
+/**
+ * API for updating view properties.
+ * <p>
+ * Apply returns the updated view properties as a map for validation.
+ * <p>
+ * When committing, these changes will be applied to the current view metadata.
+ * Commit conflicts will be resolved by applying the pending changes to the new view metadata.
+ */
+public interface ViewUpdateProperties extends PendingUpdate<Map<String, String>> {

Review Comment:
   UpdateViewProperties?



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


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

Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r952926036


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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,

Review Comment:
   Having that `ViewMetadata` encapsulation seems to be against the structure defined in spec overall. Also I think we cannot use the term `ViewMetadata` since that is a term which means the entire view metadata including all versions in the spec: https://github.com/apache/iceberg/blob/master/format/view-spec.md?plain=1#L57
   
   In my opinion, in the long term what we need is a builder here like `Catalog.buildTable(...)`, so something like 
   
   ```
   ViewCatalog.buildView(TableIdentifier.of("db","table"))
     .addRepresentation(SqlViewRepresentation.of("select * from table"))
     .addProperty("key", "val")
     .build()
   ```
   
   But for now this `createView` method should be sufficient



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1242914702

   @danielcweeks @stevenzwu @rdblue Any more comments on the API changes? Would be nice so that we could get to the core implementation.


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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1276912371

   - Since `ViewBuilder` can update properties, do we still need `UpdateViewProperties`?
   - @amogh-jahagirdar Are you ok with using `int` for version id?


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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r991848646


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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(

Review Comment:
   Will do



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990855018


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ *
+ * <p>A version consists of a view metadata file.
+ *
+ * <p>Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+
+  /** Returns this version's id. Version ids are monotonically increasing */
+  long versionId();
+
+  /** Returns this version's parent id or null if there is no parent */
+  Long parentId();

Review Comment:
   What does it mean to have a parent version? If it is just the order in which view versions are created, can't we get that by looking at view with `versionId - 1`?



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990854892


##########
api/src/main/java/org/apache/iceberg/view/ViewHistoryEntry.java:
##########
@@ -0,0 +1,33 @@
+/*
+ * 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.view;
+
+/**
+ * View history entry.
+ *
+ * <p>An entry contains a change to the view state. At the given timestamp, the current version was
+ * set to the given version ID.
+ */
+public interface ViewHistoryEntry {
+  /** Returns the timestamp in milliseconds of the change */
+  long timestampMillis();
+
+  /** Returns ID of the new current version */
+  int versionId();

Review Comment:
   The spec is ambiguous here. I think it's unlikely that a view will have 4 billion versions, so I'd leave it as an int.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r996473331


##########
api/src/main/java/org/apache/iceberg/view/SqlViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a {@link View} with only SQL view representation.
+ *
+ * <p>Call {@link ViewCatalog#buildSqlView} to create a new builder.
+ */
+public interface SqlViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  SqlViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view sql.
+   *
+   * @param sql view sql
+   * @return this for method chaining
+   */
+  SqlViewBuilder withSql(String sql);
+
+  /**
+   * Set the view sql dialect.
+   *
+   * @param dialect view sql dialect
+   * @return this for method chaining
+   */
+  SqlViewBuilder withDialect(String dialect);

Review Comment:
   I think `withSql` and `withDialect` are the only options that are specific to a SQL-defined view. I think that means we should just merge this with `ViewBuilder` and remove the places that pass `ViewRepresentation`. I generally don't think it is very friendly to expose representation like that and require users to figure out how to create one, when we could just build one internally.
   
   We shouldn't expose internal complexity through the API unless it is really needed.



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1283319905

   > How about `ViewMetadataVersion`, `ViewMetadataSnapshot`
   
   Like `ViewMetadataVersion`.
   
   > I am still unclear on whether we could store different dialects for the same definition as one version or multiple dialects (even for the same definition) imply different versions.
   
   Multiple dialects are available at the same time, so in one version.
   
   > 
   > Related, how can a `ViewVersion` return a list of representations?
   
   Each `Version` contains a list of representations. See view spec, section `Versions`.
   
   > 
   > Finally, what in the example you gave instructs building a `SQLViewRepresentation`?
   
   In the created `View`, current version contains a single SQL view representation.
   


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


[GitHub] [iceberg] wmoustafa commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1284470303

   > Not exposed currently. Do you have a use case? What do u need in the API to achieve it?
   
   I do not necessarily have a use case, but was trying to understand the API contracts. It sounds like something that should be either explicitly supported or not supported by the API (i.e., without having to introduce a backward incompatibility in the future to support it), and probably we should show a pathway for this API to be compatible with the spec.
   
   As a follow up, in case both multiple representations could share the same version, and additional representations could end up with a new version, semantically what does a new version mean? Is it an addition to the previous version, or a replacement? For example, if I add the Spark representation in one version and the equivalent Trino representation in another (with different syntax), is it allowed? Should Spark queries start to fail?
   
   > Yes. The current view builder only supports SQLViewRepresentation. For other representations, one idea is to add more withXXX methods. Any suggestion?
   
   Just making sure that `withQuery` is the one that signifies the `SQLViewRepresentation`. It sounded there was another source that it is a SQL view (e.g., the fact that the dialect is Spark). Would be good to find out how to normalize those things (so there are not two independent hints about the same representation).


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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015648978


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();

Review Comment:
   I disagree that we want to define supported dialects. We don't want engine writers to need to come to the Iceberg community and get a new symbol in an enum before storing a view. I don't see much benefit to doing that.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1017042399


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();
+
+  /** The default catalog when the view is created. */
+  String defaultCatalog();
+
+  /** The default namespace when the view is created. */
+  Namespace defaultNamespace();
+
+  /**
+   * The output column names of the query that creates this view. The field aliases are not applied.
+   */
+  List<String> queryColumnNames();

Review Comment:
   Maybe we should keep it simple, at least in the first batch of commits, and evolve the API in follow-ups?
   



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1003621379


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);

Review Comment:
   Added `ViewVersion.sqlViewRepresentation()`.



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014899332


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();
+
+  /** The default catalog when the view is created. */
+  String defaultCatalog();

Review Comment:
   this is a getter. wondering why `default...`? should it just be `catalog()`?



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015781565


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespace.
+   *
+   * @param defaultNamespace view default namespace
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(Namespace defaultNamespace);
+
+  /**
+   * Set the view query column names.
+   *
+   * @param queryColumnNames view query column names
+   * @return this for method chaining
+   */
+  ViewBuilder withQueryColumnNames(List<String> queryColumnNames);
+
+  /**
+   * Set the view field aliases.
+   *
+   * @param fieldAliases view field aliases
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldAliases(List<String> fieldAliases);
+
+  /**
+   * Set the view field comments.
+   *
+   * @param fieldComments view field comments
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldComments(List<String> fieldComments);
+
+  /**
+   * Add key/value properties to the view.
+   *
+   * @param properties key/value properties
+   * @return this for method chaining
+   */
+  ViewBuilder withProperties(Map<String, String> properties);
+
+  /**
+   * Add a key/value property to the view.
+   *
+   * @param key a key
+   * @param value a value
+   * @return this for method chaining
+   */
+  ViewBuilder withProperty(String key, String value);
+
+  /**
+   * Set a location for the view.
+   *
+   * @param location a location
+   * @return this for method chaining
+   */
+  ViewBuilder withLocation(String location);
+
+  /**
+   * Add a SQL {@link View} for a different dialect.
+   *
+   * @param sqlViewRepresentation a SQL view representation
+   * @return this for method chaining
+   * @throws IllegalArgumentException if the dialect is the same as the SQL view being built
+   */
+  ViewBuilder withOtherSQLRepresentation(SQLViewRepresentation sqlViewRepresentation);

Review Comment:
   Needed to add a different dialet. See https://github.com/apache/iceberg/pull/4925#discussion_r1015685367.



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r991712969


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {

Review Comment:
   +1 Ryan's latest suggestion of `ViewDefinition`. It is the most intuitive name so far. I like `View` prefix even though this is under `view` package already. Otherwise, `Definition` is a bit too broad after import.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r997565409


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.view;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+/** SQL definition for a view */
+public class SQLViewRepresentation implements ViewRepresentation {

Review Comment:
   Sounds good



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r996472986


##########
api/src/main/java/org/apache/iceberg/view/SqlViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a {@link View} with only SQL view representation.
+ *
+ * <p>Call {@link ViewCatalog#buildSqlView} to create a new builder.
+ */
+public interface SqlViewBuilder {

Review Comment:
   In Iceberg, we typically keep commonly upper case words as upper case, like `RESTCatalog`. In this case, I think `SQLViewBuilder` would be a better name, although I think we will probably want a single view builder, not one specific to SQL.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990855445


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ *
+ * <p>A version consists of a view metadata file.
+ *
+ * <p>Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+
+  /** Returns this version's id. Version ids are monotonically increasing */
+  long versionId();

Review Comment:
   The type of `version` should be consistent. Probably int?



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990855149


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {

Review Comment:
   I think `ViewVersion` is fine. We could also go with just `Version`, since this is in the `view` package.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990855595


##########
api/src/main/java/org/apache/iceberg/view/ViewRepresentation.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.view;
+
+import java.util.Locale;
+
+public interface ViewRepresentation {
+
+  enum Type {
+    SQL;
+
+    public static Type parse(String typeName) {

Review Comment:
   I think we typically call this `fromString`.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014520008


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespaces.
+   *
+   * @param defaultNamespaces view default namespaces
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(List<String> defaultNamespaces);
+
+  /**
+   * Set the view field aliases.
+   *
+   * @param fieldAliases view field aliases
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldAliases(List<String> fieldAliases);
+
+  /**
+   * Set the view field comments.
+   *
+   * @param fieldComments view field comments
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldComments(List<String> fieldComments);
+
+  /**
+   * Add key/value properties to the view.
+   *
+   * @param properties key/value properties
+   * @return this for method chaining
+   */
+  ViewBuilder withProperties(Map<String, String> properties);
+
+  /**
+   * Add a key/value property to the view.
+   *
+   * @param key a key
+   * @param value a value
+   * @return this for method chaining
+   */
+  ViewBuilder withProperty(String key, String value);
+
+  /**
+   * Set a location for the view.
+   *
+   * @param location a location
+   * @return this for method chaining
+   */
+  ViewBuilder withLocation(String location);
+
+  /**
+   * Add a SQL {@link View} for a different dialect.
+   *
+   * <p>If its dialect is the same as the SQL view being built, {@link IllegalArgumentException}
+   * will be thrown when creating or replacing the view.
+   *
+   * @param sqlViewRepresentation a SQL view representation
+   * @return this for method chaining
+   */
+  ViewBuilder withOtherSQLView(SQLViewRepresentation sqlViewRepresentation);

Review Comment:
   Applied the change



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


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

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015680437


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();

Review Comment:
   I think it is fine to do either: not take a position at all or take a well defined position. There could be a few scenarios where the intended meaning is not achieved. For example:
   * One defines the view SQL using a non-SQL string (e.g., some other DSL), and still leverages `SQLViewReperesentation` for that. Even if this is permitted, it is not clear from the spec if it is okay.
   * The dialect could be the same but not standardized, e.g., dialects such as `spark`, `Spark`, `SparkSQL`, `Spark SQL`.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014897964


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespaces.
+   *
+   * @param defaultNamespaces view default namespaces
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(List<String> defaultNamespaces);

Review Comment:
   Changed to use Namespace class and use singular



##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.view;
+
+import java.util.List;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  String query();
+
+  String dialect();
+
+  String defaultCatalog();
+
+  List<String> defaultNamespace();

Review Comment:
   Changed to use Namespace class and use singular



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


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

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015882452


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();
+
+  /** The default catalog when the view is created. */
+  String defaultCatalog();
+
+  /** The default namespace when the view is created. */
+  Namespace defaultNamespace();
+
+  /**
+   * The output column names of the query that creates this view. The field aliases are not applied.
+   */
+  List<String> queryColumnNames();

Review Comment:
   Also relevant discussion here: https://github.com/apache/iceberg/pull/6134#discussion_r1015129057
   
   I think we should try to avoid thinking in terms what Spark stores in its metadata and try to understand the higher level objective.



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014766892


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespaces.
+   *
+   * @param defaultNamespaces view default namespaces
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(List<String> defaultNamespaces);
+
+  /**
+   * Set the view field aliases.
+   *
+   * @param fieldAliases view field aliases
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldAliases(List<String> fieldAliases);
+
+  /**
+   * Set the view field comments.
+   *
+   * @param fieldComments view field comments
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldComments(List<String> fieldComments);
+
+  /**
+   * Add key/value properties to the view.
+   *
+   * @param properties key/value properties
+   * @return this for method chaining
+   */
+  ViewBuilder withProperties(Map<String, String> properties);
+
+  /**
+   * Add a key/value property to the view.
+   *
+   * @param key a key
+   * @param value a value
+   * @return this for method chaining
+   */
+  ViewBuilder withProperty(String key, String value);
+
+  /**
+   * Set a location for the view.
+   *
+   * @param location a location
+   * @return this for method chaining
+   */
+  ViewBuilder withLocation(String location);
+
+  /**
+   * Add a SQL {@link View} for a different dialect.
+   *
+   * <p>If its dialect is the same as the SQL view being built, {@link IllegalArgumentException}

Review Comment:
   should this be written as `@throws`?



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014766805


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);

Review Comment:
   if this is intended for SQL view/query, should this method be called `withSQLQuery`?



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


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

Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890517700


##########
api/src/main/java/org/apache/iceberg/view/ViewDefinition.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.Schema;
+
+public interface ViewDefinition extends ViewRepresentation {

Review Comment:
   +1, why is `ViewDefinition` not just an implementation of the presentation?



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890765621


##########
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:
   Good point, It just looked odd to me but that could just be my style. Looking at the other exceptions this seems to be the standard , so makes sense to leave it as is! 



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r952928346


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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,

Review Comment:
   Yeah ViewMetadata is reserved for the overall metadata for the view. The list of view representation is part of the "versions" in the view. +1 to the builder idea, it follows existing established patterns in Iceberg



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r953173694


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {

Review Comment:
   To me, `version` only carries the meaning of some version id or number. Just brainstorming some ideas: `ViewPoint` or `PointOfView`?



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r953291593


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {

Review Comment:
   Yeah, version typically means just the numeric id to me. I also thought about `ViewSnapshot`. I think it can get confused with table snapshot. Or if we use git analogy, maybe `ViewCommit`?



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


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

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r999903501


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);

Review Comment:
   If this is supposed to return `SQLViewReperentation`, then it should enforce it somehow?



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r991828199


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {

Review Comment:
   TODO: sounds good, checking the code to be sure.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990854951


##########
api/src/main/java/org/apache/iceberg/view/View.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/** Interface for view definition. */
+public interface View {
+
+  String name();
+
+  /**
+   * Get the current version for this view, or null if there are no versions.
+   *
+   * @return the current view version.
+   */
+  ViewVersion currentVersion();
+
+  /**
+   * Get the versions of this view.
+   *
+   * @return an Iterable of versions of this view.
+   */
+  Iterable<ViewVersion> versions();
+
+  /**
+   * Get a version in this view by ID.
+   *
+   * @param versionId version ID
+   * @return a version, or null if the ID cannot be found
+   */
+  ViewVersion version(long versionId);

Review Comment:
   This should be an `int` to correspond to `ViewHistoryEntry`.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990858575


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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(

Review Comment:
   This method assumes that a view will be replaced using a catalog method, but I'm not sure that's a good idea.
   
   The table builder API exposes `create`, `createTransaction`, `replaceTransaction`, and `createOrReplaceTransaction`. The `Transaction` methods return a Transaction that will create or replace the table when the transaction is committed. I don't think that there are transactions for views, though. It would make little sense to create a view, then update its properties in a transaction rather than create a view with the properties already set.
   
   I could see adding a way to make it easy to create or replace a view, but that's about it.
   
   For me, this question comes down to how we are going to evolve views in the API. `View` exposes `updateProperties` and it makes a lot of sense to me to use the same pattern that we use for tables:
   
   ```java
   view.updateProperties().set("prop", "val").commit();
   
   view.updateDefinition()
       .withSchema(schemaFromSelect)
       .withQuery(selectStatement)
       .withAliases(aliases, docs)
       .withCatalog("prod")
       .withNamespace("db")
       .withDialect("spark-3.3")
       .commit();
   ```
   
   With that, I'd probably just have the view create builder expose a `createOrReplace` method to finish the building.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890746295


##########
api/src/main/java/org/apache/iceberg/view/ViewUpdateProperties.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.Map;
+import org.apache.iceberg.PendingUpdate;
+
+/**
+ * API for updating view properties.
+ * <p>
+ * Apply returns the updated view properties as a map for validation.
+ * <p>
+ * When committing, these changes will be applied to the current view metadata.
+ * Commit conflicts will be resolved by applying the pending changes to the new view metadata.
+ */
+public interface ViewUpdateProperties extends PendingUpdate<Map<String, String>> {

Review Comment:
   `UpdateProperties` has a method `defaultFormat` that does not apply to views.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890746295


##########
api/src/main/java/org/apache/iceberg/view/ViewUpdateProperties.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.Map;
+import org.apache.iceberg.PendingUpdate;
+
+/**
+ * API for updating view properties.
+ * <p>
+ * Apply returns the updated view properties as a map for validation.
+ * <p>
+ * When committing, these changes will be applied to the current view metadata.
+ * Commit conflicts will be resolved by applying the pending changes to the new view metadata.
+ */
+public interface ViewUpdateProperties extends PendingUpdate<Map<String, String>> {

Review Comment:
   Unfortunately `UpdateProperties` has a method `defaultFormat` that does not apply to views.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890744113


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

Review Comment:
   https://github.com/apache/iceberg/pull/3188#discussion_r718985188



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r997568833


##########
api/src/main/java/org/apache/iceberg/view/UpdateViewRepresentations.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.function.Predicate;
+import org.apache.iceberg.PendingUpdate;
+
+/**
+ * API for updating view representations.
+ *
+ * <p>Apply returns the updated view representations as a list for validation.
+ *
+ * <p>When committing, these changes will be applied to the current view metadata. Commit conflicts
+ * will be resolved by applying the pending changes to the new view metadata.
+ */
+public interface UpdateViewRepresentations extends PendingUpdate<List<ViewRepresentation>> {

Review Comment:
   Sounds good. We can add this or something similar when the use cases come up.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1003616023


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);

Review Comment:
   If there are multiple SQL view representations for different dialects, I assume the first/default one (specified in buildView) should be set in this new field.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1033020666


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();
+
+  /** The default catalog when the view is created. */
+  String defaultCatalog();
+
+  /** The default namespace when the view is created. */
+  Namespace defaultNamespace();
+
+  /**
+   * The output column names of the query that creates this view. The field aliases are not applied.
+   */
+  List<String> queryColumnNames();

Review Comment:
   I updated this. Will merge when tests are passing.



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r894943109


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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);
+
+  /**
+   * 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);

Review Comment:
   One thing I wanted to clarify, do you have an example of the behavior what it means to drop data files (I understand removing metadata files) when we purge the view? Sorry it may be a silly question but just wanted to validate my understanding



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015864672


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();

Review Comment:
   > One defines the view SQL using a non-SQL string
   
   I don't think this is allowed. If you create a SQL view then it should contain SQL. In any case, being strict about dialects doesn't help prevent this.
   
   > The dialect could be the same but not standardized
   
   This is a risk, but I think it isn't very likely. We should document the known dialect strings, but we shouldn't switch it to be an enum.



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014765467


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.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.ViewBuilder;
+
+/** A Catalog API for view create, drop, and load operations. */
+public interface ViewCatalog {
+
+  /**
+   * Return the name for this catalog.
+   *
+   * @return this catalog's name
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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

Review Comment:
   nit: table -> view?



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014776310


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.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.ViewBuilder;
+
+/** A Catalog API for view create, drop, and load operations. */
+public interface ViewCatalog {
+
+  /**
+   * Return the name for this catalog.
+   *
+   * @return this catalog's name
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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;
+    }
+  }
+
+  /**
+   * Instantiate a builder to create or replace a SQL view.

Review Comment:
   It is SQL View. `ViewBuilder` create a SQL view primarily.
   
   It can add an additional SQL view for a different dialect using `withOtherSQLRepresentation`.
   
   In the future, we will extend it with another `withNNNN` for a new representation.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015834172


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();
+
+  /** The default catalog when the view is created. */
+  String defaultCatalog();
+
+  /** The default namespace when the view is created. */
+  Namespace defaultNamespace();
+
+  /**
+   * The output column names of the query that creates this view. The field aliases are not applied.
+   */
+  List<String> queryColumnNames();

Review Comment:
   It is tricky. See discussion in Spark PR https://github.com/apache/spark/pull/37556#discussion_r1014506227.
   
   Currently the Spark PR will pass the following fields to v2 view catalog similar to v1 view:
   
   - Post-alias schema
   - Query column names
   
   Of course Iceberg can choose to store pre-alias schema and compute post-alias schema and query column names on the fly:
   
   - during create, Iceberg can compute and store pre-alias schema based on post-alias schema and query column names. Iceberg will not store query column names
   - during usage, Iceberg can compute post-alias schema and query column names on the fly based on stored pre-alias schema and field alias
   
   What approach should we take?
   
   cc @xkrogin @wmoustafa 



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015649887


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();
+
+  /** The default catalog when the view is created. */
+  String defaultCatalog();
+
+  /** The default namespace when the view is created. */
+  Namespace defaultNamespace();
+
+  /**
+   * The output column names of the query that creates this view. The field aliases are not applied.
+   */
+  List<String> queryColumnNames();

Review Comment:
   Why is this not a schema?



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r953170099


##########
api/src/main/java/org/apache/iceberg/view/View.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Interface for view definition.
+ */
+public interface View {
+
+  String name();
+
+  /**
+   * Get the current version for this view, or null if there are no versions.
+   *
+   * @return the current view version.
+   */
+  ViewVersion currentVersion();
+
+  /**
+   * Get the versions of this view.
+   *
+   * @return an Iterable of versions of this view.
+   */
+  Iterable<ViewVersion> versions();
+
+  /**
+   * Get a version in this view by ID.
+   *
+   * @param versionId version ID
+   * @return a version, or null if the ID cannot be found
+   */
+  ViewVersion version(int versionId);
+
+  /**
+   * Get the version history of this table.
+   *
+   * @return a list of {@link ViewHistoryEntry}
+   */
+  List<ViewHistoryEntry> history();
+
+  /**
+   * Return a map of string properties for this view.
+   *
+   * @return this view's properties map
+   */
+  Map<String, String> properties();
+
+  /**
+   * Update view properties and commit the changes.

Review Comment:
   This Javadoc is not very accurate. maybe sth like this.
   
   ```
   Create a new {@link UpdateViewProperties} to update view properties and commit the changes.
   ```



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


[GitHub] [iceberg] jackye1995 commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jackye1995 commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1255328952

   >  Following this line of thought, we should probably also address the question of whether the SQL text should be validated in Iceberg/the API implementation, or validation is left to the enclosing engine. If it is validated in Iceberg/the API implementation, then Iceberg/implementation needs to understand the dialects as well. If it is left to the enclosing engine, there is the risk of passing an invalid view text.
   
   I would vote for leaving to the enclosing engine or translation tool to validate the correctness and semantic equivalence in the initial API implementation.
   
   Imagine in the most manual way, there is a data engineer manually adding 2 representations for Spark and Trino, and the engineer does the manual translation, and the translation might not be perfect but works for their use case. Then the engineer invokes this API to update the Iceberg view spec. We should make sure at least this use case can proceed without issue without Iceberg throwing unnecessary validation exceptions.
   
   We can always introduce features like `CoralValidatedSqlRepresentation` for people who would like to use certain tool, and plugin points in the Iceberg library, such that the integrations could live as plugin packages that don't even need to live in the Iceberg repository.


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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990854697


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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);
+
+  /**
+   * Drop a view and delete all 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 metadata files */);
+  }
+
+  /**
+   * Drop a view; optionally delete metadata files.
+   *
+   * <p>If purge is set to true the implementation should delete all metadata files.
+   *
+   * @param identifier a view identifier
+   * @param purge if true, delete all 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);

Review Comment:
   Why is there a `purge` option here? Is there value to requiring this?
   
   The `purge` option for tables is not very valuable and is in a lot of cases misunderstood. The problem is that it confuses two needs: "clean up resources" and "do this immediately". Cleaning up resources (i.e., metadata and data files) should be done on a schedule determined by the catalog and administrators. That way undrop can be supported. Doing something immediately should be used when it is urgent that the underlying resources are removed for some other reason, like needing to completely remove PII that has leaked.
   
   In the view case, I see no need for `purge` because I doubt there is a case where deleting a view's description or representation must be done immediately.



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


[GitHub] [iceberg] rdblue commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
rdblue commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1272655369

   @jzhuge, I just had a look at this and it's mostly good. I think a few places should be updated though. Can you make the changes? Thanks!


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


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

Posted by GitBox <gi...@apache.org>.
danielcweeks commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r945926168


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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,

Review Comment:
   I find it a little odd that we're exposing the list of representations at this level without a wrapper class.  I just feel like there are a number of cases where we would want encapsulating data/information.  I would suggest adding a `ViewMetadata` as a container for this list. 



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


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

Posted by GitBox <gi...@apache.org>.
danielcweeks commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r945955064


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+  /**
+   * Return this version's ID.
+   *
+   * @return a long ID
+   */
+  int versionId();
+
+  /**
+   * Return this version's parent ID or null.
+   *
+   * @return a long ID for this version's parent, or null if it has no parent
+   */
+  Integer parentId();
+
+  /**
+   * Return this version's timestamp.
+   * <p>
+   * This timestamp is the same as those produced by {@link System#currentTimeMillis()}.
+   *
+   * @return a long timestamp in milliseconds
+   */
+  long timestampMillis();
+
+  /**
+   * Returns the version summary such as the name and genie-id of the operation that created that version of the view

Review Comment:
   You might want to remove references to genie.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r998512447


##########
api/src/main/java/org/apache/iceberg/view/SqlViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a {@link View} with only SQL view representation.
+ *
+ * <p>Call {@link ViewCatalog#buildSqlView} to create a new builder.
+ */
+public interface SqlViewBuilder {

Review Comment:
   Done



##########
api/src/main/java/org/apache/iceberg/view/SqlViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a {@link View} with only SQL view representation.
+ *
+ * <p>Call {@link ViewCatalog#buildSqlView} to create a new builder.
+ */
+public interface SqlViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  SqlViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view sql.
+   *
+   * @param sql view sql
+   * @return this for method chaining
+   */
+  SqlViewBuilder withSql(String sql);

Review Comment:
   Done



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1284428712

   > > Multiple dialects are available at the same time, so in one version.
   > 
   > What is an API example to achieve that?
   
   Not exposed currently. Do you have a use case? What do u need in the API to achieve it?
   
   > 
   > > Each `Version` contains a list of representations. See view spec, section `Versions`.
   > > In the created `View`, current version contains a single SQL view representation.
   > 
   > Could you clarify if the above two statements are consistent? It seems the former implies a version contains a list of representations and the latter indicates a version contains a single representation.
   
   What I meant was the current builder API only supports creating a view view with a single representation, but the view spec and on-disk format does support multiple representations.
   
   > 
   > > > Finally, what in the example you gave instructs building a SQLViewRepresentation?
   > 
   > This question was about how to implement the builder. Will this builder result in creating a `SQLViewRepresentation`? If yes, how would it know it should create a `SQLViewRepresentation` vs something else (e.g., not SQL representation)?
   
   Yes. The current view builder only supports SQLViewRepresentation. For other representations, one idea is to add more `withXXX` methods. Any suggestion?
   
   


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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1003609858


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);

Review Comment:
   Good idea since we always have  at least 1 SQL view representation.



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014766709


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespaces.
+   *
+   * @param defaultNamespaces view default namespaces
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(List<String> defaultNamespaces);

Review Comment:
   similar, should we use `Namespace` class here?



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014766250


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.view;
+
+import java.util.List;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  String query();
+
+  String dialect();
+
+  String defaultCatalog();
+
+  List<String> defaultNamespace();

Review Comment:
   oh. I guess the list is for the namespace hierachy.



##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.view;
+
+import java.util.List;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  String query();
+
+  String dialect();
+
+  String defaultCatalog();
+
+  List<String> defaultNamespace();

Review Comment:
   oh. I guess the list is for the namespace hierarchy.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015709176


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();

Review Comment:
   > Maybe what we need is an API to add supported dialects to the metadata? It is up to each catalog implementation to add their dialects, and view definitions can be associated with a dialect ID.
   
   Already added
   ```java
     /**
      * Add a SQL {@link View} for a different dialect.
      *
      * @param sqlViewRepresentation a SQL view representation
      * @return this for method chaining
      * @throws IllegalArgumentException if the dialect is the same as the SQL view being built
      */
     ViewBuilder withOtherSQLRepresentation(SQLViewRepresentation sqlViewRepresentation);
   ```



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


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

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015762154


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();

Review Comment:
   I was referring to making dialects (not just view representations) a construct in the metadata where people can define and add them, e.g., some catalogs define `SparkSQL, id = 1` and `TrinoSQL, id = 2`, and each view representation references a standardized dialect ID. They are not part of the Iceberg spec, but defining and adding them dynamically is.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015652744


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespace.
+   *
+   * @param defaultNamespace view default namespace
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(Namespace defaultNamespace);
+
+  /**
+   * Set the view query column names.
+   *
+   * @param queryColumnNames view query column names
+   * @return this for method chaining
+   */
+  ViewBuilder withQueryColumnNames(List<String> queryColumnNames);
+
+  /**
+   * Set the view field aliases.
+   *
+   * @param fieldAliases view field aliases
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldAliases(List<String> fieldAliases);
+
+  /**
+   * Set the view field comments.
+   *
+   * @param fieldComments view field comments
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldComments(List<String> fieldComments);
+
+  /**
+   * Add key/value properties to the view.
+   *
+   * @param properties key/value properties
+   * @return this for method chaining
+   */
+  ViewBuilder withProperties(Map<String, String> properties);
+
+  /**
+   * Add a key/value property to the view.
+   *
+   * @param key a key
+   * @param value a value
+   * @return this for method chaining
+   */
+  ViewBuilder withProperty(String key, String value);
+
+  /**
+   * Set a location for the view.
+   *
+   * @param location a location
+   * @return this for method chaining
+   */
+  ViewBuilder withLocation(String location);
+
+  /**
+   * Add a SQL {@link View} for a different dialect.
+   *
+   * @param sqlViewRepresentation a SQL view representation
+   * @return this for method chaining
+   * @throws IllegalArgumentException if the dialect is the same as the SQL view being built
+   */
+  ViewBuilder withOtherSQLRepresentation(SQLViewRepresentation sqlViewRepresentation);

Review Comment:
   Let's remove this. We should not be exposing view representation to callers using this builder yet.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015658211


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ *
+ * <p>A version consists of a view metadata file.
+ *
+ * <p>Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+
+  /** Returns this version's id. Version ids are monotonically increasing */
+  long versionId();
+
+  /** Returns this version's parent id or null if there is no parent */
+  Long parentId();

Review Comment:
   I don't think parent makes sense because each view definition is independent. Maybe history matters, but we have history for that. Let's remove parent ID.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r997577783


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {

Review Comment:
   Unfortunately, "view definition" has different meaning in the spec:
   
   ```
   ##### Original View Definition in SQL
   
   This type of representation stores the original view definition in SQL and its SQL dialect.
   ```



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1017039590


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();
+
+  /** The default catalog when the view is created. */
+  String defaultCatalog();
+
+  /** The default namespace when the view is created. */
+  Namespace defaultNamespace();
+
+  /**
+   * The output column names of the query that creates this view. The field aliases are not applied.
+   */
+  List<String> queryColumnNames();

Review Comment:
   Yeah, lots of complexity comes from
   
   - column alias feature of CREATE VIEW in Spark
   - store column names for SELECT star query



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890745073


##########
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:
   Yeah, I keep this for parity with table catalog.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990854769


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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);
+
+  /**
+   * Drop a view and delete all 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 metadata files */);

Review Comment:
   I don't think there should be a purge option, and I definitely don't think that it should be set to `true` by default. Otherwise, you're instructing the catalog to discard the information that may be needed to un-drop the view later.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990857489


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {

Review Comment:
   What about `Definition`? We can use a version ID for the definition, but call it a "definition".



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r996460853


##########
api/src/main/java/org/apache/iceberg/view/SqlViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a {@link View} with only SQL view representation.
+ *
+ * <p>Call {@link ViewCatalog#buildSqlView} to create a new builder.
+ */
+public interface SqlViewBuilder {

Review Comment:
   there seems some overlap btw `ViewBuilder` and `SqlViewBuilder`. maybe we can extract a base interface.
   
   You can see `Scan`, `IncrementalScan`, `IncrementalAppendScan`, `IncrementalChangelogScan` as an example.



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1277065293

   To create a view with SQL representation:
   
   ```java
   ViewRepresentation sqlViewRepresentation = SQLViewRepresentation.builder()
       .sql("SELECT foo FROM base")
       .dialect("spark")
       .defaultCatalog("prodhive")
       .defaultNamespace(ICollections.singleList("default"))
       .build()
   
   viewCatalog.buildView(ident)
       .withSchema(schema)
       .withRepresentation(sqlViewRepresentation)
       .createOrReplace()
   ```


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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r953177858


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+  /**
+   * Return this version's ID.
+   *
+   * @return a long ID

Review Comment:
   type mismatch: int vs long. same for the parentId below.



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


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

Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r952926036


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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,

Review Comment:
   Having that `ViewMetadata` encapsulation seems to be against the structure defined in spec overall. Also I think we cannot use the term `ViewMetadata` since that is a term which means the entire view metadata including all versions in the spec: https://github.com/apache/iceberg/blob/master/format/view-spec.md?plain=1#L57
   
   In my opinion, in the long term what we need is a builder here like `Catalog.buildTable(...)`, so something like 
   
   ```
   ViewCatalog.buildView(TableIdentifier.of("db","view"))
     .addRepresentation(SqlViewRepresentation.of("select * from table"))
     .addProperty("key", "val")
     .build()
   ```
   
   But for now this `createView` method should be sufficient



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r969515205


##########
api/src/main/java/org/apache/iceberg/view/ViewHistoryEntry.java:
##########
@@ -0,0 +1,33 @@
+/*
+ * 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.view;
+
+/**
+ * View history entry.
+ *
+ * <p>An entry contains a change to the view state. At the given timestamp, the current version was
+ * set to the given version ID.
+ */
+public interface ViewHistoryEntry {
+  /** Returns the timestamp in milliseconds of the change */
+  long timestampMillis();
+
+  /** Returns ID of the new current version */
+  int versionId();

Review Comment:
   I just realized this should also be a long.



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1295507260

   @rdblue @wmoustafa Could you take look at the PR again? Especially `ViewBuilder`.


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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1012482420


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespaces.
+   *
+   * @param defaultNamespaces view default namespaces
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(List<String> defaultNamespaces);
+
+  /**
+   * Set the view field aliases.
+   *
+   * @param fieldAliases view field aliases
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldAliases(List<String> fieldAliases);
+
+  /**
+   * Set the view field comments.
+   *
+   * @param fieldComments view field comments
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldComments(List<String> fieldComments);
+
+  /**
+   * Add key/value properties to the view.
+   *
+   * @param properties key/value properties
+   * @return this for method chaining
+   */
+  ViewBuilder withProperties(Map<String, String> properties);
+
+  /**
+   * Add a key/value property to the view.
+   *
+   * @param key a key
+   * @param value a value
+   * @return this for method chaining
+   */
+  ViewBuilder withProperty(String key, String value);
+
+  /**
+   * Set a location for the view.
+   *
+   * @param location a location
+   * @return this for method chaining
+   */
+  ViewBuilder withLocation(String location);
+
+  /**
+   * Add a SQL {@link View} for a different dialect.
+   *
+   * <p>If its dialect is the same as the SQL view being built, {@link IllegalArgumentException}
+   * will be thrown when creating or replacing the view.
+   *
+   * @param sqlViewRepresentation a SQL view representation
+   * @return this for method chaining
+   */
+  ViewBuilder withOtherSQLView(SQLViewRepresentation sqlViewRepresentation);

Review Comment:
   Thanks @amogh-jahagirdar !
   
   One of these 3 choices :)
   
   - withOtherSQLView
   - withOtherSQLViewRepresentation
   - withOtherSQLRepresentation



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015865455


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespace.
+   *
+   * @param defaultNamespace view default namespace
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(Namespace defaultNamespace);
+
+  /**
+   * Set the view query column names.
+   *
+   * @param queryColumnNames view query column names
+   * @return this for method chaining
+   */
+  ViewBuilder withQueryColumnNames(List<String> queryColumnNames);
+
+  /**
+   * Set the view field aliases.
+   *
+   * @param fieldAliases view field aliases
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldAliases(List<String> fieldAliases);
+
+  /**
+   * Set the view field comments.
+   *
+   * @param fieldComments view field comments
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldComments(List<String> fieldComments);
+
+  /**
+   * Add key/value properties to the view.
+   *
+   * @param properties key/value properties
+   * @return this for method chaining
+   */
+  ViewBuilder withProperties(Map<String, String> properties);
+
+  /**
+   * Add a key/value property to the view.
+   *
+   * @param key a key
+   * @param value a value
+   * @return this for method chaining
+   */
+  ViewBuilder withProperty(String key, String value);
+
+  /**
+   * Set a location for the view.
+   *
+   * @param location a location
+   * @return this for method chaining
+   */
+  ViewBuilder withLocation(String location);
+
+  /**
+   * Add a SQL {@link View} for a different dialect.
+   *
+   * @param sqlViewRepresentation a SQL view representation
+   * @return this for method chaining
+   * @throws IllegalArgumentException if the dialect is the same as the SQL view being built
+   */
+  ViewBuilder withOtherSQLRepresentation(SQLViewRepresentation sqlViewRepresentation);

Review Comment:
   @jzhuge, I still think we should remove this. We don't need to expose multiple representations in the builder yet. And when we do, I'm very, very skeptical that we will do so by passing a `SQLViewRepresentation` object.



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014765966


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.view;
+
+import java.util.List;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  String query();
+
+  String dialect();
+
+  String defaultCatalog();
+
+  List<String> defaultNamespace();

Review Comment:
   if it is singular, return type should be `String`. if return is a `List`, the method name probably should be plural.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r997565588


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+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.ViewBuilder;
+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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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 schema view schema
+   * @param representation a view representation
+   * @param properties a string map of view properties
+   */
+  default View createView(

Review Comment:
   Fine with me



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


[GitHub] [iceberg] danielcweeks commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
danielcweeks commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1215417024

   @jzhuge or @anjalinorwood I feel like I'm missing something in terms of where we actually access the view content / text?  I would think that would live in `ViewRepresentation` or `ViewVersion`?  


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


[GitHub] [iceberg] wmoustafa commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1253381372

   @amogh-jahagirdar very good points. Following this line of thought, we should probably also address the question of whether the SQL text should be validated in Iceberg/the API implementation, or validation is left to the enclosing engine. If it is validated in Iceberg/the API implementation, then Iceberg/implementation needs to understand the dialects as well. If it is left to the enclosing engine, there is the risk of passing an invalid view text. 
   
   Similarly, whether it is responsibility of Iceberg (or the API implementation) to ensure the semantic equivalence of all the representations (and not only the schemas).
   
   Finally, if we assume there is a translation tool, we may consider if it makes sense to store one representation and let the remaining representations be handled by translation, as opposed to letting the caller generate all the representations, which as you indicated, could fall out of sync.
   
   By the way, I believe adding new representations (case #2) should not increment the view version.
   
   To answer your question about Coral schema validation, Coral infers the schema of a view given the view text and base table schemas (see some [test cases](https://github.com/linkedin/coral/blob/ceb8fdfc8c91eb58a0864ca92c22361361f73c3c/coral-schema/src/test/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverterTests.java#L24)). It uses Avro schemas for representing the schemas (due to its rich semantics), but extension to use Iceberg schemas is straightforward.
   


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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890744436


##########
api/src/main/java/org/apache/iceberg/view/ViewDefinition.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.Schema;
+
+public interface ViewDefinition extends ViewRepresentation {

Review Comment:
   Per discussion, I will turn ViewDefinition into an implementation of ViewRepresentation.
   And move it to core.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890747850


##########
api/src/main/java/org/apache/iceberg/view/ViewUpdateProperties.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.Map;
+import org.apache.iceberg.PendingUpdate;
+
+/**
+ * API for updating view properties.
+ * <p>
+ * Apply returns the updated view properties as a map for validation.
+ * <p>
+ * When committing, these changes will be applied to the current view metadata.
+ * Commit conflicts will be resolved by applying the pending changes to the new view metadata.
+ */
+public interface ViewUpdateProperties extends PendingUpdate<Map<String, String>> {

Review Comment:
   Name `ViewUpdateProperties` has the same prefix as `ViewHistoryEntry`, `ViewRepresentation`, and `ViewVersion`.



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


[GitHub] [iceberg] rdblue commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
rdblue commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1337860939

   Merge! Let me know where the implementation PR is and I'll start looking at that!


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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1277059001

   3 ways to update view metadata:
   
   1. `buildView() + create/replace`: create or replace the entire view
   2. `loadView().updateRepresentations + commit`: update representations
   3. `loadView().updateProperties + commit`: update properties


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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1010030683


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);

Review Comment:
   I think this should be fine for now because it for now we will practically always have sql representation. Down the line, if engines use something use a library like Substrait to serialize common plans then this assumption may not hold.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015658926


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ *
+ * <p>A version consists of a view metadata file.
+ *
+ * <p>Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+
+  /** Return this version's id. Version ids are monotonically increasing */
+  int versionId();
+
+  /** Returns this version's parent id or null if there is no parent */
+  int parentId();
+
+  /**
+   * Return this version's timestamp.
+   *
+   * <p>This timestamp is the same as those produced by {@link System#currentTimeMillis()}.
+   *
+   * @return a long timestamp in milliseconds
+   */
+  long timestampMillis();
+
+  /**
+   * Return the version summary such as the name of the operation that created that version of the
+   * view
+   *
+   * @return a version summary
+   */
+  Map<String, String> summary();
+
+  /**
+   * Return the main SQL view representation.
+   *
+   * @return a SQL view representation
+   */
+  SQLViewRepresentation sqlViewRepresentation();

Review Comment:
   Let's remove this. There isn't necessarily a SQL representation.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015658509


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ *
+ * <p>A version consists of a view metadata file.
+ *
+ * <p>Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+
+  /** Return this version's id. Version ids are monotonically increasing */
+  int versionId();
+
+  /** Returns this version's parent id or null if there is no parent */
+  int parentId();

Review Comment:
   Let's remove parent ID. I don't think it makes sense for views.



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


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

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015888620


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();
+
+  /** The default catalog when the view is created. */
+  String defaultCatalog();
+
+  /** The default namespace when the view is created. */
+  Namespace defaultNamespace();
+
+  /**
+   * The output column names of the query that creates this view. The field aliases are not applied.
+   */
+  List<String> queryColumnNames();

Review Comment:
   I think "original" query column names are specifically useful for `SELECT *` queries only, and for full utility they should be accompanied by table names as well to avoid ambiguity. I think we should also decouple the data communicated from an engine to the catalog as part of a `CREATE VIEW` statement, and the what we capture in the View Representation. Having `ViewRepresentation` heavily influenced by `CREATE VIEW` syntax could be the reason for this complexity?
   
   Adding the right tag for Erik @xkrogen.



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1307975405

   > `buildView() + withOtherSQLRepresentation() + replace()` automatically copies existing dialects from previous versions or if we want to preserve them, we need to add them again?
   
   `buildView()` (with no argument) will start from scratch, i.e., we need to add everything again.


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


[GitHub] [iceberg] jackye1995 commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jackye1995 commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1160611225

   @rdblue do you have any additional comment for adding these view APIs?


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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r904660167


##########
api/src/main/java/org/apache/iceberg/view/View.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Interface for view definition.
+ */
+public interface View {

Review Comment:
   I think we would also want to add schema() to this as well. But I think we can tackle that in a follow on PR



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


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

Posted by GitBox <gi...@apache.org>.
nastra commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r886648961


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

Review Comment:
   same question as above re list of representations in the API



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

Review Comment:
   nit: for view -> for views?



##########
api/src/main/java/org/apache/iceberg/view/ViewDefinition.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.Schema;
+
+public interface ViewDefinition extends ViewRepresentation {

Review Comment:
   I'm not sure exactly why we have both `ViewRepresentation` and `ViewDefinition`, could you elaborate here please?



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

Review Comment:
   nit: tableIdentifier -> identifier?



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

Review Comment:
   just curious, what's the rationale for having a list of view representations here?



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890542168


##########
api/src/main/java/org/apache/iceberg/view/ViewDefinition.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.Schema;
+
+public interface ViewDefinition extends ViewRepresentation {

Review Comment:
   Yeah the only difference in implementations is really only in the type and I think that can be encapsulated in separate classes (imo no need for an interface for just one case which only captures the types), so we can just have 1 be an interface (say ViewRepresentation) and then just have SqlViewRepresentation etc which implement that contract



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


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

Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890517282


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

Review Comment:
   I think it's for cross engine compatibility, in case there is a better way to represent the view that more engines can interpret.



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1189310180

   Hi @danielcweeks, could you please take a look and merge if it looks ok?


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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r996461450


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.view;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+/** SQL definition for a view */
+public class SQLViewRepresentation implements ViewRepresentation {

Review Comment:
   should this live in the iceberg-core module? it doesn't seem to be referenced anywhere in the api module.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r996472334


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.view;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+/** SQL definition for a view */
+public class SQLViewRepresentation implements ViewRepresentation {

Review Comment:
   Yes, I think that implementation classes should live in core. We only want to put the interfaces in API.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r991840645


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ *
+ * <p>A version consists of a view metadata file.
+ *
+ * <p>Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+
+  /** Returns this version's id. Version ids are monotonically increasing */
+  long versionId();
+
+  /** Returns this version's parent id or null if there is no parent */
+  Long parentId();

Review Comment:
   You are right. Will we support rollback? If yes, the parent-child relation makes a little bit sense, for maintaining a lineage tree.
   
   However, since nothing is shared between 2 views, "rollback" can be treated as a "replace" with all representations re-computed.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r998506323


##########
api/src/main/java/org/apache/iceberg/view/View.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Interface for view definition.
+ */
+public interface View {

Review Comment:
   Added schema() and schemas(), similar to `Table` interface.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r998513204


##########
api/src/main/java/org/apache/iceberg/view/UpdateViewRepresentations.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.function.Predicate;
+import org.apache.iceberg.PendingUpdate;
+
+/**
+ * API for updating view representations.
+ *
+ * <p>Apply returns the updated view representations as a list for validation.
+ *
+ * <p>When committing, these changes will be applied to the current view metadata. Commit conflicts
+ * will be resolved by applying the pending changes to the new view metadata.
+ */
+public interface UpdateViewRepresentations extends PendingUpdate<List<ViewRepresentation>> {

Review Comment:
   Removed



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1335943584

   @rdblue Please merge.


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


[GitHub] [iceberg] wmoustafa commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1283276352

   > * Interface name `ViewVersion` not ideal, but no good alternative.
   
   How about `ViewMetadataVersion`, `ViewMetadataSnapshot`, or simply `MetadataSnapshot`?
   
   I am still unclear on whether we could store different dialects for the same definition as one version or multiple dialects (even for the same definition) imply different versions.
   
   Related, how can a `ViewVersion` return a list of representations?
   
   Finally, what in the example you gave instructs building a `SQLViewRepresentation`?


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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r952928346


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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,

Review Comment:
   Yeah ViewMetadata is reserved for the overall metadata for the view. The list of view representation is part of the "versions" in the view. +1 to the builder idea



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1232176520

   Merged Amogh's PR, rebased, and applied spotless.


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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r959052594


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {

Review Comment:
   It is not snapshot. We deliberately chose `version` to differentiate from `snapshot`.
   As for `ViewCommit`, unfortunately that is another over-used word :(



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r959053085


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+  /**
+   * Return this version's ID.
+   *
+   * @return a long ID

Review Comment:
   Done



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


[GitHub] [iceberg] wmoustafa commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1283358600

   > 
   > Multiple dialects are available at the same time, so in one version.
   >
   What is an API example to achieve that?
    
   > Each `Version` contains a list of representations. See view spec, section `Versions`. 
   > In the created `View`, current version contains a single SQL view representation.
   
   Could you clarify if the above two statements are consistent? It seems the former implies a version contains a list of representations and the latter indicates a version contains a single representation.
   
   >> Finally, what in the example you gave instructs building a SQLViewRepresentation?
   
   This question was about how to implement the builder. Will this builder result in creating a `SQLViewRepresentation`? If yes, how would it know it is a `SQLViewRepresentation` vs something else (e.g., not SQL representation)?


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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1279902810

   @rdblue Added `buildSqlView` for convenience, so the above example can be shortened as:
   ```java
   viewCatalog.buildSqlView(ident)
       .withSchema(schema)
       .withSql("SELECT foo FROM base")
       .withDialect("spark")
       .withDefaultCatalog("prodhive")
       .withDefaultNamespace(Collections.singleList("default"))
       .withProperty("k1", "v1")
       .withLocation(s3Loc)
       .createOrReplace()
   ```
   
   Should we add this convenience api for common use cases?
   For builder method names, should we use `with` prefix or not? I have examples of both in the existing code.
   


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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1289434209

   @wmoustafa Thanks for the valuable questions and feedbacks. Echo your point that it is confusing to store representations in different view versions.
   
   I'd suggest this API contract:
   
   - Add the main SQL view representation and other dialects in `buildView` API so all are stored in one view version
   - For a new representation down the road, add a new interface and a new `withXXX` in `buildView`
   - No need for something like `View.updateRepresentions()`, as `buildView() + replace()` should be enough


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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r991822977


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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);
+
+  /**
+   * Drop a view and delete all 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 metadata files */);
+  }
+
+  /**
+   * Drop a view; optionally delete metadata files.
+   *
+   * <p>If purge is set to true the implementation should delete all metadata files.
+   *
+   * @param identifier a view identifier
+   * @param purge if true, delete all 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);

Review Comment:
   Will remove



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990853680


##########
api/src/main/java/org/apache/iceberg/view/View.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Interface for view definition.
+ */
+public interface View {

Review Comment:
   I agree. This needs to expose the view schema.



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890542168


##########
api/src/main/java/org/apache/iceberg/view/ViewDefinition.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.Schema;
+
+public interface ViewDefinition extends ViewRepresentation {

Review Comment:
   Yeah the only difference is in the type, so we can just have 1 be an interface (say ViewRepresentation) and then just have SqlViewRepresentation etc which implement that contract



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


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

Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r893802698


##########
api/src/main/java/org/apache/iceberg/view/ViewUpdateProperties.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.Map;
+import org.apache.iceberg.PendingUpdate;
+
+/**
+ * API for updating view properties.
+ * <p>
+ * Apply returns the updated view properties as a map for validation.
+ * <p>
+ * When committing, these changes will be applied to the current view metadata.
+ * Commit conflicts will be resolved by applying the pending changes to the new view metadata.
+ */
+public interface ViewUpdateProperties extends PendingUpdate<Map<String, String>> {

Review Comment:
   I think we are not chasing for 1:1 mapping of methods with `UpdateProperties` here,  `defaultFormat` is just a shortcut of setting `write.format.default`, there could be other view specific shortcuts here.
   
   The reason of my proposed name change is that `ViewHistoryEntry` and`ViewRepresentation` are objects, whereas this class here represents an update action.
   
   For table, we have `UpdateProperties`, `UpdateLocation`, `UpdateSchema`, etc. which reflects the fact that his is an action. That's the reason I think `UpdateViewProperties` seems to be more appropriate.
   
   For the implementation of these actions, in the past we had to find another name, like `SetLocation implements UpdateLocation`, `PropertiesUpdate implements UpdateProperties`, but I think newer implementations are converging to use the convention of `Base<InterfaceName>`, like `BaseReplaceSortOrder`, `BaseRowDelta`.
   
   I would imagine this pair of impl and API to be `BaseUpdateViewProperties` and `UpdateViewProperties`.



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r894943166


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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);
+
+  /**
+   * 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);

Review Comment:
   One thing I wanted to clarify, do you have an example of the behavior what it means to drop data files (I understand removing view metadata files) when we purge the view? Sorry it may be a silly question but just wanted to validate my understanding



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r894942800


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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);
+
+  /**
+   * 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 */);

Review Comment:
   One thing I wanted to clarify, do you have an example of the behavior what it means to drop data files (I understand removing metadata files) when we purge the view? Sorry it may be a silly question but just wanted to validate my understanding 



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r894942800


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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);
+
+  /**
+   * 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 */);

Review Comment:
   One thing I wanted to clarify, do you have an example of the behavior what it means to drop data files when we purge the view? Sorry it may be a silly question but just wanted to validate my understanding 



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r897097566


##########
api/src/main/java/org/apache/iceberg/view/ViewUpdateProperties.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.Map;
+import org.apache.iceberg.PendingUpdate;
+
+/**
+ * API for updating view properties.
+ * <p>
+ * Apply returns the updated view properties as a map for validation.
+ * <p>
+ * When committing, these changes will be applied to the current view metadata.
+ * Commit conflicts will be resolved by applying the pending changes to the new view metadata.
+ */
+public interface ViewUpdateProperties extends PendingUpdate<Map<String, String>> {

Review Comment:
   Sounds good



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r897098418


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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);
+
+  /**
+   * 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);

Review Comment:
   No data file at this point. I will update the javadoc.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014898267


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespaces.
+   *
+   * @param defaultNamespaces view default namespaces
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(List<String> defaultNamespaces);
+
+  /**
+   * Set the view field aliases.
+   *
+   * @param fieldAliases view field aliases
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldAliases(List<String> fieldAliases);
+
+  /**
+   * Set the view field comments.
+   *
+   * @param fieldComments view field comments
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldComments(List<String> fieldComments);
+
+  /**
+   * Add key/value properties to the view.
+   *
+   * @param properties key/value properties
+   * @return this for method chaining
+   */
+  ViewBuilder withProperties(Map<String, String> properties);
+
+  /**
+   * Add a key/value property to the view.
+   *
+   * @param key a key
+   * @param value a value
+   * @return this for method chaining
+   */
+  ViewBuilder withProperty(String key, String value);
+
+  /**
+   * Set a location for the view.
+   *
+   * @param location a location
+   * @return this for method chaining
+   */
+  ViewBuilder withLocation(String location);
+
+  /**
+   * Add a SQL {@link View} for a different dialect.
+   *
+   * <p>If its dialect is the same as the SQL view being built, {@link IllegalArgumentException}

Review Comment:
   Fixed



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


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

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015154082


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ *
+ * <p>A version consists of a view metadata file.
+ *
+ * <p>Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+
+  /** Return this version's id. Version ids are monotonically increasing */
+  int versionId();
+
+  /** Returns this version's parent id or null if there is no parent */
+  int parentId();
+
+  /**
+   * Return this version's timestamp.
+   *
+   * <p>This timestamp is the same as those produced by {@link System#currentTimeMillis()}.
+   *
+   * @return a long timestamp in milliseconds
+   */
+  long timestampMillis();
+
+  /**
+   * Return the version summary such as the name of the operation that created that version of the
+   * view
+   *
+   * @return a version summary
+   */
+  Map<String, String> summary();
+
+  /**
+   * Return the main SQL view representation.
+   *
+   * @return a SQL view representation
+   */
+  SQLViewRepresentation sqlViewRepresentation();
+
+  /**
+   * Return the list of other view representations.
+   *
+   * <p>May contain SQL view representations for other dialects.
+   *
+   * @return the list of view representations
+   */
+  List<ViewRepresentation> representations();

Review Comment:
   `The main SQL view representation` sounds like something new to the spec.



##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();

Review Comment:
   Why would not this method be also common with other representations?



##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();

Review Comment:
   I feel this needs to be an `Enum` and somehow be merged with `Type`. @rdblue, @danielcweeks, @amogh-jahagirdar, thoughts? Further, it is better for the spec to take a position on supported dialects, or not take a position at all, but in this case SQL should not be a special type. Right now the position sounds a bit fuzzy.



##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);

Review Comment:
   My original question was that this builder returns a `View`, and in this discussion, you mentioned that `withQuery()` is the method responsible for the fact that it should return `SQLViewRepresentation`. However, I think this method still does not enforce it in this iteration.



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1307936107

   > > * No need for something like `View.updateRepresentions()`, as `buildView() + replace()` should be enough
   > 
   > Can one replace the current version or an old version by adding a new dialect? Does it result in a new version?
   
   Not supported.
   
   To add a new dialect, `buildView() + withOtherSQLRepresentation() + replace()` 


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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1017221086


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ *
+ * <p>A version consists of a view metadata file.
+ *
+ * <p>Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+
+  /** Return this version's id. Version ids are monotonically increasing */
+  int versionId();
+
+  /** Returns this version's parent id or null if there is no parent */
+  int parentId();

Review Comment:
   I will create a PR to update the view spec.



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1250178504

   Follow up from our discussion in yesterday's sync.
   
   ## Create View Semantics
   
   I think we'll probably need to better define what createView exactly entails. There are 2 cases I can think of that should be handled in createView. 
   
   CreateView can either:
   
   1.) Create a completely new view with an initial set of representations for the view. i.e. the view is not even defined in the catalog 
   
   OR
   
   2.) Add new representation(s) to an existing view if and only if the new representations or sql dialects don't already exist in the current view (if they exist this means that a user must replace the view). This case should still increment the view version. 
   
   This could be a separate API AddViewRepresentation but this puts more work on a caller to identify if a given view representation or dialect already exists in a view which does not seem like the right behavior. 
   
   ## Schema Validation of different representations
   
   There's another issue here for if and how does CreateView validate that the representations all have the expected schema for case 2? Considering a view represents a result of a computation there must be a single schema. Following this, ideally CreateView should validate that the schema is the same for the representations. 
   
   This is challenging considering different representations and SQL dialects. In the long run, I think projects like Coral or Substrait would be used to help perform the schema validation across the different SQL dialects. As an extension, even there could be a Substrait View Representation down the line. 
   
   @wmoustafa @jacques-n Any recommendations on a good way for handling this schema validation within the view format itself? I'm taking a look in Coral and Substrait (apologies if this is a naive question)
   
   For addressing schema validation in the short term, I think in createView API engines should pass in the schema for the dialects. Then createView performs a validation that the passed in schema aligns with the view schema. This could be bypassed by an engine just passing in the view.schema() even though it doesn't actually align with the view definition. So we could 
   
   Happy to get thoughts and suggestions on this! @jzhuge @danielcweek  @jackye1995 
   
   
   
   


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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1221606965

   @danielcweeks I'll let @jzhuge @anjalinorwood confirm but the model at least in my mind is that there is an implementation of ViewRepresentation; for the SQL view representation, this would be SqlViewRepresentation which would expose a sql() method for surfacing the literal text. Down the line there would be other view representation types such as for substrait which would expose the view representation in their own way (serialized plan node for example). 


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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r952928346


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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,

Review Comment:
   Yeah ViewMetadata is reserved for the overall metadata for the view. The list of view reprsentations is part of the "versions" in the view.



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r953294906


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+  /**
+   * Return this version's ID.
+   *
+   * @return a long ID

Review Comment:
   also is version a monotonically increased numbers? if yes, maybe document it in the Javadoc?



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1263841883

   @jzhuge I saw schema was optional in the spec, I see the rationale here https://github.com/apache/iceberg/pull/3188#discussion_r748303084
   
   I think we'll want a separate createView which also accepts schema. 
   I've raised a PR to your branch https://github.com/jzhuge/iceberg/pull/2/files for addressing this and a definition for updateViewRepresentations for adding new representations of new types and replacing existing representations of the same type. The PR also has some other fixes for long versionId in the history entry and doc adjustments.
   
   Let me know what you think! 


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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1260144084

   Thanks @wmoustafa for your thoughts and sorry for the late reply. So here are my thoughts:
   
   > Following this line of thought, we should probably also address the question of whether the SQL text should be validated in Iceberg/the API implementation, or validation is left to the enclosing engine. If it is validated in Iceberg/the API implementation, then Iceberg/implementation needs to understand the dialects as well. If it is left to the enclosing engine, there is the risk of passing an invalid view text.
   
   Yes, after some thought, my thinking is in the long run the Iceberg View format should enforce correctness and semantic equality between the different representations. However, I think for an initial implementation though it suffices to just put it on the engine or translation layer to validate. Later on, validation can be implemented within the View API. 
   
   >By the way, I believe adding new representations (e.g., dialects) of semantically equivalent views (case 2 above) should not increment the view version. Do you agree? It seems this might result in having to distinguish between view representations that only add a dialect and preserve the semantics and view representations that change the semantics.
   
   So view versions in my mind should represent every single change to the view, similar to there's a new table metadata version regardless of if there is a new snapshot or not. Another argument is that view version should only increment for semantic or schema changes in the view (which if i'm not mistaken is what you're suggesting), but I think the mental model would be hard to grasp here when people try and compare with Iceberg table specification.
   
    Also for an initial implementation if we don't have any validation controls, then I think it becomes necessary to increment on any new version representations which are updated, so that people can rollback the view if it's in a state they do not like.
    
    I'm on board with having a separated updateViewRepresentations which has a "merge" like semantic for updating view representations (either replacing existing ones of the same type and dialect OR if non-existing, create the new representation)
    
    Thoughts @jzhuge @danielcweeks ?


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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r991826408


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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,

Review Comment:
   Adding the buildView API.



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1279816980

   Added `ViewBuilder.withLocation` and rebased to master branch.


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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r996472429


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+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.ViewBuilder;
+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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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 schema view schema
+   * @param representation a view representation
+   * @param properties a string map of view properties
+   */
+  default View createView(

Review Comment:
   Do we need this method? What about using just `buildView` instead?



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1001952322


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);

Review Comment:
   > If this is supposed to return `SQLViewReperentation`, then it should enforce it somehow?
   
   `ViewVersion` returns a list of `ViewRepresentation`. How about adding a field explicitly for `SQLViewReperentation`? In this way, we enforce views should have at least SQL view representation. On disk, we can still lump together and store as a JSON array.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015780924


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespace.
+   *
+   * @param defaultNamespace view default namespace
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(Namespace defaultNamespace);
+
+  /**
+   * Set the view query column names.
+   *
+   * @param queryColumnNames view query column names
+   * @return this for method chaining
+   */
+  ViewBuilder withQueryColumnNames(List<String> queryColumnNames);
+
+  /**
+   * Set the view field aliases.
+   *
+   * @param fieldAliases view field aliases
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldAliases(List<String> fieldAliases);
+
+  /**
+   * Set the view field comments.
+   *
+   * @param fieldComments view field comments
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldComments(List<String> fieldComments);
+
+  /**
+   * Add key/value properties to the view.
+   *
+   * @param properties key/value properties
+   * @return this for method chaining
+   */
+  ViewBuilder withProperties(Map<String, String> properties);
+
+  /**
+   * Add a key/value property to the view.
+   *
+   * @param key a key
+   * @param value a value
+   * @return this for method chaining
+   */
+  ViewBuilder withProperty(String key, String value);
+
+  /**
+   * Set a location for the view.
+   *
+   * @param location a location
+   * @return this for method chaining
+   */
+  ViewBuilder withLocation(String location);

Review Comment:
   Not needed. Can add later if necessary.



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


[GitHub] [iceberg] wmoustafa commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1305287086

   > * No need for something like `View.updateRepresentions()`, as `buildView() + replace()` should be enough
   
   Can one replace the current version or an old version by adding a new dialect? Does it result in a new version?


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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015653216


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespace.
+   *
+   * @param defaultNamespace view default namespace
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(Namespace defaultNamespace);
+
+  /**
+   * Set the view query column names.
+   *
+   * @param queryColumnNames view query column names
+   * @return this for method chaining
+   */
+  ViewBuilder withQueryColumnNames(List<String> queryColumnNames);
+
+  /**
+   * Set the view field aliases.
+   *
+   * @param fieldAliases view field aliases
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldAliases(List<String> fieldAliases);
+
+  /**
+   * Set the view field comments.
+   *
+   * @param fieldComments view field comments
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldComments(List<String> fieldComments);
+
+  /**
+   * Add key/value properties to the view.
+   *
+   * @param properties key/value properties
+   * @return this for method chaining
+   */
+  ViewBuilder withProperties(Map<String, String> properties);
+
+  /**
+   * Add a key/value property to the view.
+   *
+   * @param key a key
+   * @param value a value
+   * @return this for method chaining
+   */
+  ViewBuilder withProperty(String key, String value);
+
+  /**
+   * Set a location for the view.
+   *
+   * @param location a location
+   * @return this for method chaining
+   */
+  ViewBuilder withLocation(String location);

Review Comment:
   What does the location control? Do we need to expose this right now?



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1305068781

   Created #6134 to add the missing field `query-column-names` to SQL view representation in the view spec.


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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990856649


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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,

Review Comment:
   > But for now this createView method should be sufficient
   
   I think we should create a builder now so that we can see the whole proposed API, not just part of it. We took the approach of updating `createTable` for different cases for a long time and needed to introduce the builder API because it was getting so annoying to maintain all the methods.
   
   This is missing critical parts of the view spec right now, like schema, and I don't think we can move forward until those are represented.
   
   ```java
   catalog.buildView(identifier, schema)
       .withQuery(selectStatement, dialect)
       .withProperty("key", "value")
       .withProperties(props)
       .withLocation(s3Location)
       .create();
   ```



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r990855695


##########
api/src/main/java/org/apache/iceberg/view/ViewRepresentation.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.view;
+
+import java.util.Locale;
+
+public interface ViewRepresentation {

Review Comment:
   I'd like to see the SQL view representation in this PR. Otherwise it's hard to understand where different pieces of information are coming 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: 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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r998512941


##########
api/src/main/java/org/apache/iceberg/view/SqlViewBuilder.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a {@link View} with only SQL view representation.
+ *
+ * <p>Call {@link ViewCatalog#buildSqlView} to create a new builder.
+ */
+public interface SqlViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  SqlViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view sql.
+   *
+   * @param sql view sql
+   * @return this for method chaining
+   */
+  SqlViewBuilder withSql(String sql);
+
+  /**
+   * Set the view sql dialect.
+   *
+   * @param dialect view sql dialect
+   * @return this for method chaining
+   */
+  SqlViewBuilder withDialect(String dialect);

Review Comment:
   Done



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014766250


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.view;
+
+import java.util.List;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  String query();
+
+  String dialect();
+
+  String defaultCatalog();
+
+  List<String> defaultNamespace();

Review Comment:
   or is the list for the namespace hierarchy?



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014775979


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.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.ViewBuilder;
+
+/** A Catalog API for view create, drop, and load operations. */
+public interface ViewCatalog {
+
+  /**
+   * Return the name for this catalog.
+   *
+   * @return this catalog's name
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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

Review Comment:
   Fixed



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014903529


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();
+
+  /** The default catalog when the view is created. */
+  String defaultCatalog();

Review Comment:
   In a Spark/Presto SQL session, you can run `USE` to set default catalog and namespace, thus the "default".



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


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

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1017235634


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespace.
+   *
+   * @param defaultNamespace view default namespace
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(Namespace defaultNamespace);
+
+  /**
+   * Set the view query column names.
+   *
+   * @param queryColumnNames view query column names
+   * @return this for method chaining
+   */
+  ViewBuilder withQueryColumnNames(List<String> queryColumnNames);
+
+  /**
+   * Set the view field aliases.
+   *
+   * @param fieldAliases view field aliases
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldAliases(List<String> fieldAliases);
+
+  /**
+   * Set the view field comments.
+   *
+   * @param fieldComments view field comments
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldComments(List<String> fieldComments);
+
+  /**
+   * Add key/value properties to the view.
+   *
+   * @param properties key/value properties
+   * @return this for method chaining
+   */
+  ViewBuilder withProperties(Map<String, String> properties);
+
+  /**
+   * Add a key/value property to the view.
+   *
+   * @param key a key
+   * @param value a value
+   * @return this for method chaining
+   */
+  ViewBuilder withProperty(String key, String value);
+
+  /**
+   * Set a location for the view.
+   *
+   * @param location a location
+   * @return this for method chaining
+   */
+  ViewBuilder withLocation(String location);
+
+  /**
+   * Add a SQL {@link View} for a different dialect.
+   *
+   * @param sqlViewRepresentation a SQL view representation
+   * @return this for method chaining
+   * @throws IllegalArgumentException if the dialect is the same as the SQL view being built
+   */
+  ViewBuilder withOtherSQLRepresentation(SQLViewRepresentation sqlViewRepresentation);

Review Comment:
   Relevant discussion here: https://github.com/apache/iceberg/pull/4925#issuecomment-1253381372.



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r997567541


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+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.ViewBuilder;
+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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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 schema view schema
+   * @param representation a view representation
+   * @param properties a string map of view properties
+   */
+  default View createView(
+      TableIdentifier identifier,
+      Schema schema,
+      ViewRepresentation representation,
+      Map<String, String> properties) {
+    return buildView(identifier)
+        .withSchema(schema)
+        .withRepresentation(representation)
+        .withProperties(properties)
+        .create();
+  }
+
+  /**
+   * Instantiate a builder to create or replace a view.
+   *
+   * @param identifier a view identifier
+   * @return a view builder
+   */
+  ViewBuilder buildView(TableIdentifier identifier);
+
+  /**
+   * Instantiate a builder to create or replace a view with only SQL view representation.
+   *
+   * @param identifier a view identifier
+   * @return a view builder
+   */
+  ViewBuilder buildSqlView(TableIdentifier identifier);

Review Comment:
   Totally fine with this approach.
   
   - buildView() + create/replace(): create or replace sql view representation
   - loadView().updateRepresentations() + commit(): update other representations



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1283182848

   @rdblue @danielcweeks @stevenzwu @amogh-jahagirdar @jackye1995 @nastra Please take another look.
   
   Summary of discussions:
   
   - ViewBuilder API focuses on SQL view first. Do not expose vague APIs to manage a list of representations.
   - Interface name `ViewVersion` not ideal, but no good alternative.
   - Version ID type is integer, not long.
   
   Usage example:
   
   ```
   viewCatalog.buildView(ident)
       .withSchema(schema)
       .withQuery("SELECT foo FROM base")
       .withDialect("spark")
       .withDefaultCatalog("prodhive")
       .withDefaultNamespace(Collections.singleList("default"))
       .withProperty("k1", "v1")
       .withLocation(s3Loc)
       .createOrReplace();
   ```


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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r998512215


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+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.ViewBuilder;
+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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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 schema view schema
+   * @param representation a view representation
+   * @param properties a string map of view properties
+   */
+  default View createView(
+      TableIdentifier identifier,
+      Schema schema,
+      ViewRepresentation representation,
+      Map<String, String> properties) {
+    return buildView(identifier)
+        .withSchema(schema)
+        .withRepresentation(representation)
+        .withProperties(properties)
+        .create();
+  }
+
+  /**
+   * Instantiate a builder to create or replace a view.
+   *
+   * @param identifier a view identifier
+   * @return a view builder
+   */
+  ViewBuilder buildView(TableIdentifier identifier);
+
+  /**
+   * Instantiate a builder to create or replace a view with only SQL view representation.
+   *
+   * @param identifier a view identifier
+   * @return a view builder
+   */
+  ViewBuilder buildSqlView(TableIdentifier identifier);

Review Comment:
   Only expose this API now:
   
   - buildView() + create/replace(): create or replace sql view representation



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1215245771

   Hi @danielcweeks, have you got a chance to take a look?


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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015661549


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();
+
+  /** The view query SQL dialect. */
+  String dialect();
+
+  /** The default catalog when the view is created. */
+  String defaultCatalog();
+
+  /** The default namespace when the view is created. */
+  Namespace defaultNamespace();
+
+  /**
+   * The output column names of the query that creates this view. The field aliases are not applied.
+   */
+  List<String> queryColumnNames();

Review Comment:
   Thinking about this more, I think it would make sense if this were a schema ID rather than query column names. Since this is derived from the query by the engine that creates the view, we should keep the full version.
   
   We may also want to simply remove this and add a schema ID to `ViewVersion` since the schema should be consistent across representations.



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1014766250


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.view;
+
+import java.util.List;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  String query();
+
+  String dialect();
+
+  String defaultCatalog();
+
+  List<String> defaultNamespace();

Review Comment:
   or is the list for the namespace hierarchy? Either way, it might be more clear to use `Namespace` class?



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


[GitHub] [iceberg] wmoustafa commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1307939119

   `buildView() + withOtherSQLRepresentation() + replace()` automatically copies existing dialects from previous versions or if we want to preserve them, we need to add them again?


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


[GitHub] [iceberg] rdblue commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
rdblue commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1328358261

   @jzhuge, this looks good to go. Can you rebase and fix tests?


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


[GitHub] [iceberg] rdblue merged pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
rdblue merged PR #4925:
URL: https://github.com/apache/iceberg/pull/4925


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


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

Posted by GitBox <gi...@apache.org>.
jackye1995 commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r952913731


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {
+  /**
+   * Return this version's ID.

Review Comment:
   Can just use `Returns this verion's ID` to avoid both having a message and a `@return` in javadoc. Just a random example: https://github.com/apache/iceberg/blob/master/arrow/src/main/java/org/apache/iceberg/arrow/vectorized/ColumnarBatch.java#L72



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r953208736


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {

Review Comment:
   View Version does contain a version id which identifies the actual version of the view, but I think I get what you mean; the name "version" should be tied to just the numeric id. Some other ideas in my mind is `ViewInstance` or `ViewSnapshot` but maybe snapshot will get confusing, although that is what this really is at least in my mind.



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r953173694


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {

Review Comment:
   To me, `version` only carries the meaning of some version id or number. Just brainstorming some ideas: `ViewPoint`, `ViewPosition`, `ViewCursor`, or `PointOfView`?



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1015647765


##########
api/src/main/java/org/apache/iceberg/view/SQLViewRepresentation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+
+public interface SQLViewRepresentation extends ViewRepresentation {
+
+  @Override
+  default Type type() {
+    return Type.SQL;
+  }
+
+  /** The view query SQL text. */
+  String query();

Review Comment:
   This is the SQL text of the view. Other view representations don't necessarily have a SQL query. I think this is reasonable.



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r1010029138


##########
api/src/main/java/org/apache/iceberg/view/ViewBuilder.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.ViewCatalog;
+
+/**
+ * A builder used to create or replace a SQL {@link View}.
+ *
+ * <p>Call {@link ViewCatalog#buildView} to create a new builder.
+ */
+public interface ViewBuilder {
+  /**
+   * Set the view schema.
+   *
+   * @param schema view schema
+   * @return this for method chaining
+   */
+  ViewBuilder withSchema(Schema schema);
+
+  /**
+   * Set the view query.
+   *
+   * @param query view query
+   * @return this for method chaining
+   */
+  ViewBuilder withQuery(String query);
+
+  /**
+   * Set the view SQL dialect.
+   *
+   * @param dialect view SQL dialect
+   * @return this for method chaining
+   */
+  ViewBuilder withDialect(String dialect);
+
+  /**
+   * Set the view default catalog.
+   *
+   * @param defaultCatalog view default catalog
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultCatalog(String defaultCatalog);
+
+  /**
+   * Set the view default namespaces.
+   *
+   * @param defaultNamespaces view default namespaces
+   * @return this for method chaining
+   */
+  ViewBuilder withDefaultNamespace(List<String> defaultNamespaces);
+
+  /**
+   * Set the view field aliases.
+   *
+   * @param fieldAliases view field aliases
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldAliases(List<String> fieldAliases);
+
+  /**
+   * Set the view field comments.
+   *
+   * @param fieldComments view field comments
+   * @return this for method chaining
+   */
+  ViewBuilder withFieldComments(List<String> fieldComments);
+
+  /**
+   * Add key/value properties to the view.
+   *
+   * @param properties key/value properties
+   * @return this for method chaining
+   */
+  ViewBuilder withProperties(Map<String, String> properties);
+
+  /**
+   * Add a key/value property to the view.
+   *
+   * @param key a key
+   * @param value a value
+   * @return this for method chaining
+   */
+  ViewBuilder withProperty(String key, String value);
+
+  /**
+   * Set a location for the view.
+   *
+   * @param location a location
+   * @return this for method chaining
+   */
+  ViewBuilder withLocation(String location);
+
+  /**
+   * Add a SQL {@link View} for a different dialect.
+   *
+   * <p>If its dialect is the same as the SQL view being built, {@link IllegalArgumentException}
+   * will be thrown when creating or replacing the view.
+   *
+   * @param sqlViewRepresentation a SQL view representation
+   * @return this for method chaining
+   */
+  ViewBuilder withOtherSQLView(SQLViewRepresentation sqlViewRepresentation);

Review Comment:
   Nit: I think this should be called  `withOtherSQLRepresentation` to differentiate that it's another representation and not a "View" in our terms.  



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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r991823367


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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);
+
+  /**
+   * Drop a view and delete all 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 metadata files */);

Review Comment:
   Same action as above.



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


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

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r991712969


##########
api/src/main/java/org/apache/iceberg/view/ViewVersion.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A version of the view at a point in time.
+ * <p>
+ * A version consists of a view metadata file.
+ * <p>
+ * Versions are created by view operations, like Create and Replace.
+ */
+public interface ViewVersion {

Review Comment:
   +1 Ryan's latest suggestion of `ViewDefinition`. It is the most intuitive name so far.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r996472622


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.List;
+import java.util.Map;
+import org.apache.iceberg.Schema;
+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.ViewBuilder;
+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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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 schema view schema
+   * @param representation a view representation
+   * @param properties a string map of view properties
+   */
+  default View createView(
+      TableIdentifier identifier,
+      Schema schema,
+      ViewRepresentation representation,
+      Map<String, String> properties) {
+    return buildView(identifier)
+        .withSchema(schema)
+        .withRepresentation(representation)
+        .withProperties(properties)
+        .create();
+  }
+
+  /**
+   * Instantiate a builder to create or replace a view.
+   *
+   * @param identifier a view identifier
+   * @return a view builder
+   */
+  ViewBuilder buildView(TableIdentifier identifier);
+
+  /**
+   * Instantiate a builder to create or replace a view with only SQL view representation.
+   *
+   * @param identifier a view identifier
+   * @return a view builder
+   */
+  ViewBuilder buildSqlView(TableIdentifier identifier);

Review Comment:
   I would rather have a single `buildView` method that allows you to create a SQL view. There are no other representations right now so we should focus on SQL. Rather than exposing `ViewRepresentation` right now, we can use methods that update the SQL representation, like `withQuery(String)`.



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


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

Posted by GitBox <gi...@apache.org>.
rdblue commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r996473688


##########
api/src/main/java/org/apache/iceberg/view/UpdateViewRepresentations.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.view;
+
+import java.util.List;
+import java.util.function.Predicate;
+import org.apache.iceberg.PendingUpdate;
+
+/**
+ * API for updating view representations.
+ *
+ * <p>Apply returns the updated view representations as a list for validation.
+ *
+ * <p>When committing, these changes will be applied to the current view metadata. Commit conflicts
+ * will be resolved by applying the pending changes to the new view metadata.
+ */
+public interface UpdateViewRepresentations extends PendingUpdate<List<ViewRepresentation>> {

Review Comment:
   I'm not confident that this is how we want to evolve a view. Like I said above, I don't like exposing a big complex object (`ViewRepresentation`) to users.
   
   I'd prefer to start off with just `updateDefinition` or similar that allows replacing the current view version. We can adapt that to add representations implicitly. That update can contain a call to both `withQuery` or a future `withSubstrait` or something that creates parallel representations.



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


[GitHub] [iceberg] wmoustafa commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
wmoustafa commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1253409649

   Should the spec define rules for schema evolution of views across different versions? The implementation should probably enforce them.


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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1171322357

   If no more comment, is it possible to get it merged so that I can move on to the Core PR?


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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r894943166


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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);
+
+  /**
+   * 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);

Review Comment:
   One thing I wanted to clarify, do you have an example of the behavior what it means to drop data files (I understand removing view metadata files) when we purge the view? Sorry it may be a silly question but just wanted to validate my understanding. I'm not sure for views if we can drop any data files since it's effectively a logical table.



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r894943166


##########
api/src/main/java/org/apache/iceberg/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.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.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
+   */
+  String name();
+
+  /**
+   * Return all the identifiers under this namespace.
+   *
+   * @param namespace a namespace
+   * @return a list of identifiers for views
+   * @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 the identifier
+   * @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);
+
+  /**
+   * 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);
+
+  /**
+   * 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);

Review Comment:
   One thing I wanted to clarify, do you have an example of the behavior what it means to drop data files (I understand removing metadata files) when we purge the view? Sorry it may be a silly question but just wanted to validate my understanding



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1143092626

   Split from #4567 


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


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

Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r890745861


##########
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:
   Neither NoSuchTableException nor NoSuchNamespaceException has a newline.
   What do you see this specific style being followed in Iceberg codebase?



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r893812760


##########
api/src/main/java/org/apache/iceberg/view/ViewUpdateProperties.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.Map;
+import org.apache.iceberg.PendingUpdate;
+
+/**
+ * API for updating view properties.
+ * <p>
+ * Apply returns the updated view properties as a map for validation.
+ * <p>
+ * When committing, these changes will be applied to the current view metadata.
+ * Commit conflicts will be resolved by applying the pending changes to the new view metadata.
+ */
+public interface ViewUpdateProperties extends PendingUpdate<Map<String, String>> {

Review Comment:
   Right, I also think the verb "Update" coming first in UpdateViewProperties better indicates that it is an action like UpdateProperties, UpdateSchema and so on and then we can follow the existing pattern for the implementation. 



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


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

Posted by GitBox <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#discussion_r893812760


##########
api/src/main/java/org/apache/iceberg/view/ViewUpdateProperties.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.view;
+
+import java.util.Map;
+import org.apache.iceberg.PendingUpdate;
+
+/**
+ * API for updating view properties.
+ * <p>
+ * Apply returns the updated view properties as a map for validation.
+ * <p>
+ * When committing, these changes will be applied to the current view metadata.
+ * Commit conflicts will be resolved by applying the pending changes to the new view metadata.
+ */
+public interface ViewUpdateProperties extends PendingUpdate<Map<String, String>> {

Review Comment:
   Right, I also think the verb "Update" coming first in UpdateViewProperties better indicates that it is an action like UpdateProperties, UpdateSchema and so on.



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


[GitHub] [iceberg] jzhuge commented on pull request #4925: API: Add view interfaces

Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #4925:
URL: https://github.com/apache/iceberg/pull/4925#issuecomment-1160010168

   Thanks @amogh-jahagirdar.
   
   BTW, I am also ok if we decide to remove `UpdateViewProperties` and just use the existing `UpdateProperties`.


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