-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
261 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...xtensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/RewriteViewCommands.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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.SparkSession | ||
import org.apache.spark.sql.catalyst.plans.logical.DropView | ||
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
import org.apache.spark.sql.catalyst.plans.logical.views.DropIcebergView | ||
import org.apache.spark.sql.catalyst.rules.Rule | ||
import org.apache.spark.sql.connector.catalog.CatalogManager | ||
import org.apache.spark.sql.connector.catalog.CatalogPlugin | ||
import org.apache.spark.sql.connector.catalog.LookupCatalog | ||
import org.apache.spark.sql.connector.catalog.ViewCatalog | ||
|
||
/** | ||
* ResolveSessionCatalog exits early for some v2 View commands, | ||
* thus they are pre-substituted here and then handled in ResolveViews | ||
*/ | ||
case class RewriteViewCommands(spark: SparkSession) extends Rule[LogicalPlan] with LookupCatalog { | ||
|
||
protected lazy val catalogManager: CatalogManager = spark.sessionState.catalogManager | ||
|
||
override def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsUp { | ||
case DropView(ResolvedView(resolved), ifExists) => | ||
DropIcebergView(resolved, ifExists) | ||
} | ||
|
||
private def isTempView(nameParts: Seq[String]): Boolean = { | ||
catalogManager.v1SessionCatalog.isTempView(nameParts) | ||
} | ||
|
||
private def isViewCatalog(catalog: CatalogPlugin): Boolean = { | ||
catalog.isInstanceOf[ViewCatalog] | ||
} | ||
|
||
object ResolvedView { | ||
def unapply(unresolved: UnresolvedIdentifier): Option[ResolvedIdentifier] = unresolved match { | ||
case UnresolvedIdentifier(nameParts, true) if isTempView(nameParts) => | ||
None | ||
|
||
case UnresolvedIdentifier(CatalogAndIdentifier(catalog, ident), _) if isViewCatalog(catalog) => | ||
Some(ResolvedIdentifier(catalog, ident)) | ||
|
||
case _ => | ||
None | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ns/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/views/DropIcebergView.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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.plans.logical.views | ||
|
||
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
import org.apache.spark.sql.catalyst.plans.logical.UnaryCommand | ||
|
||
case class DropIcebergView( | ||
child: LogicalPlan, | ||
ifExists: Boolean) extends UnaryCommand { | ||
override protected def withNewChildInternal(newChild: LogicalPlan): DropIcebergView = | ||
copy(child = newChild) | ||
} |
48 changes: 48 additions & 0 deletions
48
...ensions/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DropV2ViewExec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.execution.datasources.v2 | ||
|
||
import org.apache.spark.sql.catalyst.InternalRow | ||
import org.apache.spark.sql.catalyst.analysis.NoSuchViewException | ||
import org.apache.spark.sql.catalyst.expressions.Attribute | ||
import org.apache.spark.sql.connector.catalog.Identifier | ||
import org.apache.spark.sql.connector.catalog.ViewCatalog | ||
|
||
|
||
case class DropV2ViewExec( | ||
catalog: ViewCatalog, | ||
ident: Identifier, | ||
ifExists: Boolean) extends LeafV2CommandExec { | ||
|
||
override lazy val output: Seq[Attribute] = Nil | ||
|
||
override protected def run(): Seq[InternalRow] = { | ||
val dropped = catalog.dropView(ident) | ||
if (!dropped && !ifExists) { | ||
throw new NoSuchViewException(ident) | ||
} | ||
|
||
Nil | ||
} | ||
|
||
override def simpleString(maxFields: Int): String = { | ||
s"DropV2View: ${ident}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters