Skip to content

Commit 120cd21

Browse files
committed
initial commit
1 parent 6cb88c1 commit 120cd21

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/higherOrderFunctions.scala

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,6 @@ object ResolveLambdaVariables extends Rule[LogicalPlan] {
4141

4242
type LambdaVariableMap = Map[String, NamedExpression]
4343

44-
private def canonicalizer = {
45-
if (!conf.caseSensitiveAnalysis) {
46-
// scalastyle:off caselocale
47-
s: String => s.toLowerCase
48-
// scalastyle:on caselocale
49-
} else {
50-
s: String => s
51-
}
52-
}
53-
5444
override def apply(plan: LogicalPlan): LogicalPlan = {
5545
plan.resolveOperatorsWithPruning(
5646
_.containsAnyPattern(HIGH_ORDER_FUNCTION, LAMBDA_FUNCTION, LAMBDA_VARIABLE), ruleId) {
@@ -80,11 +70,11 @@ object ResolveLambdaVariables extends Rule[LogicalPlan] {
8070
"actualNumArgs" -> argInfo.size.toString))
8171
}
8272

83-
if (names.map(a => canonicalizer(a.name)).distinct.size < names.size) {
73+
if (names.map(a => conf.canonicalize(a.name)).distinct.size < names.size) {
8474
e.failAnalysis(
8575
errorClass = "INVALID_LAMBDA_FUNCTION_CALL.DUPLICATE_ARG_NAMES",
8676
messageParameters = Map(
87-
"args" -> names.map(a => canonicalizer(a.name)).map(toSQLId(_)).mkString(", "),
77+
"args" -> names.map(a => conf.canonicalize(a.name)).map(toSQLId(_)).mkString(", "),
8878
"caseSensitiveConfig" -> toSQLConf(SQLConf.CASE_SENSITIVE.key)))
8979
}
9080

@@ -124,11 +114,11 @@ object ResolveLambdaVariables extends Rule[LogicalPlan] {
124114
l
125115

126116
case l: LambdaFunction if !l.hidden =>
127-
val lambdaMap = l.arguments.map(v => canonicalizer(v.name) -> v).toMap
117+
val lambdaMap = l.arguments.map(v => conf.canonicalize(v.name) -> v).toMap
128118
l.mapChildren(resolve(_, parentLambdaMap ++ lambdaMap))
129119

130120
case u @ UnresolvedNamedLambdaVariable(name +: nestedFields) =>
131-
parentLambdaMap.get(canonicalizer(name)) match {
121+
parentLambdaMap.get(conf.canonicalize(name)) match {
132122
case Some(lambda) =>
133123
nestedFields.foldLeft(lambda: Expression) { (expr, fieldName) =>
134124
ExtractValue(expr, Literal(fieldName), conf.resolver)

sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7210,6 +7210,20 @@ class SQLConf extends Serializable with Logging with SqlApiConf {
72107210
}
72117211
}
72127212

7213+
/**
7214+
* Returns the lower case representation of a string if `caseSensitiveAnalysis` is enabled.
7215+
* Otherwise, returns the original string.
7216+
*/
7217+
def canonicalize(s: String): String = {
7218+
if (caseSensitiveAnalysis) {
7219+
// scalastyle:off caselocale
7220+
s.toLowerCase
7221+
// scalastyle:on caselocale
7222+
} else {
7223+
s
7224+
}
7225+
}
7226+
72137227
/**
72147228
* Returns the error handler for handling hint errors.
72157229
*/

0 commit comments

Comments
 (0)