Skip to content

Commit

Permalink
fix: mdoc compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ingarabr committed Sep 11, 2023
1 parent 242b0e8 commit e46bd54
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
6 changes: 3 additions & 3 deletions docs/example_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object Schemas {
object UserEventSchema {
private val timestamp: BQField = BQField("timestamp", BQField.Type.TIMESTAMP, BQField.Mode.REQUIRED)
val tableDef: BQTableDef.Table[LocalDate] = BQTableDef.Table(
BQTableId(BQDataset(ProjectId("my-gcp-project"), "prod", Some(LocationId("eu"))), "user_log"),
BQTableId.unsafeOf(BQDataset.unsafeOf(ProjectId.unsafeFromString("my-gcp-project"), "prod", Some(LocationId.EU)), "user_log"),
BQSchema.of(
BQField("eventId", BQField.Type.STRING, BQField.Mode.REQUIRED),
timestamp,
Expand All @@ -36,7 +36,7 @@ object Schemas {
BQField("lastName", BQField.Type.STRING, BQField.Mode.REQUIRED)
)
val tableDef: BQTableDef.Table[Unit] = BQTableDef.Table(
BQTableId.unsafeOf(BQDataset.unsafeOf(ProjectId("my-gcp-project"), "prod").withLocation(LocationId("eu")), "users"),
BQTableId.unsafeOf(BQDataset.unsafeOf(ProjectId.unsafeFromString("my-gcp-project"), "prod").withLocation(LocationId.EU), "users"),
BQSchema.of(
BQField("userId", BQField.Type.STRING, BQField.Mode.REQUIRED),
namesStruct
Expand Down Expand Up @@ -151,7 +151,7 @@ run all tests without getting in to issues like api quotas or cost issued.

Note that we can create illegal queries using `BQSqlFrag`s so it's essential that we write tests for them.

```scala mdoc
```scala
import no.nrk.bigquery.testing.{BQSmokeTest, BigQueryTestClient}
import java.time.LocalDate

Expand Down
10 changes: 5 additions & 5 deletions docs/example_udf.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object MyTemporarySQLUdfs {

val addOneUdf = UDF.temporary(
ident"addOneSqlUdf",
UDF.Param("n", BQType.FLOAT64) :: Nil,
UDF.Params.of(UDF.Param("n", BQType.FLOAT64)),
UDF.Body.Sql(bqfr"""(n + 1)"""),
Some(BQType.FLOAT64)
)
Expand All @@ -32,11 +32,11 @@ import no.nrk.bigquery._
import no.nrk.bigquery.syntax._

object MyPersistentSQLUdfs {
val dataset = BQDataset(ProjectId("my-project"), "ds1", None)
val dataset = BQDataset.unsafeOf(ProjectId.unsafeFromString("my-project"), "ds1", None)
val addOneUdf = UDF.persistent(
ident"addOneSqlUdf",
dataset,
UDF.Param("n", BQType.FLOAT64) :: Nil,
UDF.Params.of(UDF.Param("n", BQType.FLOAT64)),
UDF.Body.Sql(bqfr"""(n + 1)"""),
Some(BQType.FLOAT64)
)
Expand All @@ -57,7 +57,7 @@ object MyJsUdfs {
val jsLibraryGcsPath = List.empty
val addOneUdf = UDF.temporary(
ident"addOneJsUdf",
UDF.Param("n", BQType.FLOAT64) :: Nil,
UDF.Params.of(UDF.Param("n", BQType.FLOAT64)),
UDF.Body.Js("return n + 1", jsLibraryGcsPath),
Some(BQType.FLOAT64)
)
Expand Down Expand Up @@ -85,7 +85,7 @@ val myQuery: BQSqlFrag =

## Testing

```scala mdoc
```scala
import io.circe.Json
import no.nrk.bigquery.testing.{BQUdfSmokeTest, BigQueryTestClient}

Expand Down
13 changes: 7 additions & 6 deletions docs/example_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ Here we have to tables, `my-gcp-project.prod.user_log` and `my-gcp-project.prod.
```scala mdoc
import no.nrk.bigquery._
import no.nrk.bigquery.syntax._
import no.nrk.bigquery.internal.nat._1
import java.time.LocalDate

object Schemas {

object UserEventSchema {
private val timestamp: BQField = BQField("timestamp", BQField.Type.TIMESTAMP, BQField.Mode.REQUIRED)
val tableDef: BQTableDef.Table[LocalDate] = BQTableDef.Table(
BQTableId(BQDataset(ProjectId("my-gcp-project"), "prod", Some(LocationId("eu"))), "user_log"),
BQTableId.unsafeOf(BQDataset.unsafeOf(ProjectId.unsafeFromString("my-gcp-project"), "prod", Some(LocationId.EU)), "user_log"),
BQSchema.of(
BQField("eventId", BQField.Type.STRING, BQField.Mode.REQUIRED),
timestamp,
Expand All @@ -37,17 +38,17 @@ object Schemas {
BQField("lastName", BQField.Type.STRING, BQField.Mode.REQUIRED)
)
val tableDef: BQTableDef.Table[Unit] = BQTableDef.Table(
BQTableId(BQDataset(ProjectId("my-gcp-project"), "prod", Some(LocationId("eu"))), "users"),
BQTableId.unsafeOf(BQDataset.unsafeOf(ProjectId.unsafeFromString("my-gcp-project"), "prod", Some(LocationId.EU)), "users"),
BQSchema.of(
BQField("userId", BQField.Type.STRING, BQField.Mode.REQUIRED),
namesStruct
),
BQPartitionType.NotPartitioned
)

val fullNameUdf: UDF.Temporary = UDF.temporary(
val fullNameUdf: UDF.Temporary[_1] = UDF.temporary(
ident"toFullName",
UDF.Param.fromField(namesStruct) :: Nil,
UDF.Params.of(UDF.Param.fromField(namesStruct)),
UDF.Body.Sql(
bqfr"""(names.firstName || ' ' || coalesce(names.middleName || ' ', '') || names.lastName)""".stripMargin
),
Expand Down Expand Up @@ -86,7 +87,7 @@ object UserEventView {
private val timestamp: BQField = BQField("timestamp", BQField.Type.TIMESTAMP, BQField.Mode.REQUIRED)

val viewDef: BQTableDef.View[LocalDate] = BQTableDef.View(
BQTableId(BQDataset(ProjectId("my-gcp-project"), "prod", Some(LocationId("eu"))), "user_activity_view"),
BQTableId.unsafeOf(BQDataset.unsafeOf(ProjectId.unsafeFromString("my-gcp-project"), "prod", Some(LocationId.EU)), "user_activity_view"),
BQPartitionType.DatePartitioned(timestamp.ident),
query,
BQSchema.of(
Expand All @@ -110,7 +111,7 @@ will be cached in a `generated` folder that should be checked into version contr
version against the generated folder to determine the test it need to rerun using BigQuery. This make it possible to quickly
run all tests without getting in to issues like api quotas or cost issued.

```scala mdoc
```scala
import no.nrk.bigquery.testing.{BQSmokeTest, BigQueryTestClient}

class UserEventViewTest extends BQSmokeTest(BigQueryTestClient.testClient) {
Expand Down
43 changes: 22 additions & 21 deletions docs/struct_projection.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ Let's start with the source struct we want to rewrite from:
import no.nrk.bigquery._
import no.nrk.bigquery.syntax._
import no.nrk.bigquery.util.BqSqlProjection
import com.google.cloud.bigquery.Field.Mode
import com.google.cloud.bigquery.StandardSQLTypeName

val originalStruct: BQField = BQField.struct("foo", Mode.NULLABLE)(
BQField("keep_me", StandardSQLTypeName.STRING, Mode.NULLABLE),
BQField("drop_me", StandardSQLTypeName.STRING, Mode.NULLABLE),
BQField("rename_me", StandardSQLTypeName.STRING, Mode.NULLABLE),
BQField.struct("keep_original_struct", Mode.NULLABLE)(
BQField("one", StandardSQLTypeName.STRING, Mode.NULLABLE),
BQField("two", StandardSQLTypeName.STRING, Mode.NULLABLE)
val originalStruct: BQField = BQField.struct("foo", BQField.Mode.NULLABLE)(
BQField("keep_me", BQField.Type.STRING, BQField.Mode.NULLABLE),
BQField("drop_me", BQField.Type.STRING, BQField.Mode.NULLABLE),
BQField("rename_me", BQField.Type.STRING, BQField.Mode.NULLABLE),
BQField.struct("keep_original_struct", BQField.Mode.NULLABLE)(
BQField("one", BQField.Type.STRING, BQField.Mode.NULLABLE),
BQField("two", BQField.Type.STRING, BQField.Mode.NULLABLE)
),
BQField.struct("flatten_struct", Mode.NULLABLE)(
BQField("one", StandardSQLTypeName.STRING, Mode.NULLABLE),
BQField("two", StandardSQLTypeName.STRING, Mode.NULLABLE)
BQField.struct("flatten_struct", BQField.Mode.NULLABLE)(
BQField("one", BQField.Type.STRING, BQField.Mode.NULLABLE),
BQField("two", BQField.Type.STRING, BQField.Mode.NULLABLE)
)
)
```
Expand All @@ -32,15 +31,15 @@ In this example we have named them based on the action we want to project on the
struct should be:

```scala mdoc
val projectedStruct: BQField = BQField.struct("foo", Mode.NULLABLE)(
BQField("keep_me", StandardSQLTypeName.STRING, Mode.NULLABLE),
BQField("renamed", StandardSQLTypeName.STRING, Mode.NULLABLE),
BQField.struct("keep_original_struct", Mode.NULLABLE)(
BQField("one", StandardSQLTypeName.STRING, Mode.NULLABLE),
BQField("two", StandardSQLTypeName.STRING, Mode.NULLABLE)
val projectedStruct: BQField = BQField.struct("foo", BQField.Mode.NULLABLE)(
BQField("keep_me", BQField.Type.STRING, BQField.Mode.NULLABLE),
BQField("renamed", BQField.Type.STRING, BQField.Mode.NULLABLE),
BQField.struct("keep_original_struct", BQField.Mode.NULLABLE)(
BQField("one", BQField.Type.STRING, BQField.Mode.NULLABLE),
BQField("two", BQField.Type.STRING, BQField.Mode.NULLABLE)
),
BQField("barOne", StandardSQLTypeName.STRING, Mode.NULLABLE),
BQField("barTwo", StandardSQLTypeName.STRING, Mode.NULLABLE)
BQField("barOne", BQField.Type.STRING, BQField.Mode.NULLABLE),
BQField("barTwo", BQField.Type.STRING, BQField.Mode.NULLABLE)
)
```

Expand All @@ -63,7 +62,7 @@ Let's start with the source table:
```scala mdoc
val originTable: BQTableDef.Table[Unit] =
BQTableDef.Table(
BQTableId(BQDataset(ProjectId("p1"), "d1", None), "table_1"),
BQTableId.unsafeOf(BQDataset.unsafeOf(ProjectId.unsafeFromString("example-project"), "d1", None), "table_1"),
BQSchema.of(originalStruct),
BQPartitionType.NotPartitioned
)
Expand All @@ -84,12 +83,14 @@ import no.nrk.bigquery.testing.{BQSmokeTest, BigQueryTestClient}

val view1: BQTableDef.View[Unit] =
BQTableDef.View(
BQTableId(BQDataset(ProjectId("p1"), "d1", None), "view_1"),
BQTableId.unsafeOf(BQDataset.unsafeOf(ProjectId.unsafeFromString("example-project"), "d1", None), "view_1"),
BQPartitionType.NotPartitioned,
query,
BQSchema.of(projectedStruct)
)
```

```scala
class View1Test extends BQSmokeTest(BigQueryTestClient.testClient) {
bqCheckViewTest("project a struct 2", view1)
}
Expand Down

0 comments on commit e46bd54

Please sign in to comment.