Skip to content

Commit

Permalink
fix: add type parameter for call in routines
Browse files Browse the repository at this point in the history
Using BQSqlFrag did introduce a regression when using the ufd
smoketests where BQSqlFrag.Call was expected. It makes sense to
keep the more specific type here because it will not work with
TVFs.
  • Loading branch information
ingarabr committed Nov 23, 2023
1 parent 89ccbf8 commit 2c1a93e
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 81 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.typesafe.tools.mima.core._

// https://typelevel.org/sbt-typelevel/faq.html#what-is-a-base-version-anyway
ThisBuild / tlBaseVersion := "0.12" // your current series x.y
ThisBuild / tlBaseVersion := "0.13" // your current series x.y

ThisBuild / organization := "no.nrk.bigquery"
ThisBuild / organizationName := "NRK"
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/scala/no/nrk/bigquery/BQRoutine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import no.nrk.bigquery.syntax.*
import no.nrk.bigquery.util.IndexSeqSizedBuilder
import no.nrk.bigquery.util.{Nat, Sized}

sealed trait BQRoutine[N <: Nat] {
sealed trait BQRoutine[N <: Nat, C] {
def params: BQRoutine.Params[N]
def call(args: Sized[IndexedSeq[BQSqlFrag.Magnet], N]): BQSqlFrag
def call(args: Sized[IndexedSeq[BQSqlFrag.Magnet], N]): C
}

sealed trait BQPersistentRoutine[N <: Nat] extends BQRoutine[N] {
sealed trait BQPersistentRoutine[N <: Nat, C] extends BQRoutine[N, C] {
def name: BQPersistentRoutine.Id
}

Expand Down Expand Up @@ -64,8 +64,8 @@ case class TVF[+P, N <: Nat](
query: BQSqlFrag,
schema: BQSchema,
description: Option[String] = None
) extends BQPersistentRoutine[N] {
def call(args: Sized[IndexedSeq[BQSqlFrag.Magnet], N]): BQSqlFrag =
) extends BQPersistentRoutine[N, BQSqlFrag.TableRef] {
def call(args: Sized[IndexedSeq[BQSqlFrag.Magnet], N]): BQSqlFrag.TableRef =
BQSqlFrag.TableRef(BQAppliedTableValuedFunction(this, args.map(_.frag)))
}

Expand Down Expand Up @@ -96,12 +96,12 @@ object TVF {
* bqfr"\${myUdf(ident"bar1", ident"bar")}" // compile error
* }}}
*/
sealed trait UDF[+A <: UDFId, N <: Nat] extends BQRoutine[N] {
sealed trait UDF[+A <: UDFId, N <: Nat] extends BQRoutine[N, BQSqlFrag.Call] {
def name: A
def params: BQRoutine.Params[N]
def returnType: Option[BQType]

def call(args: Sized[IndexedSeq[BQSqlFrag.Magnet], N]): BQSqlFrag =
def call(args: Sized[IndexedSeq[BQSqlFrag.Magnet], N]): BQSqlFrag.Call =
BQSqlFrag.Call(this, args.unsized.toList.map(_.frag))
}

Expand Down Expand Up @@ -133,7 +133,7 @@ object UDF {
body: UDF.Body,
returnType: Option[BQType]
) extends UDF[UDFId.PersistentId, N]
with BQPersistentRoutine[N] {
with BQPersistentRoutine[N, BQSqlFrag.Call] {
def convertToTemporary: Temporary[N] =
Temporary(TemporaryId(name.name), params, body, returnType)
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/no/nrk/bigquery/EnsureUpdated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ case class TableDefOperationMeta(
}
case class PersistentRoutineOperationMeta(
routine: RoutineInfo,
persistentRoutine: BQPersistentRoutine[_]
persistentRoutine: BQPersistentRoutine[_, _]
) extends OperationMeta {
override def identifier: String = persistentRoutine.name.asString
}
Expand Down Expand Up @@ -99,7 +99,7 @@ class EnsureUpdated[F[_]](
TableUpdateOperation.from(template, maybeExisting)
}

def check(persistentRoutine: BQPersistentRoutine[_]): F[UpdateOperation] =
def check(persistentRoutine: BQPersistentRoutine[_, _]): F[UpdateOperation] =
bqClient.getRoutine(persistentRoutine.name).map { maybeExisting =>
RoutineUpdateOperation.from(persistentRoutine, maybeExisting)
}
Expand Down
Loading

0 comments on commit 2c1a93e

Please sign in to comment.