You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/02/11 02:33:37 UTC
[GitHub] [spark] AngersZhuuuu commented on a change in pull request #35476: [SPARK-38173][SQL] Quoted column cannot be recognized correctly when quotedRegexColumnNa…
AngersZhuuuu commented on a change in pull request #35476:
URL: https://github.com/apache/spark/pull/35476#discussion_r804318804
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -2085,12 +2085,23 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
private def canApplyRegex(ctx: ParserRuleContext): Boolean = withOrigin(ctx) {
var parent = ctx.getParent
while (parent != null) {
- if (parent.isInstanceOf[NamedExpressionContext]) return true
+ if (parent.isInstanceOf[NamedExpressionContext] && isRegex(ctx.getText)) return true
parent = parent.getParent
}
return false
}
+ /**
+ * Returns whether the pattern is a regex expression (instead of a normal
+ * string). Normal string is a string with all alphabets/digits and "_".
+ */
+ private def isRegex(pattern: String): Boolean = {
+ for (p <- pattern) {
+ if (!Character.isLetterOrDigit(p) && p != '_') return true
+ }
Review comment:
Maybe we can make it more like a scala code.
to use
```
pattern.find()
or
pattern.forall()
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org