Skip to content

Commit

Permalink
RD-10763: Replace maybeType by a Decl in ProgramDescription (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgaidioz authored Mar 28, 2024
1 parent 7df6754 commit ebee7f2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package raw.client.api

final case class ProgramDescription(
decls: Map[String, List[DeclDescription]],
maybeType: Option[RawType],
maybeRunnable: Option[DeclDescription],
comment: Option[String]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean), maybeClass
formattedDecls,
maybeType.map { t =>
rql2TypeToRawType(t) match {
case Some(rawType) => rawType
case Some(rawType) => DeclDescription(None, rawType, None)
case None => return GetProgramDescriptionFailure(
List(ErrorMessage(UnsupportedType.message, List.empty, UnsupportedType.code))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ class SqlCompilerService(maybeClassLoader: Option[ClassLoader] = None)(implicit
// Regardless if there are parameters, we declare a main function with the output type.
// This permits the publish endpoints from the UI (https://raw-labs.atlassian.net/browse/RD-10359)
val ok = ProgramDescription(
Map("main" -> List(DeclDescription(Some(ps.toVector), iterableType, None))),
None,
Map.empty,
Some(DeclDescription(Some(ps.toVector), iterableType, None)),
None
)
GetProgramDescriptionSuccess(ok)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,6 @@ class TestNamedParametersStatement
super.afterAll()
}

test("bug") { _ =>
assume(password != "")

val code = """-- @type aeroport_id smallint
|SELECT :city::json FROM example.airports WHERE airport_id = :aeroport_id""".stripMargin

val statement = new NamedParametersPreparedStatement(con, parse(code))
val metadata = statement.queryMetadata
assert(metadata.isLeft)
statement.setString("v1", "Hello!")
val rs = statement.executeQuery()

rs.next()
assert(rs.getString("arg") == "Hello!")
}

test("single parameter") { _ =>
assume(password != "")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ class TestSqlCompilerServiceAirports
val v = compilerService.validate(t.q, environment)
assert(v.messages.isEmpty)
val GetProgramDescriptionSuccess(description) = compilerService.getProgramDescription(t.q, environment)
assert(description.maybeType.isEmpty)
val List(main) = description.decls("main")
assert(description.decls.isEmpty)
val Some(main) = description.maybeRunnable
assert(
main.outType == airportType
)
Expand Down Expand Up @@ -416,8 +416,8 @@ class TestSqlCompilerServiceAirports
val v = compilerService.validate(t.q, environment)
assert(v.messages.isEmpty)
val GetProgramDescriptionSuccess(description) = compilerService.getProgramDescription(t.q, environment)
assert(description.maybeType.isEmpty)
val List(main) = description.decls("main")
assert(description.decls.isEmpty)
val Some(main) = description.maybeRunnable
assert(
main.outType == airportType
)
Expand Down Expand Up @@ -455,8 +455,8 @@ class TestSqlCompilerServiceAirports
val v = compilerService.validate(t.q, environment)
assert(v.messages.isEmpty)
val GetProgramDescriptionSuccess(description) = compilerService.getProgramDescription(t.q, environment)
assert(description.maybeType.isEmpty)
val List(main) = description.decls("main")
assert(description.decls.isEmpty)
val Some(main) = description.maybeRunnable
assert(
main.outType == airportType
)
Expand Down Expand Up @@ -605,8 +605,8 @@ class TestSqlCompilerServiceAirports
val v = compilerService.validate(t.q, withCity)
assert(v.messages.isEmpty)
val GetProgramDescriptionSuccess(description) = compilerService.getProgramDescription(t.q, withCity)
assert(description.maybeType.isEmpty)
val List(main) = description.decls("main")
assert(description.decls.isEmpty)
val Some(main) = description.maybeRunnable
assert(
main.outType == RawIterableType(
RawRecordType(Vector(RawAttrType("count", RawLongType(true, false))), false, false),
Expand Down Expand Up @@ -651,8 +651,8 @@ class TestSqlCompilerServiceAirports
val v = compilerService.validate(t.q, withCity)
assert(v.messages.isEmpty)
val GetProgramDescriptionSuccess(description) = compilerService.getProgramDescription(t.q, withCity)
assert(description.maybeType.isEmpty)
val List(main) = description.decls("main")
assert(description.decls.isEmpty)
val Some(main) = description.maybeRunnable
assert(
main.outType == RawIterableType(
RawRecordType(Vector(RawAttrType("count", RawLongType(true, false))), false, false),
Expand Down Expand Up @@ -681,8 +681,8 @@ class TestSqlCompilerServiceAirports
val v = compilerService.validate(t.q, environment)
assert(v.messages.isEmpty)
val GetProgramDescriptionSuccess(description) = compilerService.getProgramDescription(t.q, environment)
assert(description.maybeType.isEmpty)
val List(main) = description.decls("main")
assert(description.decls.isEmpty)
val Some(main) = description.maybeRunnable
assert(
main.outType == RawIterableType(
RawRecordType(
Expand Down

0 comments on commit ebee7f2

Please sign in to comment.