srielau commented on code in PR #53530: URL: https://github.com/apache/spark/pull/53530#discussion_r2695022643
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveFetchCursor.scala: ########## @@ -0,0 +1,97 @@ +/* + * 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.SparkException +import org.apache.spark.sql.AnalysisException +import org.apache.spark.sql.catalyst.expressions.VariableReference +import org.apache.spark.sql.catalyst.plans.logical.{FetchCursor, LogicalPlan, SingleStatement} +import org.apache.spark.sql.catalyst.rules.Rule +import org.apache.spark.sql.catalyst.trees.TreePattern.COMMAND +import org.apache.spark.sql.connector.catalog.CatalogManager +import org.apache.spark.sql.errors.QueryCompilationErrors.unresolvedVariableError + +/** + * Resolves the target SQL variables in FetchCursor command. + * Variables can be either scripting local variables or session variables. + */ +class ResolveFetchCursor(val catalogManager: CatalogManager) extends Rule[LogicalPlan] + with ColumnResolutionHelper { + // VariableResolution looks up both scripting local variables (via SqlScriptingContextManager) + // and session variables (via tempVariableManager), checking local variables first. + private val variableResolution = new VariableResolution(catalogManager.tempVariableManager) + + /** + * Checks for duplicate variable names and throws an exception if found. + * Names are normalized when the variables are created. + * No need for case insensitive comparison here. + */ + private def checkForDuplicateVariables(variables: Seq[VariableReference]): Unit = { Review Comment: I have a SELECT INTO PR which will follow. We can unify there. I have already unified USING for EXECUTE and OPEN -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
