Skip to content

Commit

Permalink
RD-11232 sql compiler crash parser computes a wrong line col (#465)
Browse files Browse the repository at this point in the history
- Fixed by striping trail and removing the extra new line

---------

Co-authored-by: Benjamin Gaidioz <ben@raw-labs.com>
  • Loading branch information
alexzerntev and bgaidioz authored Jul 8, 2024
1 parent 8f8bd12 commit 87bbbf9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class RawSqlSyntaxAnalyzer(val positions: Positions) extends Parsers(positions)
val source = StringSource(s)
val rawErrorListener = new RawSqlErrorListener()

val lexer = new PsqlLexer(CharStreams.fromString(s))
val striped = s.stripTrailing()
val lexer = new PsqlLexer(CharStreams.fromString(striped))
lexer.removeErrorListeners()
lexer.addErrorListener(rawErrorListener)

Expand Down
27 changes: 27 additions & 0 deletions sql-client/src/test/scala/raw/client/sql/TestSqlParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -624,4 +624,31 @@ class TestSqlParser extends AnyFunSuite {
}
}

test("newline after comment") {
val code = """select
| id,
| key,
| summary,
| project_key,
| status,
| assignee_display_name,
| assignee_account_id
|from
| "jira-danai".jira_backlog_issue
| limit 2
|--where
|-- assignee_display_name = 'yann';
| """.stripMargin
val result = doTest(code)
checkStartEnd(result)
}

private def checkStartEnd(result: ParseProgramResult) = {
val SqlProgramNode(stmt) = result.tree
assert(result.positions.getStart(stmt).isDefined)
assert(result.positions.getFinish(stmt).isDefined)
assert(result.positions.getStart(stmt).flatMap(_.optOffset).isDefined)
assert(result.positions.getFinish(stmt).flatMap(_.optOffset).isDefined)
}

}

0 comments on commit 87bbbf9

Please sign in to comment.