-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-30214][SQL] A new framework to resolve v2 commands #26847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
a005713
7c45c9b
024ab39
e489e62
9b272b6
85617cd
e33a200
3e37941
7df9407
57c83fc
ccc4702
72c01a9
1a7c800
415de11
6ab2228
56037ff
6675e7f
a42e12e
2c458f0
573a66e
f6e742b
0754656
a868420
5a6aa2a
0b89d3a
a41acc5
de054c7
e0836f6
fc555be
7b4f3e3
9f2159f
70028dd
9d10239
c391212
d20b1b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * 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.catalyst.analysis | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.Attribute | ||
| import org.apache.spark.sql.catalyst.plans.logical.LeafNode | ||
| import org.apache.spark.sql.connector.catalog.SupportsNamespaces | ||
|
|
||
| trait NamespaceNode extends LeafNode { | ||
|
yaooqinn marked this conversation as resolved.
Outdated
|
||
| override def output: Seq[Attribute] = Nil | ||
| def catalog: SupportsNamespaces | ||
| def namespace: Seq[String] | ||
| } | ||
|
|
||
| case class ResolvedNamespace(catalog: SupportsNamespaces, namespace: Seq[String]) | ||
| extends NamespaceNode | ||
|
|
||
| case class UnresolvedNamespace(multipartIdentifier: Seq[String]) extends NamespaceNode { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, we should give nice error message in |
||
| override lazy val resolved: Boolean = false | ||
|
|
||
| override def catalog: SupportsNamespaces = throw new UnresolvedException(this, "catalog") | ||
|
|
||
| override def namespace: Seq[String] = throw new UnresolvedException(this, "namespace") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * 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.catalyst.analysis | ||
|
|
||
| import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.connector.catalog.{CatalogManager, CatalogV2Util, LookupCatalog} | ||
| import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._ | ||
|
|
||
| case class ResolveCatalogsToV2(catalogManager: CatalogManager) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about |
||
| extends Rule[LogicalPlan] with LookupCatalog { | ||
| override def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { | ||
| case UnresolvedNamespace(CatalogAndNamespace(catalog, ns)) => | ||
| ResolvedNamespace(catalog.asNamespaceCatalog, ns) | ||
|
|
||
| case u @ UnresolvedV2Table(CatalogAndIdentifier(catalog, ident)) => | ||
| CatalogV2Util.loadRelation(catalog, ident).map { _ => | ||
| ResolvedV2Table(catalog.asTableCatalog, ident) | ||
| }.getOrElse(u) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * 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.catalyst.analysis | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.Attribute | ||
| import org.apache.spark.sql.catalyst.plans.logical.LeafNode | ||
| import org.apache.spark.sql.connector.catalog.{Identifier, TableCatalog} | ||
|
|
||
| trait TableNode extends LeafNode { | ||
|
yaooqinn marked this conversation as resolved.
Outdated
|
||
| override def output: Seq[Attribute] = Nil | ||
| def catalog: TableCatalog | ||
| def tableIdentifier: Identifier | ||
| } | ||
|
|
||
| case class ResolvedV2Table(catalog: TableCatalog, tableIdentifier: Identifier) | ||
|
yaooqinn marked this conversation as resolved.
Outdated
|
||
| extends TableNode | ||
|
|
||
| case class UnresolvedV2Table(multipartIdentifier: Seq[String]) extends TableNode { | ||
| override lazy val resolved: Boolean = false | ||
|
|
||
| override def catalog: TableCatalog = throw new UnresolvedException(this, "catalog") | ||
|
|
||
| override def tableIdentifier: Identifier = throw new UnresolvedException(this, "tableIdentifier") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,8 @@ import scala.collection.JavaConverters._ | |
| import org.apache.spark.sql.{AnalysisException, Strategy} | ||
| import org.apache.spark.sql.catalyst.expressions.{And, PredicateHelper, SubqueryExpression} | ||
| import org.apache.spark.sql.catalyst.planning.PhysicalOperation | ||
| import org.apache.spark.sql.catalyst.plans.logical.{AlterNamespaceSetProperties, AlterTable, AppendData, CreateNamespace, CreateTableAsSelect, CreateV2Table, DeleteFromTable, DescribeNamespace, DescribeTable, DropNamespace, DropTable, LogicalPlan, OverwriteByExpression, OverwritePartitionsDynamic, RefreshTable, RenameTable, Repartition, ReplaceTable, ReplaceTableAsSelect, SetCatalogAndNamespace, ShowCurrentNamespace, ShowNamespaces, ShowTableProperties, ShowTables} | ||
| import org.apache.spark.sql.connector.catalog.{StagingTableCatalog, TableCapability} | ||
| import org.apache.spark.sql.catalyst.plans.logical.{AlterNamespaceSetProperties, AlterTable, AppendData, CommentOnNamespace, CommentOnTable, CreateNamespace, CreateTableAsSelect, CreateV2Table, DeleteFromTable, DescribeNamespace, DescribeTable, DropNamespace, DropTable, LogicalPlan, OverwriteByExpression, OverwritePartitionsDynamic, RefreshTable, RenameTable, Repartition, ReplaceTable, ReplaceTableAsSelect, SetCatalogAndNamespace, ShowCurrentNamespace, ShowNamespaces, ShowTableProperties, ShowTables} | ||
| import org.apache.spark.sql.connector.catalog.{StagingTableCatalog, SupportsNamespaces, TableCapability, TableCatalog, TableChange} | ||
| import org.apache.spark.sql.connector.read.streaming.{ContinuousStream, MicroBatchStream} | ||
| import org.apache.spark.sql.execution.{FilterExec, ProjectExec, SparkPlan} | ||
| import org.apache.spark.sql.execution.datasources.DataSourceStrategy | ||
|
|
@@ -210,6 +210,16 @@ object DataSourceV2Strategy extends Strategy with PredicateHelper { | |
| case AlterNamespaceSetProperties(catalog, namespace, properties) => | ||
| AlterNamespaceSetPropertiesExec(catalog, namespace, properties) :: Nil | ||
|
|
||
| case CommentOnNamespace(namespace, comment) => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we can match |
||
| AlterNamespaceSetPropertiesExec( | ||
| namespace.catalog, | ||
| namespace.namespace, | ||
| Map(SupportsNamespaces.PROP_COMMENT -> comment)) :: Nil | ||
|
cloud-fan marked this conversation as resolved.
|
||
|
|
||
| case CommentOnTable(table, comment) => | ||
| val changes = TableChange.setProperty(TableCatalog.PROP_COMMENT, comment) | ||
| AlterTableExec(table.catalog, table.tableIdentifier, Seq(changes)) :: Nil | ||
|
|
||
| case CreateNamespace(catalog, namespace, ifNotExists, properties) => | ||
| CreateNamespaceExec(catalog, namespace, ifNotExists, properties) :: Nil | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not related to this PR, but I have seen (database | NAMESPACE) too many times.
Maybe we should have a
and use
namespacedirectly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created #27027 for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! merged