Github user janewangfb commented on a diff in the pull request:
https://github.com/apache/spark/pull/18023#discussion_r117374353
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
---
@@ -1229,25 +1228,56 @@ class AstBuilder(conf: SQLConf) extends
SqlBaseBaseVisitor[AnyRef] with Logging
CaseWhen(branches, Option(ctx.elseExpression).map(expression))
}
+ def enableHiveSupportQuotedIdentifiers() : Boolean = {
+ SparkEnv.get != null &&
+ SparkEnv.get.conf != null &&
+ SparkEnv.get.conf.getBoolean("hive.support.quoted.identifiers",
false)
+ }
+
/**
- * Create a dereference expression. The return type depends on the type
of the parent, this can
- * either be a [[UnresolvedAttribute]] (if the parent is an
[[UnresolvedAttribute]]), or an
- * [[UnresolvedExtractValue]] if the parent is some expression.
+ * Create a dereference expression. The return type depends on the type
of the parent.
+ * If the parent is an [[UnresolvedAttribute]], it can be a
[[UnresolvedAttribute]] or
+ * a [[UnresolvedRegex]] for regex quoted in ``; if the parent is some
other expression,
+ * it can be [[UnresolvedExtractValue]].
*/
override def visitDereference(ctx: DereferenceContext): Expression =
withOrigin(ctx) {
val attr = ctx.fieldName.getText
expression(ctx.base) match {
- case UnresolvedAttribute(nameParts) =>
+ case unresolved_attr @ UnresolvedAttribute(nameParts) =>
+ if (enableHiveSupportQuotedIdentifiers) {
+ val escapedIdentifier = "`(.+)`".r
+ val ret = Option(ctx.fieldName.getStart).map(_.getText match {
+ case r@escapedIdentifier(i) =>
+ UnresolvedRegex(i, Some(unresolved_attr.name))
--- End diff --
Before we go to ResolveReferences, we need to figure out that the regex is
the special case, just like Star. ResolveReferences will do the resolve based
on the expression type is UnresolvedRegx, Star etc.
Database API goes the same path. I have added a unittest for
DatasetSuite.scala for regex
---
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]