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-10767 typealias in top level declarations #400

Merged
merged 17 commits into from
Apr 23, 2024
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
4 changes: 2 additions & 2 deletions client/src/main/scala/raw/client/api/ProgramDescription.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ final case class ProgramDescription(

final case class DeclDescription(
params: Option[Vector[ParamDescription]],
outType: RawType,
outType: Option[RawType],
comment: Option[String]
)

final case class ParamDescription(
idn: String,
tipe: RawType,
tipe: Option[RawType],
defaultValue: Option[RawValue],
comment: Option[String],
required: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,41 +154,20 @@ class Rql2TruffleCompilerService(engineDefinition: (Engine, Boolean), maybeClass
val formattedDecls = decls.map {
case (idn, programDecls) =>
val formattedDecls = programDecls.map {
case TreeDeclDescription(None, outType, comment) => rql2TypeToRawType(outType) match {
case Some(rawType) => DeclDescription(None, rawType, comment)
case None => return GetProgramDescriptionFailure(
List(ErrorMessage(UnsupportedType.message, List.empty, UnsupportedType.code))
)
}
case TreeDeclDescription(None, outType, comment) =>
DeclDescription(None, rql2TypeToRawType(outType), comment)
case TreeDeclDescription(Some(params), outType, comment) =>
val formattedParams = params.map {
case TreeParamDescription(idn, tipe, required) => rql2TypeToRawType(tipe) match {
case Some(rawType) =>
ParamDescription(idn, rawType, defaultValue = None, comment = None, required)
case None => return GetProgramDescriptionFailure(
List(ErrorMessage(UnsupportedType.message, List.empty, UnsupportedType.code))
)
}
}
rql2TypeToRawType(outType) match {
case Some(rawType) => DeclDescription(Some(formattedParams), rawType, comment)
case None => return GetProgramDescriptionFailure(
List(ErrorMessage(UnsupportedType.message, List.empty, UnsupportedType.code))
)
case TreeParamDescription(idn, tipe, required) =>
ParamDescription(idn, rql2TypeToRawType(tipe), defaultValue = None, comment = None, required)
}
DeclDescription(Some(formattedParams), rql2TypeToRawType(outType), comment)
}
(idn, formattedDecls)
}
val programDescription = ProgramDescription(
formattedDecls,
maybeType.map { t =>
rql2TypeToRawType(t) match {
case Some(rawType) => DeclDescription(None, rawType, None)
case None => return GetProgramDescriptionFailure(
List(ErrorMessage(UnsupportedType.message, List.empty, UnsupportedType.code))
)
}
},
maybeType.map(t => DeclDescription(None, rql2TypeToRawType(t), None)),
comment
)
GetProgramDescriptionSuccess(programDescription)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2023 RAW Labs S.A.
*
* Use of this software is governed by the Business Source License
* included in the file licenses/BSL.txt.
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0, included in the file
* licenses/APL.txt.
*/

package raw.compiler.rql2.tests.truffle.regressions

import raw.client.api.{GetProgramDescriptionSuccess, ProgramEnvironment}
import raw.compiler.rql2.truffle.TruffleCompilerTestContext
import raw.compiler.utils.SnapiInterpolator

class RD10767Test extends TruffleCompilerTestContext {
private val data = tempFile("""
|[
| {"a": 1, "b": 10, "c": 100},
| {"a": 2, "b": 20, "c": 200},
| {"a": 3, "b": 30, "c": 300}
|]""".stripMargin)

test(snapi"""data_type() = type collection(record(a: int, b: int, c: int))
|
|Json.Read("$data", data_type())
|""".stripMargin) { it =>
val programEnvironment = ProgramEnvironment(authorizedUser, None, Set.empty, Map.empty, None)
compilerService.getProgramDescription(it.q, programEnvironment) match {
case GetProgramDescriptionSuccess(desc) =>
assert(desc.maybeRunnable.isDefined, "Expected a runnable program")
val decls = desc.decls("data_type")
assert(decls.head.outType.isEmpty)
case other => fail(s"Expected GetProgramDescriptionSuccess, got $other")
}
}

test(snapi"""func() = let f(i: int) = i +1 in f
|
|func()(1)
|""".stripMargin) { it =>
val programEnvironment = ProgramEnvironment(authorizedUser, None, Set.empty, Map.empty, None)
compilerService.getProgramDescription(it.q, programEnvironment) match {
case GetProgramDescriptionSuccess(desc) =>
assert(desc.maybeRunnable.isDefined, "Expected a runnable program")
val decls = desc.decls("func")
assert(decls.head.outType.isEmpty)
case other => fail(s"Expected GetProgramDescriptionSuccess, got $other")
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import raw.compiler.rql2.truffle.TruffleCompilerTestContext
import raw.testing.tags.TruffleTests

@TruffleTests class RD9485TruffleTest extends TruffleCompilerTestContext with RD9485Test

@TruffleTests class RD9445TruffleTest extends TruffleCompilerTestContext with RD9445Test

@TruffleTests class RD5797TruffleTest extends TruffleCompilerTestContext with RD5797Test
@TruffleTests class RD5779TruffleTest extends TruffleCompilerTestContext with RD5779Test
@TruffleTests class RD5393TruffleTest extends TruffleCompilerTestContext with RD5393Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ class SqlCompilerService(maybeClassLoader: Option[ClassLoader] = None)(implicit
case other => other.cloneNullable
}
// their default value is `null`.
ParamDescription(name, nullableType, Some(RawNull()), paramInfo.comment, required = false)
ParamDescription(
name,
Some(nullableType),
Some(RawNull()),
paramInfo.comment,
required = false
)
}
}
.foldLeft(Right(Seq.empty): Either[Seq[String], Seq[ParamDescription]]) {
Expand All @@ -111,7 +117,7 @@ class SqlCompilerService(maybeClassLoader: Option[ClassLoader] = None)(implicit
// This permits the publish endpoints from the UI (https://raw-labs.atlassian.net/browse/RD-10359)
val ok = ProgramDescription(
Map.empty,
Some(DeclDescription(Some(ps.toVector), iterableType, None)),
Some(DeclDescription(Some(ps.toVector), Some(iterableType), None)),
None
)
GetProgramDescriptionSuccess(ok)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class TestSqlCompilerServiceAirports
assert(description.decls.isEmpty)
val Some(main) = description.maybeRunnable
assert(
main.outType == airportType
main.outType.get == airportType
)
assert(main.params.contains(Vector.empty))
val baos = new ByteArrayOutputStream()
Expand Down Expand Up @@ -419,12 +419,12 @@ class TestSqlCompilerServiceAirports
assert(description.decls.isEmpty)
val Some(main) = description.maybeRunnable
assert(
main.outType == airportType
main.outType.get == airportType
)
val Some(Vector(param)) = main.params
assert(!param.required)
assert(param.idn == "city")
assert(param.tipe == RawStringType(true, false))
assert(param.tipe.get == RawStringType(true, false))
assert(param.defaultValue.contains(RawNull()))
val baos = new ByteArrayOutputStream()
assert(
Expand Down Expand Up @@ -458,12 +458,12 @@ class TestSqlCompilerServiceAirports
assert(description.decls.isEmpty)
val Some(main) = description.maybeRunnable
assert(
main.outType == airportType
main.outType.get == airportType
)
val Some(Vector(param)) = main.params
assert(!param.required)
assert(param.idn == "city")
assert(param.tipe == RawStringType(true, false))
assert(param.tipe.get == RawStringType(true, false))
assert(param.defaultValue.contains(RawNull()))
val baos = new ByteArrayOutputStream()
assert(
Expand Down Expand Up @@ -608,7 +608,7 @@ class TestSqlCompilerServiceAirports
assert(description.decls.isEmpty)
val Some(main) = description.maybeRunnable
assert(
main.outType == RawIterableType(
main.outType.get == RawIterableType(
RawRecordType(Vector(RawAttrType("count", RawLongType(true, false))), false, false),
false,
false
Expand All @@ -617,7 +617,7 @@ class TestSqlCompilerServiceAirports
val Some(Vector(param)) = main.params
assert(!param.required)
assert(param.idn == "name")
assert(param.tipe == RawStringType(true, false))
assert(param.tipe.get == RawStringType(true, false))
assert(param.defaultValue.contains(RawNull()))
val baos = new ByteArrayOutputStream()
baos.reset()
Expand Down Expand Up @@ -654,7 +654,7 @@ class TestSqlCompilerServiceAirports
assert(description.decls.isEmpty)
val Some(main) = description.maybeRunnable
assert(
main.outType == RawIterableType(
main.outType.get == RawIterableType(
RawRecordType(Vector(RawAttrType("count", RawLongType(true, false))), false, false),
false,
false
Expand All @@ -663,7 +663,7 @@ class TestSqlCompilerServiceAirports
val Some(Vector(param)) = main.params
assert(!param.required)
assert(param.idn == "name")
assert(param.tipe == RawStringType(true, false))
assert(param.tipe.get == RawStringType(true, false))
assert(param.defaultValue.contains(RawNull()))
val baos = new ByteArrayOutputStream()
baos.reset()
Expand All @@ -685,7 +685,7 @@ class TestSqlCompilerServiceAirports
assert(description.decls.isEmpty)
val Some(main) = description.maybeRunnable
assert(
main.outType == RawIterableType(
main.outType.get == RawIterableType(
RawRecordType(
Vector(
RawAttrType("x", RawDateType(true, false))
Expand All @@ -699,7 +699,7 @@ class TestSqlCompilerServiceAirports
)
assert(
main.params.contains(
Vector(ParamDescription("s", RawIntType(true, false), Some(RawNull()), Some("just an int"), false))
Vector(ParamDescription("s", Some(RawIntType(true, false)), Some(RawNull()), Some("just an int"), false))
)
)
val baos = new ByteArrayOutputStream()
Expand Down
Loading