miland-db commented on code in PR #48795:
URL: https://github.com/apache/spark/pull/48795#discussion_r1833358190
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParserUtils.scala:
##########
@@ -134,3 +139,70 @@ object ParserUtils extends SparkParserUtils {
sb.toString()
}
}
+
+object LabelUtils {
+ private val seenLabels: mutable.Set[String] = mutable.Set.empty
+
+ def init(): Unit = {
+ seenLabels.clear()
+ }
+
+ private def checkLabels(
+ beginLabelCtx: Option[BeginLabelContext],
+ endLabelCtx: Option[EndLabelContext]) : Unit = {
+ (beginLabelCtx, endLabelCtx) match {
+ case (Some(bl: BeginLabelContext), Some(el: EndLabelContext))
+ if bl.multipartIdentifier().getText.nonEmpty &&
Review Comment:
This checks that if both labels are defined (not None) and if they hold
different string value it should fail as _BeginLabel_ and _EndLabel_ must match.
When I look at it now, I think we can remove
`bl.multipartIdentifier().getText.nonEmpty` part from the check because we know
that label is defined.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParserUtils.scala:
##########
@@ -134,3 +139,70 @@ object ParserUtils extends SparkParserUtils {
sb.toString()
}
}
+
+object LabelUtils {
+ private val seenLabels: mutable.Set[String] = mutable.Set.empty
+
+ def init(): Unit = {
+ seenLabels.clear()
+ }
+
+ private def checkLabels(
+ beginLabelCtx: Option[BeginLabelContext],
+ endLabelCtx: Option[EndLabelContext]) : Unit = {
+ (beginLabelCtx, endLabelCtx) match {
+ case (Some(bl: BeginLabelContext), Some(el: EndLabelContext))
+ if bl.multipartIdentifier().getText.nonEmpty &&
+ bl.multipartIdentifier().getText.toLowerCase(Locale.ROOT) !=
+ el.multipartIdentifier().getText.toLowerCase(Locale.ROOT) =>
+ withOrigin(bl) {
+ seenLabels.clear()
+ throw SqlScriptingErrors.labelsMismatch(
+ CurrentOrigin.get,
+ bl.multipartIdentifier().getText,
+ el.multipartIdentifier().getText)
+ }
+ case (None, Some(el: EndLabelContext)) =>
Review Comment:
This can fall into default `case _` because if _BeginLabel_ is defined and
_EndLabel_ is not, that is always ok (except if BeginLabel is duplicate of some
parent label but we are not concerned with that part here).
--
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]