cloud-fan commented on a change in pull request #25747: [SPARK-29039][SQL] 
centralize the catalog and table lookup logic
URL: https://github.com/apache/spark/pull/25747#discussion_r328889729
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveCatalogAndTablesForV1Commands.scala
 ##########
 @@ -0,0 +1,118 @@
+/*
+ * 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.AnalysisException
+import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
+import 
org.apache.spark.sql.catalyst.plans.logical.sql.{AlterTableAddColumnsStatement, 
AlterTableAlterColumnStatement, AlterTableDropColumnsStatement, 
AlterTableRenameColumnStatement, AlterTableSetLocationStatement, 
AlterTableSetPropertiesStatement, AlterTableUnsetPropertiesStatement, 
AlterViewSetPropertiesStatement, AlterViewUnsetPropertiesStatement, 
DeleteFromStatement, DescribeColumnStatement, DescribeTableStatement, 
QualifiedColType}
+import org.apache.spark.sql.catalyst.rules.Rule
+import org.apache.spark.sql.connector.catalog.{CatalogManager, LookupCatalog, 
V1Table}
+import org.apache.spark.sql.execution.command.{AlterTableAddColumnsCommand, 
AlterTableSetLocationCommand, AlterTableSetPropertiesCommand, 
AlterTableUnsetPropertiesCommand, DescribeColumnCommand, DescribeTableCommand}
+import org.apache.spark.sql.types.{HIVE_TYPE_STRING, HiveStringType, 
MetadataBuilder, StructField}
+
+/**
+ * Resolves catalogs and tables from the multi-part identifiers in SQL 
statements, and convert the
+ * statements to the corresponding v1 commands if the resolved table is a 
[[V1Table]].
+ *
+ * We can remove this rule once we implement all the catalog functionality in 
`V2SessionCatalog`.
+ */
+class ResolveCatalogAndTablesForV1Commands(
+    val catalogManager: CatalogManager, isTempView: Seq[String] => Boolean)
+  extends Rule[LogicalPlan] with LookupCatalog {
+  import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
+
+  override def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsUp 
{
+    case AlterTableAddColumnsStatement(
+         CatalogAndTable(catalog, tblName, _: V1Table), cols) =>
 
 Review comment:
   Sorry I didn't make it clear. Yes session catalog may contain v2 tables as 
we can create table with v2 provider. However, session catalog never return v2 
tables. So all the v2 commands that need to resolve tables never work for v2 
tables in session catalog.
   
   This is the existing behavior. If you take a look at `ResolveAlterTable`, it 
calls `lookupV2RelationAndCatalog` which ignores `V1Table`.
   
   The code here is future-proof. Once #25651 is merged, we will create v2 
commands for v2 tables in session catalog without any changes.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to