Skip to content

Commit

Permalink
New case class WholeTable, so we can reference a table and keep parti…
Browse files Browse the repository at this point in the history
…tioning info in query.
  • Loading branch information
HenningKoller committed Jul 12, 2023
1 parent e8f3946 commit df3d64f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions core/src/main/scala/no/nrk/bigquery/BQShow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ trait BQShowInstances {
implicit def bqShowTablesLike[I[t] <: Iterable[t], T <: BQTableLike[Unit]]: BQShow[I[T]] =
tables => BQSqlFrag.Combined(tables.map(_.assertPartition.bqShow).toSeq)

implicit def bqShowWholeTable[P]: BQShow[WholeTable[P]] = x => BQSqlFrag.TableRef(x.table)

implicit def bqShowFill[Fill <: BQFill[Any]]: BQShow[Fill] =
BQSqlFrag.FillRef.apply

Expand Down
9 changes: 6 additions & 3 deletions core/src/main/scala/no/nrk/bigquery/BQSqlFrag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ sealed trait BQSqlFrag {
}

case BQSqlFrag.TableRef(table) =>
outerRef match {
case Some(partitionRef: BQPartitionId.DatePartitioned) => List(table.assertPartition(partitionRef.partition))
(table, outerRef) match {
case (t: BQTableRef[LocalDate], Some(partitionRef: BQPartitionId.DatePartitioned)) =>
List(t.assertPartition(partitionRef.partition))
case (t: BQTableDef[LocalDate], Some(partitionRef: BQPartitionId.DatePartitioned)) =>
List(t.assertPartition(partitionRef.partition))
case _ => List(table.unpartitioned.assertPartition)
}

Expand Down Expand Up @@ -174,7 +177,7 @@ object BQSqlFrag {
)
}
case class Combined(values: Seq[BQSqlFrag]) extends BQSqlFrag
case class TableRef(table: BQTableLike[LocalDate]) extends BQSqlFrag
case class TableRef(table: BQTableLike[_]) extends BQSqlFrag
case class PartitionRef(ref: BQPartitionId[Any]) extends BQSqlFrag

case class FillRef(fill: BQFill[Any]) extends BQSqlFrag
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/scala/no/nrk/bigquery/BQTableLike.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ sealed trait BQTableLike[+P] {
def partitionType: BQPartitionType[P]
def withTableType[PP](tpe: BQPartitionType[PP]): BQTableLike[PP]
def unpartitioned: BQTableLike[Unit]
def asWholeTable: WholeTable[P] = WholeTable(this)
}

object BQTableLike {
Expand Down Expand Up @@ -96,6 +97,8 @@ sealed trait BQTableDef[+P] extends BQTableLike[P] {
labels.verify(tableId)
}

case class WholeTable[+P](table: BQTableLike[P])

object BQTableDef {

/** @param schema
Expand Down

0 comments on commit df3d64f

Please sign in to comment.