Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RD-14898: SqlCompiler crashes when running 'hover' against a query that has two statements #516

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,10 @@ class SqlVisitor(
val param = SqlParamUseNode(name)

param match {
case use: SqlParamUseNode => params.get(use.name) match {
// The first statement is the only one that will be provided and later considered when running/validating
// in Postgres. Therefore, we ignore parameters when they don't belong that first statement.
case use: SqlParamUseNode if isFirstStatement =>
params.get(use.name) match {
case Some(value) => params.update(use.name, value.copy(occurrences = value.occurrences :+ use))
case None => params += (use.name -> SqlParam(use.name, None, None, None, Vector.empty, Vector(use)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1124,4 +1124,33 @@ class TestSqlCompilerServiceAirports
assert(baos.toString() === """[{"x":"2008-09-29"}]""")
}

test("""RD-14898""".stripMargin) { _ =>
{
// A query with a single statement spread over two lines.
val t = TestData("""
|SELECT airport_id FROM example.airports WHERE city = :location
| AND airport_id = :iata
|""".stripMargin)
// hover ':location' returns the type of location (varchar)
val v1 = compilerService.hover(t.q, asJson(), Pos(2, 57))
assert(v1.completion.contains(TypeCompletion("location", "varchar")))
// hover ':iata' returns the type of iata (integer)
val v2 = compilerService.hover(t.q, asJson(), Pos(3, 57))
assert(v2.completion.contains(TypeCompletion("iata", "integer")))
}
{
// ALMOST THE SAME code as before, there's a typo: a semicolon in the end of the first line.
val t = TestData("""
|SELECT airport_id FROM example.airports WHERE city = :location;
| AND airport_id = :iata
|""".stripMargin)
// hover ':location' still returns the type of location (varchar)
val v1 = compilerService.hover(t.q, asJson(), Pos(2, 57))
assert(v1.completion.contains(TypeCompletion("location", "varchar")))
// hover ':iata' doesn't return anything since it's ignored.
val v2 = compilerService.hover(t.q, asJson(), Pos(3, 57))
assert(v2.completion.isEmpty)
}
}

}