gengliangwang commented on a change in pull request #35936:
URL: https://github.com/apache/spark/pull/35936#discussion_r832884518
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ParserUtilsSuite.scala
##########
@@ -199,4 +217,42 @@ class ParserUtilsSuite extends SparkFunSuite {
assert(origin == Origin(Some(3), Some(27)))
assert(CurrentOrigin.get == current)
}
+
+ private def findCastContext(ctx: ParserRuleContext): Option[CastContext] = {
+ ctx match {
+ case context: CastContext =>
+ Some(context)
+ case _ =>
+ val it = ctx.children.iterator()
+ while(it.hasNext) {
+ it.next() match {
+ case p: ParserRuleContext =>
+ val childResult = findCastContext(p)
+ if (childResult.isDefined) {
+ return childResult
+ }
+ case _ =>
+ }
+ }
+ None
+ }
+ }
+
+ test("withOrigin: setting SQL text") {
+ withOrigin(castQueryContext, Some(castQuery)) {
+ assert(CurrentOrigin.get.sqlText.contains(castQuery))
+ val castContext = findCastContext(castQueryContext)
+ assert(castContext.isDefined)
+ withOrigin(castContext.get) {
+ val current = CurrentOrigin.get
+ assert(current.sqlText.contains(castQuery))
+ assert(current.startIndex.isDefined)
+ assert(current.stopIndex.isDefined)
+ // With sqlText, startIndex, stopIndex, we can get the corresponding
SQL text of the
+ // Cast clause.
+ assert(current.sqlText.get.substring(current.startIndex.get,
current.stopIndex.get + 1) ==
Review comment:
Yeah I am thinking about having a method for building the whole error
message like:
```
(line 1, pos 7)
== SQL ==
select cast('a' as int)
-------^^^ ^^^^^^^
```
This will be added after we decide the error message format in another PR.
--
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]