Skip to content

Commit

Permalink
feat(tvf): support for testing usage of tvf in smoke test
Browse files Browse the repository at this point in the history
The check is a bit different from table and views. It has to verify that the schema
matches and the params. The schema tests is done through a CTE and the parameters
through a UDF that always return true. The query CTE body needs to include a reference
to both of them.
  • Loading branch information
ingarabr committed Nov 8, 2023
1 parent 5945a38 commit aca4ebf
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions testing/src/main/scala/no/nrk/bigquery/testing/BQSmokeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ object BQSmokeTest {
(x, Nil)

case BQSqlFrag.Call(udf, args) =>
val (newArgs, ctes) = args.toList.map(recurse).separate
val (newArgs, ctes) = args.map(recurse).separate
udf match {
case tUdf @ UDF.Temporary(_, _, Body.Sql(body), _) =>
val (newUdfBody, ctesFromUDF) = recurse(body)
Expand All @@ -409,7 +409,19 @@ object BQSmokeTest {
),
ctesFromUDF ++ ctes.flatten
)
case _ => (BQSqlFrag.Call(udf, newArgs), ctes.flatten)
case tvf: TVF[_, _] =>
val cteName = Ident(tvf.name.asString.filter(c => c.isLetterOrDigit || c == '_'))
val tvfParamUdf =
BQSqlFrag.Call(
UDF.temporary(Ident(cteName.value ++ "_udf"), tvf.params, bqfr"TRUE", Some(BQType.BOOL)),
newArgs
)
(
bqfr"(select * from $cteName where $tvfParamUdf)",
List(CTE(cteName, bqfr"(select ${exampleRow(tvf.schema)})"))
)
case _ =>
(BQSqlFrag.Call(udf, newArgs), ctes.flatten)
}

case BQSqlFrag.Combined(frags) =>
Expand Down

0 comments on commit aca4ebf

Please sign in to comment.