diff --git a/core/src/main/scala/no/nrk/bigquery/UDF.scala b/core/src/main/scala/no/nrk/bigquery/UDF.scala index 876ada3c..29b39ff3 100644 --- a/core/src/main/scala/no/nrk/bigquery/UDF.scala +++ b/core/src/main/scala/no/nrk/bigquery/UDF.scala @@ -6,14 +6,28 @@ import cats.Show import no.nrk.bigquery.UDF._ import no.nrk.bigquery.UDF.UDFId._ import no.nrk.bigquery.syntax._ -import shapeless.{Nat, Sized, SizedBuilder, _0} - +import shapeless.{Nat, Sized, SizedBuilder} +import shapeless.nat. _0 + +/** The UDF has an apply method rendering a BQSqlFrag that matches the size of `params`. + * + * ``` + * val myUdf = + * UDF.temporary( + * ident"myUdf", + * UDF.Params.of(UDF.Param("foo", BQType.STRING)), + * UDF.Body.SQL(bqfr"(foo)"), + * Some(BQType.STRING) + * ) + * bqfr"${myUdf(ident"bar")}" // ok + * bqfr"${myUdf()}" // compile error + * bqfr"${myUdf(ident"bar1", ident"bar")}" // compile error + * ``` + */ sealed trait UDF[+A <: UDFId, N <: Nat] { def name: A - def params: Sized[Seq[UDF.Param], N] + def params: Sized[IndexedSeq[UDF.Param], N] def returnType: Option[BQType] - def apply(args: Sized[Seq[BQSqlFrag.Magnet], N]): BQSqlFrag.Call = - BQSqlFrag.Call(this, args.unsized.toList.map(_.frag)) } object UDF { @@ -21,9 +35,8 @@ object UDF { object Params { val empty: Sized[IndexedSeq[UDF.Param], _0] = Sized.wrap[IndexedSeq[UDF.Param], _0](IndexedSeq.empty[UDF.Param]) - def apply = new SizedBuilder[ - IndexedSeq - ]() // todo: figure out why we need to explicit call apply. Might be related to the type alias + // todo: figure out why we need to explicit call apply. Might be related to the type alias + def apply = new SizedBuilder[IndexedSeq]() def of = new SizedBuilder[IndexedSeq]() } diff --git a/core/src/main/scala/no/nrk/bigquery/internal/BQShowSyntax.scala b/core/src/main/scala/no/nrk/bigquery/internal/BQShowSyntax.scala index e0b860e3..013eb34d 100644 --- a/core/src/main/scala/no/nrk/bigquery/internal/BQShowSyntax.scala +++ b/core/src/main/scala/no/nrk/bigquery/internal/BQShowSyntax.scala @@ -1,13 +1,12 @@ package no.nrk.bigquery.internal -import no.nrk.bigquery.{BQFill, BQFilledTable, BQShow, BQSqlFrag, UDF} +import no.nrk.bigquery.{BQFill, BQFilledTable, BQShow, BQSqlFrag} import cats.Foldable import cats.syntax.all._ -import shapeless._0 import java.time.LocalDate -trait BQShowSyntax { +trait BQShowSyntax extends UdfSyntax { implicit def bqShowInterpolator(sc: StringContext): BQShow.BQShowInterpolator = new BQShow.BQShowInterpolator(sc) implicit def bqShowOps[A](a: A): BQShowOps[A] = new BQShowOps[A](a) @@ -15,15 +14,6 @@ trait BQShowSyntax { implicit def bqFilledTableLocalDateOps(fill: BQFilledTable[LocalDate]): BQFilledTableLocalDateOps = new BQFilledTableLocalDateOps(fill) - implicit def bqUdfOps(udf: UDF[UDF.UDFId, _0]): UdfOps = new UdfOps(udf) -} - -/** Makes it possible to call UDFs with no arguments. Shapeless Sized does not by default have an empty instance and we - * do not want to clutter the api with it. - */ -// todo: consider if we should create apply methods matching the Nat class. Then we do not need to think about the Sized instance -class UdfOps(udf: UDF[UDF.UDFId, _0]) { - def apply(): BQSqlFrag.Call = BQSqlFrag.Call(udf, List.empty) } class BQShowOps[A](a: A) { diff --git a/core/src/main/scala/no/nrk/bigquery/internal/UdfSyntax.scala b/core/src/main/scala/no/nrk/bigquery/internal/UdfSyntax.scala new file mode 100644 index 00000000..ae8dde55 --- /dev/null +++ b/core/src/main/scala/no/nrk/bigquery/internal/UdfSyntax.scala @@ -0,0 +1,716 @@ +package no.nrk.bigquery.internal + +import no.nrk.bigquery.{BQSqlFrag, UDF} +import shapeless.nat._ + +trait UdfSyntax { + implicit def bqUdfOps0(udf: UDF[UDF.UDFId, _0]): UdfOps0 = new UdfOps0(udf) + implicit def bqUdfOps1(udf: UDF[UDF.UDFId, _1]): UdfOps1 = new UdfOps1(udf) + implicit def bqUdfOps2(udf: UDF[UDF.UDFId, _2]): UdfOps2 = new UdfOps2(udf) + implicit def bqUdfOps3(udf: UDF[UDF.UDFId, _3]): UdfOps3 = new UdfOps3(udf) + implicit def bqUdfOps4(udf: UDF[UDF.UDFId, _4]): UdfOps4 = new UdfOps4(udf) + implicit def bqUdfOps5(udf: UDF[UDF.UDFId, _5]): UdfOps5 = new UdfOps5(udf) + implicit def bqUdfOps6(udf: UDF[UDF.UDFId, _6]): UdfOps6 = new UdfOps6(udf) + implicit def bqUdfOps7(udf: UDF[UDF.UDFId, _7]): UdfOps7 = new UdfOps7(udf) + implicit def bqUdfOps8(udf: UDF[UDF.UDFId, _8]): UdfOps8 = new UdfOps8(udf) + implicit def bqUdfOps9(udf: UDF[UDF.UDFId, _9]): UdfOps9 = new UdfOps9(udf) + implicit def bqUdfOps10(udf: UDF[UDF.UDFId, _10]): UdfOps10 = new UdfOps10(udf) + implicit def bqUdfOps11(udf: UDF[UDF.UDFId, _11]): UdfOps11 = new UdfOps11(udf) + implicit def bqUdfOps12(udf: UDF[UDF.UDFId, _12]): UdfOps12 = new UdfOps12(udf) + implicit def bqUdfOps13(udf: UDF[UDF.UDFId, _13]): UdfOps13 = new UdfOps13(udf) + implicit def bqUdfOps14(udf: UDF[UDF.UDFId, _14]): UdfOps14 = new UdfOps14(udf) + implicit def bqUdfOps15(udf: UDF[UDF.UDFId, _15]): UdfOps15 = new UdfOps15(udf) + implicit def bqUdfOps16(udf: UDF[UDF.UDFId, _16]): UdfOps16 = new UdfOps16(udf) + implicit def bqUdfOps17(udf: UDF[UDF.UDFId, _17]): UdfOps17 = new UdfOps17(udf) + implicit def bqUdfOps18(udf: UDF[UDF.UDFId, _18]): UdfOps18 = new UdfOps18(udf) + implicit def bqUdfOps19(udf: UDF[UDF.UDFId, _19]): UdfOps19 = new UdfOps19(udf) + implicit def bqUdfOps20(udf: UDF[UDF.UDFId, _20]): UdfOps20 = new UdfOps20(udf) + implicit def bqUdfOps21(udf: UDF[UDF.UDFId, _21]): UdfOps21 = new UdfOps21(udf) + implicit def bqUdfOps22(udf: UDF[UDF.UDFId, _22]): UdfOps22 = new UdfOps22(udf) +} + +class UdfOps0(udf: UDF[UDF.UDFId, _0]) { + def apply(): BQSqlFrag.Call = BQSqlFrag.Call(udf, List.empty) +} + +class UdfOps1(udf: UDF[UDF.UDFId, _1]) { + def apply( + m1: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1 + ).map(_.frag)) +} + +class UdfOps2(udf: UDF[UDF.UDFId, _2]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2 + ).map(_.frag)) +} + +class UdfOps3(udf: UDF[UDF.UDFId, _3]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3 + ).map(_.frag)) +} + +class UdfOps4(udf: UDF[UDF.UDFId, _4]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4 + ).map(_.frag)) +} + +class UdfOps5(udf: UDF[UDF.UDFId, _5]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5 + ).map(_.frag)) +} + +class UdfOps6(udf: UDF[UDF.UDFId, _6]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6 + ).map(_.frag)) +} + +class UdfOps7(udf: UDF[UDF.UDFId, _7]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7 + ).map(_.frag)) +} + +class UdfOps8(udf: UDF[UDF.UDFId, _8]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8 + ).map(_.frag)) +} + +class UdfOps9(udf: UDF[UDF.UDFId, _9]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9 + ).map(_.frag)) +} + +class UdfOps10(udf: UDF[UDF.UDFId, _10]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10 + ).map(_.frag)) +} + +class UdfOps11(udf: UDF[UDF.UDFId, _11]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet, + m11: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11 + ).map(_.frag)) +} + +class UdfOps12(udf: UDF[UDF.UDFId, _12]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet, + m11: BQSqlFrag.Magnet, + m12: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12 + ).map(_.frag)) +} + +class UdfOps13(udf: UDF[UDF.UDFId, _13]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet, + m11: BQSqlFrag.Magnet, + m12: BQSqlFrag.Magnet, + m13: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13 + ).map(_.frag)) +} + +class UdfOps14(udf: UDF[UDF.UDFId, _14]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet, + m11: BQSqlFrag.Magnet, + m12: BQSqlFrag.Magnet, + m13: BQSqlFrag.Magnet, + m14: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14 + ).map(_.frag)) +} + +class UdfOps15(udf: UDF[UDF.UDFId, _15]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet, + m11: BQSqlFrag.Magnet, + m12: BQSqlFrag.Magnet, + m13: BQSqlFrag.Magnet, + m14: BQSqlFrag.Magnet, + m15: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15 + ).map(_.frag)) +} + +class UdfOps16(udf: UDF[UDF.UDFId, _16]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet, + m11: BQSqlFrag.Magnet, + m12: BQSqlFrag.Magnet, + m13: BQSqlFrag.Magnet, + m14: BQSqlFrag.Magnet, + m15: BQSqlFrag.Magnet, + m16: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16 + ).map(_.frag)) +} + +class UdfOps17(udf: UDF[UDF.UDFId, _17]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet, + m11: BQSqlFrag.Magnet, + m12: BQSqlFrag.Magnet, + m13: BQSqlFrag.Magnet, + m14: BQSqlFrag.Magnet, + m15: BQSqlFrag.Magnet, + m16: BQSqlFrag.Magnet, + m17: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16, + m17 + ).map(_.frag)) +} + +class UdfOps18(udf: UDF[UDF.UDFId, _18]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet, + m11: BQSqlFrag.Magnet, + m12: BQSqlFrag.Magnet, + m13: BQSqlFrag.Magnet, + m14: BQSqlFrag.Magnet, + m15: BQSqlFrag.Magnet, + m16: BQSqlFrag.Magnet, + m17: BQSqlFrag.Magnet, + m18: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16, + m17, + m18 + ).map(_.frag)) +} + +class UdfOps19(udf: UDF[UDF.UDFId, _19]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet, + m11: BQSqlFrag.Magnet, + m12: BQSqlFrag.Magnet, + m13: BQSqlFrag.Magnet, + m14: BQSqlFrag.Magnet, + m15: BQSqlFrag.Magnet, + m16: BQSqlFrag.Magnet, + m17: BQSqlFrag.Magnet, + m18: BQSqlFrag.Magnet, + m19: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16, + m17, + m18, + m19 + ).map(_.frag)) +} + +class UdfOps20(udf: UDF[UDF.UDFId, _20]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet, + m11: BQSqlFrag.Magnet, + m12: BQSqlFrag.Magnet, + m13: BQSqlFrag.Magnet, + m14: BQSqlFrag.Magnet, + m15: BQSqlFrag.Magnet, + m16: BQSqlFrag.Magnet, + m17: BQSqlFrag.Magnet, + m18: BQSqlFrag.Magnet, + m19: BQSqlFrag.Magnet, + m20: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16, + m17, + m18, + m19, + m20 + ).map(_.frag)) +} + +class UdfOps21(udf: UDF[UDF.UDFId, _21]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet, + m11: BQSqlFrag.Magnet, + m12: BQSqlFrag.Magnet, + m13: BQSqlFrag.Magnet, + m14: BQSqlFrag.Magnet, + m15: BQSqlFrag.Magnet, + m16: BQSqlFrag.Magnet, + m17: BQSqlFrag.Magnet, + m18: BQSqlFrag.Magnet, + m19: BQSqlFrag.Magnet, + m20: BQSqlFrag.Magnet, + m21: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16, + m17, + m18, + m19, + m20, + m21 + ).map(_.frag)) +} + +class UdfOps22(udf: UDF[UDF.UDFId, _22]) { + def apply( + m1: BQSqlFrag.Magnet, + m2: BQSqlFrag.Magnet, + m3: BQSqlFrag.Magnet, + m4: BQSqlFrag.Magnet, + m5: BQSqlFrag.Magnet, + m6: BQSqlFrag.Magnet, + m7: BQSqlFrag.Magnet, + m8: BQSqlFrag.Magnet, + m9: BQSqlFrag.Magnet, + m10: BQSqlFrag.Magnet, + m11: BQSqlFrag.Magnet, + m12: BQSqlFrag.Magnet, + m13: BQSqlFrag.Magnet, + m14: BQSqlFrag.Magnet, + m15: BQSqlFrag.Magnet, + m16: BQSqlFrag.Magnet, + m17: BQSqlFrag.Magnet, + m18: BQSqlFrag.Magnet, + m19: BQSqlFrag.Magnet, + m20: BQSqlFrag.Magnet, + m21: BQSqlFrag.Magnet, + m22: BQSqlFrag.Magnet + ): BQSqlFrag.Call = BQSqlFrag.Call( + udf, + List( + m1, + m2, + m3, + m4, + m5, + m6, + m7, + m8, + m9, + m10, + m11, + m12, + m13, + m14, + m15, + m16, + m17, + m18, + m19, + m20, + m21, + m22 + ).map(_.frag)) +} diff --git a/core/src/main/scala/no/nrk/bigquery/internal/UdfUpdateOperation.scala b/core/src/main/scala/no/nrk/bigquery/internal/UdfUpdateOperation.scala index 8dff024f..b0fd4163 100644 --- a/core/src/main/scala/no/nrk/bigquery/internal/UdfUpdateOperation.scala +++ b/core/src/main/scala/no/nrk/bigquery/internal/UdfUpdateOperation.scala @@ -29,7 +29,7 @@ object UdfUpdateOperation { val baseBuilder = RoutineInfo .newBuilder(toRoutineId(udf.name)) .setRoutineType(UdfRoutineType) - .setArguments(udf.params.map(toRoutineArgs).asJava) + .setArguments(udf.params.unsized.map(toRoutineArgs).asJava) .setReturnType(udf.returnType.map(toSqlDataType).orNull) (udf.body match { diff --git a/core/src/test/scala/no/nrk/bigquery/BQSqlFragTest.scala b/core/src/test/scala/no/nrk/bigquery/BQSqlFragTest.scala index efaf2bc1..a29cc772 100644 --- a/core/src/test/scala/no/nrk/bigquery/BQSqlFragTest.scala +++ b/core/src/test/scala/no/nrk/bigquery/BQSqlFragTest.scala @@ -4,7 +4,6 @@ import cats.syntax.all._ import munit.FunSuite import no.nrk.bigquery.BQPartitionType.DatePartitioned import no.nrk.bigquery.syntax._ -import shapeless.Sized import java.time.LocalDate @@ -23,7 +22,7 @@ class BQSqlFragTest extends FunSuite { Some(BQType.INT64)) test("collect nested UDFs") { - val udfIdents = bqfr"select ${udfToString(Sized(udfAddOne(Sized(bqfr"1"))))}" + val udfIdents = bqfr"select ${udfToString(udfAddOne(bqfr"1"))}" .collect { case BQSqlFrag.Call(udf, _) => udf } .map(_.name) .sortBy(_.show) @@ -45,11 +44,11 @@ class BQSqlFragTest extends FunSuite { val outerUdf = UDF.temporary( Ident("aa"), UDF.Params.of(UDF.Param("input", BQType.INT64)), - UDF.Body.Sql(bqsql"(${innerUdf1(Sized(ident"input"))} / ${innerUdf2(Sized(bqfr"2"))})"), + UDF.Body.Sql(bqsql"(${innerUdf1(ident"input")} / ${innerUdf2(bqfr"2")})"), Some(BQType.FLOAT64) ) - val udfIdents = bqsql"select ${outerUdf(Sized(1))}" + val udfIdents = bqsql"select ${outerUdf(1)}" .collect { case BQSqlFrag.Call(udf, _) => udf } .map(_.name) @@ -92,12 +91,12 @@ class BQSqlFragTest extends FunSuite { Some(BQType.FLOAT64)) val fill2 = - BQFill(JobKey("hello2"), mkTable("bree"), bqsql"select ${outerUdf2(Sized(1))}", LocalDate.of(2023, 1, 1)) + BQFill(JobKey("hello2"), mkTable("bree"), bqsql"select ${outerUdf2(1)}", LocalDate.of(2023, 1, 1)) val fill1 = BQFill( JobKey("hello"), mkTable("baz"), - bqsql"select ${outerUdf1(Sized(1))} from $fill2", + bqsql"select ${outerUdf1(1)} from $fill2", LocalDate.of(2023, 1, 1) ) diff --git a/core/src/test/scala/no/nrk/bigquery/UDFTest.scala b/core/src/test/scala/no/nrk/bigquery/UDFTest.scala index efb132ca..a253ee0a 100644 --- a/core/src/test/scala/no/nrk/bigquery/UDFTest.scala +++ b/core/src/test/scala/no/nrk/bigquery/UDFTest.scala @@ -2,7 +2,7 @@ package no.nrk.bigquery import munit.FunSuite import no.nrk.bigquery.syntax._ -import shapeless.{Sized, _0} +import shapeless._0 class UDFTest extends FunSuite { @@ -90,11 +90,11 @@ class UDFTest extends FunSuite { val udf = UDF .temporary( ident"fnName", - Sized(UDF.Param("n", BQType.FLOAT64)), + UDF.Params.of(UDF.Param("n", BQType.FLOAT64)), UDF.Body.Js("return n + 1", List("bucket/foo.js")), Some(BQType.FLOAT64) ) - assertEquals(bqfr"${udf(Sized(1d))}".asString, "fnName(1.0)") + assertEquals(bqfr"${udf(1d)}".asString, "fnName(1.0)") } test("render persistent call") { @@ -107,7 +107,7 @@ class UDFTest extends FunSuite { Some(BQType.FLOAT64) ) - assertEquals(bqfr"${udf(Sized(1d))}".asString, "`p1.ds1.fnName`(1.0)") + assertEquals(bqfr"${udf(1d)}".asString, "`p1.ds1.fnName`(1.0)") } test("render udf ref call") { @@ -118,7 +118,7 @@ class UDFTest extends FunSuite { Some(BQType.FLOAT64) ) - assertEquals(bqfr"${udf.apply(Sized(1d))}".asString, "`p1.ds1.fnName`(1.0)") + assertEquals(bqfr"${udf.apply(1d)}".asString, "`p1.ds1.fnName`(1.0)") } } diff --git a/testing/src/test/scala/no/nrk/bigquery/LiveTempUdfTest.scala b/testing/src/test/scala/no/nrk/bigquery/LiveTempUdfTest.scala index b9240886..554520a0 100644 --- a/testing/src/test/scala/no/nrk/bigquery/LiveTempUdfTest.scala +++ b/testing/src/test/scala/no/nrk/bigquery/LiveTempUdfTest.scala @@ -2,7 +2,6 @@ package no.nrk.bigquery import no.nrk.bigquery.syntax._ import no.nrk.bigquery.testing.{BQSmokeTest, BigQueryTestClient} -import shapeless.Sized class LiveTempUdfTest extends BQSmokeTest(BigQueryTestClient.testClient) { val udf1 = UDF.temporary( @@ -13,10 +12,10 @@ class LiveTempUdfTest extends BQSmokeTest(BigQueryTestClient.testClient) { val udf2 = UDF.temporary( Ident("half_TMP"), UDF.Params.of(UDF.Param("input", BQType.INT64)), - UDF.Body.Sql(bqsql"(${udf1(Sized(Ident("input")))} / 2)"), + UDF.Body.Sql(bqsql"(${udf1(Ident("input"))} / 2)"), Some(BQType.FLOAT64)) bqTypeCheckTest("query with UDF") { - BQQuery[Double](bqsql"select ${udf2(Sized(1))}") + BQQuery[Double](bqsql"select ${udf2(1)}") } }