You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/08/17 16:25:36 UTC
[GitHub] [spark] jzhuge opened a new pull request, #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
jzhuge opened a new pull request, #37556:
URL: https://github.com/apache/spark/pull/37556
### What changes were proposed in this pull request?
ViewCatalog API described in [SPIP](https://docs.google.com/document/d/1XOxFtloiMuW24iqJ-zJnDzHl2KMxipTjJoxleJFz66A/edit?usp=sharing).
### Why are the changes needed?
First step towards DataSourceV2 view support.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
N/A
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] asfgit closed pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
URL: https://github.com/apache/spark/pull/37556
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014549689
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
Review Comment:
I left them out as they felt more "implementation" then "API". Do they belong to ViewCatalog?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xkrogen commented on pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
xkrogen commented on PR #37556:
URL: https://github.com/apache/spark/pull/37556#issuecomment-1306007707
Current diff LGTM. We've been testing this out internally (including changes from the umbrella PR as well) and with the recent changes I think this PR looks like it should set us up for success with the rest of the feature.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r949539969
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.Experimental;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@Experimental
Review Comment:
Ok with `DeveloperApi` annotation
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1013618805
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String sql();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the SQL text when the view is created.
+ */
+ StructType schema();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
Review Comment:
This is to capture this part in Spark's CREATE VIEW syntax:
```
( { column_alias [ COMMENT column_comment ] } [, ...] )
```
Array columnAliases and columnComments must have the same size.
#28147 does not have it but we need to add them to maintain existing Spark features.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014522636
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String sql();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the SQL text when the view is created.
+ */
+ StructType schema();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
Review Comment:
Pushed a few changes:
- Updated Javadoc for View.schema to indicate aliases applied
- Added `View.queryColumnNames` to store output column names of the query that creates this view
- Renamed `View.sql` to `View.query` because the term "query" is more accurate to describe the SELECT query that creates 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] dongjoon-hyun commented on pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on PR #37556:
URL: https://github.com/apache/spark/pull/37556#issuecomment-1219788085
Thank you for pinging me, @holdenk .
cc @viirya , @sunchao , @huaxingao , @aokolnychyi , @RussellSpitzer
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014506227
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String sql();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the SQL text when the view is created.
+ */
+ StructType schema();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
Review Comment:
No, `schema()` contains the final schema, the same as V1, to reduce confusion. I will update javadoc to clarify.
Thank you and @wmoustafa for calling it out!
For V1, schema stores column aliases. But for V2, we decided to use these metadata fields to capture the entire CREATE VIEW statement instead of relying on `schema` which feels more like "derived":
- sql
- columnAliases
- columnComments
Let me know if this makes sense.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xkrogen commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
xkrogen commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014524565
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String sql();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the SQL text when the view is created.
+ */
+ StructType schema();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
Review Comment:
LGTM. We are capturing some redundant information but I recognize the value in trying to persist everything from the `CREATE VIEW` statement to make things clear and not rely on derived attributes.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] holdenk commented on pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
holdenk commented on PR #37556:
URL: https://github.com/apache/spark/pull/37556#issuecomment-1223246102
Interesting, the failure in `CliSuite` seems like a red-herring (e.g. that text is present), maybe try a re-base + re-run?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014515719
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String sql();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the SQL text when the view is created.
+ */
+ StructType schema();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
Review Comment:
Yeah, for select star, we need something similar to `viewQueryColumnNames`.
If schema is pre-alias, then `schema.fieldNames` can serve the purpose.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014532124
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
+
+ /**
+ * List the views in a namespace from the catalog.
+ * <p>
+ * If the catalog supports tables, this must return identifiers for only views and not tables.
+ *
+ * @param namespace a multi-part namespace
+ * @return an array of Identifiers for views
+ * @throws NoSuchNamespaceException If the namespace does not exist (optional).
+ */
+ Identifier[] listViews(String... namespace) throws NoSuchNamespaceException;
+
+ /**
+ * Load view metadata by {@link Identifier ident} from the catalog.
+ * <p>
+ * If the catalog supports tables and contains a table for the identifier and not a view,
+ * this must throw {@link NoSuchViewException}.
+ *
+ * @param ident a view identifier
+ * @return the view description
+ * @throws NoSuchViewException If the view doesn't exist or is a table
+ */
+ View loadView(Identifier ident) throws NoSuchViewException;
+
+ /**
+ * Invalidate cached view metadata for an {@link Identifier identifier}.
+ * <p>
+ * If the view is already loaded or cached, drop cached data. If the view does not exist or is
+ * not cached, do nothing. Calling this method should not query remote services.
+ *
+ * @param ident a view identifier
+ */
+ default void invalidateView(Identifier ident) {
+ }
+
+ /**
+ * Test whether a view exists using an {@link Identifier identifier} from the catalog.
+ * <p>
+ * If the catalog supports views and contains a view for the identifier and not a table,
+ * this must return false.
+ *
+ * @param ident a view identifier
+ * @return true if the view exists, false otherwise
+ */
+ default boolean viewExists(Identifier ident) {
+ try {
+ return loadView(ident) != null;
+ } catch (NoSuchViewException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Create a view in the catalog.
+ *
+ * @param ident a view identifier
+ * @param sql the SQL text that defines the view
+ * @param currentCatalog the current catalog
+ * @param currentNamespace the current namespace
+ * @param schema the view query output schema
+ * @param columnAliases the column aliases
+ * @param columnComments the column comments
+ * @param properties the view properties
+ * @return the view created
+ * @throws ViewAlreadyExistsException If a view or table already exists for the identifier
+ * @throws NoSuchNamespaceException If the identifier namespace does not exist (optional)
+ */
+ View createView(
+ Identifier ident,
+ String sql,
+ String currentCatalog,
+ String[] currentNamespace,
+ StructType schema,
+ String[] columnAliases,
Review Comment:
How about builder?
```
public interface ViewBuilder {
ViewBuilder withQuery(String query);
ViewBuilder withCurrentCatalog(String defaultCatalog);
ViewBuilder withCurrentNamespace(String[] defaultNamespaces);
ViewBuilder withSchema(StructType schema);
ViewBuilder withQueryColumnNames(String[] queryColumnNames);
ViewBuilder withColumnAliases(String[] columnAliases);
ViewBuilder withColumnComments(String[] columnComments);
ViewBuilder withProperties(Map<String, String> properties);
ViewBuilder withProperty(String key, String value);
View create();
View replace();
View createOrReplace();
}
ViewCatalog {
ViewBuilder buildView(Identifier ident);
}
```
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
+
+ /**
+ * List the views in a namespace from the catalog.
+ * <p>
+ * If the catalog supports tables, this must return identifiers for only views and not tables.
+ *
+ * @param namespace a multi-part namespace
+ * @return an array of Identifiers for views
+ * @throws NoSuchNamespaceException If the namespace does not exist (optional).
+ */
+ Identifier[] listViews(String... namespace) throws NoSuchNamespaceException;
+
+ /**
+ * Load view metadata by {@link Identifier ident} from the catalog.
+ * <p>
+ * If the catalog supports tables and contains a table for the identifier and not a view,
+ * this must throw {@link NoSuchViewException}.
+ *
+ * @param ident a view identifier
+ * @return the view description
+ * @throws NoSuchViewException If the view doesn't exist or is a table
+ */
+ View loadView(Identifier ident) throws NoSuchViewException;
+
+ /**
+ * Invalidate cached view metadata for an {@link Identifier identifier}.
+ * <p>
+ * If the view is already loaded or cached, drop cached data. If the view does not exist or is
+ * not cached, do nothing. Calling this method should not query remote services.
+ *
+ * @param ident a view identifier
+ */
+ default void invalidateView(Identifier ident) {
+ }
+
+ /**
+ * Test whether a view exists using an {@link Identifier identifier} from the catalog.
+ * <p>
+ * If the catalog supports views and contains a view for the identifier and not a table,
+ * this must return false.
+ *
+ * @param ident a view identifier
+ * @return true if the view exists, false otherwise
+ */
+ default boolean viewExists(Identifier ident) {
+ try {
+ return loadView(ident) != null;
+ } catch (NoSuchViewException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Create a view in the catalog.
+ *
+ * @param ident a view identifier
+ * @param sql the SQL text that defines the view
+ * @param currentCatalog the current catalog
+ * @param currentNamespace the current namespace
+ * @param schema the view query output schema
+ * @param columnAliases the column aliases
+ * @param columnComments the column comments
+ * @param properties the view properties
+ * @return the view created
+ * @throws ViewAlreadyExistsException If a view or table already exists for the identifier
+ * @throws NoSuchNamespaceException If the identifier namespace does not exist (optional)
+ */
+ View createView(
+ Identifier ident,
+ String sql,
+ String currentCatalog,
+ String[] currentNamespace,
+ StructType schema,
+ String[] columnAliases,
Review Comment:
Should we create 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #37556:
URL: https://github.com/apache/spark/pull/37556#issuecomment-1304612855
Puzzled by this pyspark test failures. Seems unrelated.
```
[info] compiling 25 Scala sources to /__w/spark/spark/connector/docker-integration-tests/target/scala-2.12/test-classes ...
[error] /__w/spark/spark/sql/hive/src/test/scala/org/apache/spark/sql/HiveCharVarcharTestSuite.scala:49:13: exception during macro expansion:
[error] java.util.MissingResourceException: Can't find bundle for base name org.scalactic.ScalacticBundle, locale en_US
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014686160
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
Review Comment:
Indeed they are similar the table properties. I hoped to expose them with better APIs instead of string constants, but we can follow up (possibly in Builder). So will add them back.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #37556:
URL: https://github.com/apache/spark/pull/37556#issuecomment-1301598157
Looking at error:
```
SparkThrowableSuite.Error classes are correctly formatted
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xkrogen commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
xkrogen commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014522309
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
+
+ /**
+ * List the views in a namespace from the catalog.
+ * <p>
+ * If the catalog supports tables, this must return identifiers for only views and not tables.
+ *
+ * @param namespace a multi-part namespace
+ * @return an array of Identifiers for views
+ * @throws NoSuchNamespaceException If the namespace does not exist (optional).
+ */
+ Identifier[] listViews(String... namespace) throws NoSuchNamespaceException;
+
+ /**
+ * Load view metadata by {@link Identifier ident} from the catalog.
+ * <p>
+ * If the catalog supports tables and contains a table for the identifier and not a view,
+ * this must throw {@link NoSuchViewException}.
+ *
+ * @param ident a view identifier
+ * @return the view description
+ * @throws NoSuchViewException If the view doesn't exist or is a table
+ */
+ View loadView(Identifier ident) throws NoSuchViewException;
+
+ /**
+ * Invalidate cached view metadata for an {@link Identifier identifier}.
+ * <p>
+ * If the view is already loaded or cached, drop cached data. If the view does not exist or is
+ * not cached, do nothing. Calling this method should not query remote services.
+ *
+ * @param ident a view identifier
+ */
+ default void invalidateView(Identifier ident) {
+ }
+
+ /**
+ * Test whether a view exists using an {@link Identifier identifier} from the catalog.
+ * <p>
+ * If the catalog supports views and contains a view for the identifier and not a table,
+ * this must return false.
+ *
+ * @param ident a view identifier
+ * @return true if the view exists, false otherwise
+ */
+ default boolean viewExists(Identifier ident) {
+ try {
+ return loadView(ident) != null;
+ } catch (NoSuchViewException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Create a view in the catalog.
+ *
+ * @param ident a view identifier
+ * @param sql the SQL text that defines the view
+ * @param currentCatalog the current catalog
+ * @param currentNamespace the current namespace
+ * @param schema the view query output schema
+ * @param columnAliases the column aliases
+ * @param columnComments the column comments
+ * @param properties the view properties
+ * @return the view created
+ * @throws ViewAlreadyExistsException If a view or table already exists for the identifier
+ * @throws NoSuchNamespaceException If the identifier namespace does not exist (optional)
+ */
+ View createView(
+ Identifier ident,
+ String sql,
+ String currentCatalog,
+ String[] currentNamespace,
+ StructType schema,
+ String[] columnAliases,
Review Comment:
We need `queryColumnNames` here as well right?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r949538104
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.Experimental;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@Experimental
Review Comment:
The parent PR is #35636
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1028233908
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String query();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the view when the view is created after applying column aliases.
+ */
+ StructType schema();
+
+ /**
+ * The output column names of the query that creates this view.
+ */
+ String[] queryColumnNames();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
+ /**
+ * The view column comments.
+ */
+ String[] columnComments();
+
+ /**
+ * The view properties.
Review Comment:
I don't have a strong opinion, but shall we put everything (except for the query and schema) into view properties with reserved property keys? `TableCatalog` was designed this way.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ljfgem commented on pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
ljfgem commented on PR #37556:
URL: https://github.com/apache/spark/pull/37556#issuecomment-1310850967
Hi @jzhuge @holdenk, can we merge this PR? Or is there any other concerns?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] wmoustafa commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
wmoustafa commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1013611947
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String sql();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the SQL text when the view is created.
+ */
+ StructType schema();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
Review Comment:
Could you please clarify how this method is being used? By checking the umbrella PR, (#28147), it does not look like it is used either.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ljfgem commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
ljfgem commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014550696
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
Review Comment:
I think they belong to `ViewCatalog` since there are similar properties in [TableCatalog](https://github.com/apache/spark/blob/5a71a7f7b5c1762677ddbfe39a7c35d645c25e94/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableCatalog.java#L48)?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014686160
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
Review Comment:
They are similar these table properties. I had hoped to expose them with better APIs instead of string constants, but we can follow up possibly in Builder. So I will add 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] holdenk commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
holdenk commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r949442525
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.Experimental;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@Experimental
Review Comment:
Do we also want to tag Developer here too? (this applies to all the experimental tags since I think this is purely a dev 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014522636
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String sql();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the SQL text when the view is created.
+ */
+ StructType schema();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
Review Comment:
Pushed a few changes:
- Updated Javadoc for View.schema to indicate aliases applied
- Added `View.queryColumnNames` to store output column names
- Renamed `View.sql` to `View.query` because "query" is more accurate to describe the SELECT query for 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014530432
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
+
+ /**
+ * List the views in a namespace from the catalog.
+ * <p>
+ * If the catalog supports tables, this must return identifiers for only views and not tables.
+ *
+ * @param namespace a multi-part namespace
+ * @return an array of Identifiers for views
+ * @throws NoSuchNamespaceException If the namespace does not exist (optional).
+ */
+ Identifier[] listViews(String... namespace) throws NoSuchNamespaceException;
+
+ /**
+ * Load view metadata by {@link Identifier ident} from the catalog.
+ * <p>
+ * If the catalog supports tables and contains a table for the identifier and not a view,
+ * this must throw {@link NoSuchViewException}.
+ *
+ * @param ident a view identifier
+ * @return the view description
+ * @throws NoSuchViewException If the view doesn't exist or is a table
+ */
+ View loadView(Identifier ident) throws NoSuchViewException;
+
+ /**
+ * Invalidate cached view metadata for an {@link Identifier identifier}.
+ * <p>
+ * If the view is already loaded or cached, drop cached data. If the view does not exist or is
+ * not cached, do nothing. Calling this method should not query remote services.
+ *
+ * @param ident a view identifier
+ */
+ default void invalidateView(Identifier ident) {
+ }
+
+ /**
+ * Test whether a view exists using an {@link Identifier identifier} from the catalog.
+ * <p>
+ * If the catalog supports views and contains a view for the identifier and not a table,
+ * this must return false.
+ *
+ * @param ident a view identifier
+ * @return true if the view exists, false otherwise
+ */
+ default boolean viewExists(Identifier ident) {
+ try {
+ return loadView(ident) != null;
+ } catch (NoSuchViewException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Create a view in the catalog.
+ *
+ * @param ident a view identifier
+ * @param sql the SQL text that defines the view
+ * @param currentCatalog the current catalog
+ * @param currentNamespace the current namespace
+ * @param schema the view query output schema
+ * @param columnAliases the column aliases
+ * @param columnComments the column comments
+ * @param properties the view properties
+ * @return the view created
+ * @throws ViewAlreadyExistsException If a view or table already exists for the identifier
+ * @throws NoSuchNamespaceException If the identifier namespace does not exist (optional)
+ */
+ View createView(
+ Identifier ident,
+ String sql,
+ String currentCatalog,
+ String[] currentNamespace,
+ StructType schema,
+ String[] columnAliases,
Review Comment:
I'd hesitate to do so because these have different meanings: one is more like "CreateViewRequest", the other like "ViewMetadata". Using the same interface may cause confusion and evolving one of them in the future.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014523963
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
+
+ /**
+ * List the views in a namespace from the catalog.
+ * <p>
+ * If the catalog supports tables, this must return identifiers for only views and not tables.
+ *
+ * @param namespace a multi-part namespace
+ * @return an array of Identifiers for views
+ * @throws NoSuchNamespaceException If the namespace does not exist (optional).
+ */
+ Identifier[] listViews(String... namespace) throws NoSuchNamespaceException;
+
+ /**
+ * Load view metadata by {@link Identifier ident} from the catalog.
+ * <p>
+ * If the catalog supports tables and contains a table for the identifier and not a view,
+ * this must throw {@link NoSuchViewException}.
+ *
+ * @param ident a view identifier
+ * @return the view description
+ * @throws NoSuchViewException If the view doesn't exist or is a table
+ */
+ View loadView(Identifier ident) throws NoSuchViewException;
+
+ /**
+ * Invalidate cached view metadata for an {@link Identifier identifier}.
+ * <p>
+ * If the view is already loaded or cached, drop cached data. If the view does not exist or is
+ * not cached, do nothing. Calling this method should not query remote services.
+ *
+ * @param ident a view identifier
+ */
+ default void invalidateView(Identifier ident) {
+ }
+
+ /**
+ * Test whether a view exists using an {@link Identifier identifier} from the catalog.
+ * <p>
+ * If the catalog supports views and contains a view for the identifier and not a table,
+ * this must return false.
+ *
+ * @param ident a view identifier
+ * @return true if the view exists, false otherwise
+ */
+ default boolean viewExists(Identifier ident) {
+ try {
+ return loadView(ident) != null;
+ } catch (NoSuchViewException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Create a view in the catalog.
+ *
+ * @param ident a view identifier
+ * @param sql the SQL text that defines the view
+ * @param currentCatalog the current catalog
+ * @param currentNamespace the current namespace
+ * @param schema the view query output schema
+ * @param columnAliases the column aliases
+ * @param columnComments the column comments
+ * @param properties the view properties
+ * @return the view created
+ * @throws ViewAlreadyExistsException If a view or table already exists for the identifier
+ * @throws NoSuchNamespaceException If the identifier namespace does not exist (optional)
+ */
+ View createView(
+ Identifier ident,
+ String sql,
+ String currentCatalog,
+ String[] currentNamespace,
+ StructType schema,
+ String[] columnAliases,
Review Comment:
Should we create 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xkrogen commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
xkrogen commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014524565
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String sql();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the SQL text when the view is created.
+ */
+ StructType schema();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
Review Comment:
LGTM. We are capturing some redundant information but I recognize the value in trying to capture everything from the `CREATE VIEW` statement to make things clear and not rely on derived attributes.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xkrogen commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
xkrogen commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014502881
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String sql();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the SQL text when the view is created.
+ */
+ StructType schema();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
Review Comment:
@jzhuge is the intent that `schema()` contains the _pre-alias_ schema and `columnAliases()` contains the list of aliases, such that you need to combine `schema() + columnAliases()` to get the _post-alias_ schema? This is in contrast to how V1 views work, where `CatalogTable.schema()` contains the _post-alias_ schema and `viewQueryColumnNames` contains the original column names. The plan is constructed by aliasing from the `viewQueryColumnNames` to the names stored in `schema` (see [this code in SessionCatalog](https://github.com/apache/spark/blob/933dc0c42f0caf74aaa077fd4f2c2e7208452b9b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala#L949-L985)).
I don't have a strong opinion about whether it makes more sense for `schema()` to be pre- or post-aliasing, but we need to make this very clear in the interface description. If we go with pre-aliasing, we can convert it to post-alias inside of [V2ViewDescription](https://github.com/apache/spark/pull/28147/files#diff-d0c6f499b30df039d13bf2740c559251ab63ba4cea312e622e23b74fcbb2fcf0) to make it match V1 in the analyzer, reducing implementation complexity by avoiding having to special-case V1 vs V2.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1028346195
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String query();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the view when the view is created after applying column aliases.
+ */
+ StructType schema();
+
+ /**
+ * The output column names of the query that creates this view.
+ */
+ String[] queryColumnNames();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
+ /**
+ * The view column comments.
+ */
+ String[] columnComments();
+
+ /**
+ * The view properties.
Review Comment:
Thanks for the feedback!
The goal is to capture the entire CREATE VIEW syntax in API. Leave the choice to catalog plugin developers on whether to use properties to implement the APIs. I'd expect HMS-backed view catalog implementation will continue to do so the same as the current v1 implementation. On the other hand, view catalog plugins that support more free-form storage formats such as JSON can choose a different approach.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] holdenk commented on pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
holdenk commented on PR #37556:
URL: https://github.com/apache/spark/pull/37556#issuecomment-1317352658
LGTM I'll merge this now to the current dev 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] holdenk commented on pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
holdenk commented on PR #37556:
URL: https://github.com/apache/spark/pull/37556#issuecomment-1301564329
pending CI and any other concerns I plan to merge this on Friday.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #37556:
URL: https://github.com/apache/spark/pull/37556#issuecomment-1306034903
> Looking at error:
>
> ```
> SparkThrowableSuite.Error classes are correctly formatted
> ```
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014532124
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
+
+ /**
+ * List the views in a namespace from the catalog.
+ * <p>
+ * If the catalog supports tables, this must return identifiers for only views and not tables.
+ *
+ * @param namespace a multi-part namespace
+ * @return an array of Identifiers for views
+ * @throws NoSuchNamespaceException If the namespace does not exist (optional).
+ */
+ Identifier[] listViews(String... namespace) throws NoSuchNamespaceException;
+
+ /**
+ * Load view metadata by {@link Identifier ident} from the catalog.
+ * <p>
+ * If the catalog supports tables and contains a table for the identifier and not a view,
+ * this must throw {@link NoSuchViewException}.
+ *
+ * @param ident a view identifier
+ * @return the view description
+ * @throws NoSuchViewException If the view doesn't exist or is a table
+ */
+ View loadView(Identifier ident) throws NoSuchViewException;
+
+ /**
+ * Invalidate cached view metadata for an {@link Identifier identifier}.
+ * <p>
+ * If the view is already loaded or cached, drop cached data. If the view does not exist or is
+ * not cached, do nothing. Calling this method should not query remote services.
+ *
+ * @param ident a view identifier
+ */
+ default void invalidateView(Identifier ident) {
+ }
+
+ /**
+ * Test whether a view exists using an {@link Identifier identifier} from the catalog.
+ * <p>
+ * If the catalog supports views and contains a view for the identifier and not a table,
+ * this must return false.
+ *
+ * @param ident a view identifier
+ * @return true if the view exists, false otherwise
+ */
+ default boolean viewExists(Identifier ident) {
+ try {
+ return loadView(ident) != null;
+ } catch (NoSuchViewException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Create a view in the catalog.
+ *
+ * @param ident a view identifier
+ * @param sql the SQL text that defines the view
+ * @param currentCatalog the current catalog
+ * @param currentNamespace the current namespace
+ * @param schema the view query output schema
+ * @param columnAliases the column aliases
+ * @param columnComments the column comments
+ * @param properties the view properties
+ * @return the view created
+ * @throws ViewAlreadyExistsException If a view or table already exists for the identifier
+ * @throws NoSuchNamespaceException If the identifier namespace does not exist (optional)
+ */
+ View createView(
+ Identifier ident,
+ String sql,
+ String currentCatalog,
+ String[] currentNamespace,
+ StructType schema,
+ String[] columnAliases,
Review Comment:
How about builder?
```
public interface ViewBuilder {
ViewBuilder withQuery(String query);
ViewBuilder withCurrentCatalog(String defaultCatalog);
ViewBuilder withCurrentNamespace(String[] defaultNamespaces);
ViewBuilder withSchema(StructType schema);
ViewBuilder withQueryColumnNames(String[] queryColumnNames);
ViewBuilder withColumnAliases(String[] columnAliases);
ViewBuilder withColumnComments(String[] columnComments);
ViewBuilder withProperties(Map<String, String> properties);
ViewBuilder withProperty(String key, String value);
View create();
View replace();
View createOrReplace();
}
ViewCatalog {
ViewBuilder buildView(Identifier ident);
}
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #37556:
URL: https://github.com/apache/spark/pull/37556#issuecomment-1219900964
Find this message strange from https://github.com/jzhuge/spark/runs/7886846067?check_suite_focus=true:
```
[info] Found the following changed modules: catalyst, hive-thriftserver
```
This PR does not change module `hive-thriftserver`.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] holdenk commented on pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
holdenk commented on PR #37556:
URL: https://github.com/apache/spark/pull/37556#issuecomment-1219780843
cc @dongjoon-hyun who had comments on the SPIP
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on PR #37556:
URL: https://github.com/apache/spark/pull/37556#issuecomment-1317402205
Thanks @holdenk, @wmoustafa, @xkrogen, @ljfgem for the reviews!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1028233908
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String query();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the view when the view is created after applying column aliases.
+ */
+ StructType schema();
+
+ /**
+ * The output column names of the query that creates this view.
+ */
+ String[] queryColumnNames();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
+ /**
+ * The view column comments.
+ */
+ String[] columnComments();
+
+ /**
+ * The view properties.
Review Comment:
I don't have a strong opinion, but shall we put everything into view properties with reserved property keys? `TableCatalog` was designed this way.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xkrogen commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
xkrogen commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1015752773
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
+
+ /**
+ * List the views in a namespace from the catalog.
+ * <p>
+ * If the catalog supports tables, this must return identifiers for only views and not tables.
+ *
+ * @param namespace a multi-part namespace
+ * @return an array of Identifiers for views
+ * @throws NoSuchNamespaceException If the namespace does not exist (optional).
+ */
+ Identifier[] listViews(String... namespace) throws NoSuchNamespaceException;
+
+ /**
+ * Load view metadata by {@link Identifier ident} from the catalog.
+ * <p>
+ * If the catalog supports tables and contains a table for the identifier and not a view,
+ * this must throw {@link NoSuchViewException}.
+ *
+ * @param ident a view identifier
+ * @return the view description
+ * @throws NoSuchViewException If the view doesn't exist or is a table
+ */
+ View loadView(Identifier ident) throws NoSuchViewException;
+
+ /**
+ * Invalidate cached view metadata for an {@link Identifier identifier}.
+ * <p>
+ * If the view is already loaded or cached, drop cached data. If the view does not exist or is
+ * not cached, do nothing. Calling this method should not query remote services.
+ *
+ * @param ident a view identifier
+ */
+ default void invalidateView(Identifier ident) {
+ }
+
+ /**
+ * Test whether a view exists using an {@link Identifier identifier} from the catalog.
+ * <p>
+ * If the catalog supports views and contains a view for the identifier and not a table,
+ * this must return false.
+ *
+ * @param ident a view identifier
+ * @return true if the view exists, false otherwise
+ */
+ default boolean viewExists(Identifier ident) {
+ try {
+ return loadView(ident) != null;
+ } catch (NoSuchViewException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Create a view in the catalog.
+ *
+ * @param ident a view identifier
+ * @param sql the SQL text that defines the view
+ * @param currentCatalog the current catalog
+ * @param currentNamespace the current namespace
+ * @param schema the view query output schema
+ * @param columnAliases the column aliases
+ * @param columnComments the column comments
+ * @param properties the view properties
+ * @return the view created
+ * @throws ViewAlreadyExistsException If a view or table already exists for the identifier
+ * @throws NoSuchNamespaceException If the identifier namespace does not exist (optional)
+ */
+ View createView(
+ Identifier ident,
+ String sql,
+ String currentCatalog,
+ String[] currentNamespace,
+ StructType schema,
+ String[] columnAliases,
Review Comment:
Fair point. I don't have an opinion here about builder vs. leaving 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xkrogen commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
xkrogen commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014507922
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String sql();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the SQL text when the view is created.
+ */
+ StructType schema();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
Review Comment:
If both `columnAliases` and `schema` contain the final output names (post-alias), then where are the original column names stored? We need those to reconstruct the aliasing similar to the code I linked from `SessionCatalog`. Each element of the projection looks like `Alias(UpCast(<originalColName>, <outputDataType>), <alias>)`, which cannot be constructed without access to the original column names.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] xkrogen commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
xkrogen commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014526120
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
+
+ /**
+ * List the views in a namespace from the catalog.
+ * <p>
+ * If the catalog supports tables, this must return identifiers for only views and not tables.
+ *
+ * @param namespace a multi-part namespace
+ * @return an array of Identifiers for views
+ * @throws NoSuchNamespaceException If the namespace does not exist (optional).
+ */
+ Identifier[] listViews(String... namespace) throws NoSuchNamespaceException;
+
+ /**
+ * Load view metadata by {@link Identifier ident} from the catalog.
+ * <p>
+ * If the catalog supports tables and contains a table for the identifier and not a view,
+ * this must throw {@link NoSuchViewException}.
+ *
+ * @param ident a view identifier
+ * @return the view description
+ * @throws NoSuchViewException If the view doesn't exist or is a table
+ */
+ View loadView(Identifier ident) throws NoSuchViewException;
+
+ /**
+ * Invalidate cached view metadata for an {@link Identifier identifier}.
+ * <p>
+ * If the view is already loaded or cached, drop cached data. If the view does not exist or is
+ * not cached, do nothing. Calling this method should not query remote services.
+ *
+ * @param ident a view identifier
+ */
+ default void invalidateView(Identifier ident) {
+ }
+
+ /**
+ * Test whether a view exists using an {@link Identifier identifier} from the catalog.
+ * <p>
+ * If the catalog supports views and contains a view for the identifier and not a table,
+ * this must return false.
+ *
+ * @param ident a view identifier
+ * @return true if the view exists, false otherwise
+ */
+ default boolean viewExists(Identifier ident) {
+ try {
+ return loadView(ident) != null;
+ } catch (NoSuchViewException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Create a view in the catalog.
+ *
+ * @param ident a view identifier
+ * @param sql the SQL text that defines the view
+ * @param currentCatalog the current catalog
+ * @param currentNamespace the current namespace
+ * @param schema the view query output schema
+ * @param columnAliases the column aliases
+ * @param columnComments the column comments
+ * @param properties the view properties
+ * @return the view created
+ * @throws ViewAlreadyExistsException If a view or table already exists for the identifier
+ * @throws NoSuchNamespaceException If the identifier namespace does not exist (optional)
+ */
+ View createView(
+ Identifier ident,
+ String sql,
+ String currentCatalog,
+ String[] currentNamespace,
+ StructType schema,
+ String[] columnAliases,
Review Comment:
Actually, should the argument to this just be a `View`...? We are basically passing all of the same information here. `View` doesn't contain any "derived" fields you can only learn after creating the view. Similar to `ViewChange`.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] jzhuge commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
jzhuge commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014522636
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * An interface representing a persisted view.
+ */
+@DeveloperApi
+public interface View {
+ /**
+ * A name to identify this view.
+ */
+ String name();
+
+ /**
+ * The view query SQL text.
+ */
+ String sql();
+
+ /**
+ * The current catalog when the view is created.
+ */
+ String currentCatalog();
+
+ /**
+ * The current namespace when the view is created.
+ */
+ String[] currentNamespace();
+
+ /**
+ * The schema for the SQL text when the view is created.
+ */
+ StructType schema();
+
+ /**
+ * The view column aliases.
+ */
+ String[] columnAliases();
+
Review Comment:
Pushed a few changes:
- Updated Javadoc for View.schema to indicate aliases applied
- Added `View.queryColumnNames` to store output column names, useful for SELECT star queries
- Renamed `View.sql` to `View.query` because "query" is more accurate to describe the SELECT query for 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] ljfgem commented on a diff in pull request #37556: [SPARK-39799][SQL] DataSourceV2: View catalog interface
Posted by GitBox <gi...@apache.org>.
ljfgem commented on code in PR #37556:
URL: https://github.com/apache/spark/pull/37556#discussion_r1014536719
##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * 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.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.DeveloperApi;
+import org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException;
+import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
+import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Catalog methods for working with views.
+ */
+@DeveloperApi
+public interface ViewCatalog extends CatalogPlugin {
Review Comment:
Why do we remove the following preserved properties from the [umbrella PR](https://github.com/apache/spark/pull/35636/files#diff-7094226eb616c14235b9a88fb6d8bc4bef39fa4f9879aa8dc4cfe4d031b720e7)?
```
/**
* A reserved property to specify the description of the view.
*/
String PROP_COMMENT = "comment";
/**
* A reserved property to specify the owner of the view.
*/
String PROP_OWNER = "owner";
/**
* A reserved property to specify the software version used to create the view.
*/
String PROP_CREATE_ENGINE_VERSION = "create_engine_version";
/**
* A reserved property to specify the software version used to change the view.
*/
String PROP_ENGINE_VERSION = "engine_version";
/**
* All reserved properties of the view.
*/
List<String> RESERVED_PROPERTIES = Arrays.asList(
PROP_COMMENT,
PROP_OWNER,
PROP_CREATE_ENGINE_VERSION,
PROP_ENGINE_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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org