Skip to content

Commit

Permalink
Merge pull request #203 from nrkno/fix/bqtype-array-format
Browse files Browse the repository at this point in the history
fix: bqshow on bqtype for array
  • Loading branch information
ingarabr authored Oct 23, 2023
2 parents c4ea8ea + 1ba3c43 commit b5d27f2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/scala/no/nrk/bigquery/BQType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ object BQType {
case f if f.tpe == BQField.Type.STRUCT =>
s"STRUCT<${f.subFields.map { case (name, sf) => s"$name ${format(sf)}" }.mkString(", ")}>"
case f if f.tpe == BQField.Type.ARRAY =>
s"ARRAY(${format(f.subFields.head._2)})"
s"ARRAY<${format(f.subFields.head._2)}>"
case other if f.mode == BQField.Mode.REPEATED =>
s"ARRAY<${other.tpe.name}>"
case other =>
Expand Down
43 changes: 43 additions & 0 deletions core/src/test/scala/no/nrk/bigquery/BQTypeTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2020 NRK
*
* SPDX-License-Identifier: MIT
*/

package no.nrk.bigquery

import munit.FunSuite
import no.nrk.bigquery.syntax._

class BQTypeTest extends FunSuite {

test("format array") {
assertEquals(
BQType(BQField.Mode.REQUIRED, BQField.Type.ARRAY, List("" -> BQType.STRING)).bqShow,
bqfr"ARRAY<STRING>")
assertEquals(BQType.STRING.repeated.bqShow, bqfr"ARRAY<STRING>")
assertEquals(BQType.struct("foo" -> BQType.STRING).repeated.bqShow, bqfr"ARRAY<STRUCT<foo STRING>>")
}

test("format raw types") {
assertEquals(BQType.BOOL.nullable.bqShow, bqfr"BOOL")
assertEquals(BQType.INT64.nullable.bqShow, bqfr"INT64")
assertEquals(BQType.STRING.nullable.bqShow, bqfr"STRING")
}

test("format structs") {
assertEquals(
BQType.struct("s" -> BQType.STRING, "b" -> BQType.BOOL).bqShow,
bqfr"STRUCT<s STRING, b BOOL>"
)
assertEquals(
BQType.struct("s" -> BQType.STRING, "b" -> BQType.BOOL).repeated.nullable.bqShow,
bqfr"STRUCT<s STRING, b BOOL>")
}

test("format dictionaries") {
assertEquals(BQType.StringDictionary.bqShow, bqfr"ARRAY<STRUCT<index INT64, value STRING>>")
assertEquals(BQType.NumberDictionary.bqShow, bqfr"ARRAY<STRUCT<index INT64, value INT64>>")
}

}

0 comments on commit b5d27f2

Please sign in to comment.