Github user rednaxelafx commented on a diff in the pull request:
https://github.com/apache/spark/pull/19082#discussion_r136506046
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala
---
@@ -244,6 +246,92 @@ case class HashAggregateExec(
protected override val shouldStopRequired = false
+ // We assume a prefix has lower cases and a name has camel cases
+ private val variableName = "^[a-z]+_[a-zA-Z]+[0-9]*".r
--- End diff --
I know the regular expression is tempting, but there's actually a better
way to do this along your idea, under the current framework.
I've got a piece of code sitting in my own workspace that checks for Java
identifiers:
```scala
object CodegenContext {
private val javaKeywords = Set(
"abstract", "assert", "boolean", "break", "byte", "case", "catch",
"char", "class",
"const", "continue", "default", "do", "double", "else", "extends",
"false", "final",
"finally", "float", "for", "goto", "if", "implements", "import",
"instanceof", "int",
"interface", "long", "native", "new", "null", "package", "private",
"protected", "public",
"return", "short", "static", "strictfp", "super", "switch",
"synchronized", "this",
"throw", "throws", "transient", "true", "try", "void", "volatile",
"while"
)
def isJavaIdentifier(str: String): Boolean = str match {
case null | "" => false
case _ => java.lang.Character.isJavaIdentifierStart(str.charAt(0)) &&
(1 until str.length).forall(
i =>
java.lang.Character.isJavaIdentifierPart(str.charAt(i))) &&
!javaKeywords.contains(str)
}
}
```
Feel free to use it here if you'd like. This is the way
`java.lang.Character.isJavaIdentifierStart()` and
`java.lang.Character.isJavaIdentifierPart()` is supposed to be used anyway,
nothing creative.
If you want to use it in a `case` like the way you're using the regular
expression, just wrap the util above into an `unapply()`. But I'd say simply
making `def isVariable(nameId: String) =
CodegenContext.isJavaIdentifier(nameId)` is clean enough.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]