From 1ba3c43e2457bfaa1c8019e4ad3eb5cd80721573 Mon Sep 17 00:00:00 2001 From: Ingar Abrahamsen Date: Mon, 23 Oct 2023 14:59:39 +0200 Subject: [PATCH] fix: bqshow on bqtype for array --- .../main/scala/no/nrk/bigquery/BQType.scala | 2 +- .../scala/no/nrk/bigquery/BQTypeTest.scala | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 core/src/test/scala/no/nrk/bigquery/BQTypeTest.scala diff --git a/core/src/main/scala/no/nrk/bigquery/BQType.scala b/core/src/main/scala/no/nrk/bigquery/BQType.scala index d490275d..77c95d72 100644 --- a/core/src/main/scala/no/nrk/bigquery/BQType.scala +++ b/core/src/main/scala/no/nrk/bigquery/BQType.scala @@ -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 => diff --git a/core/src/test/scala/no/nrk/bigquery/BQTypeTest.scala b/core/src/test/scala/no/nrk/bigquery/BQTypeTest.scala new file mode 100644 index 00000000..99d29324 --- /dev/null +++ b/core/src/test/scala/no/nrk/bigquery/BQTypeTest.scala @@ -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") + assertEquals(BQType.STRING.repeated.bqShow, bqfr"ARRAY") + assertEquals(BQType.struct("foo" -> BQType.STRING).repeated.bqShow, bqfr"ARRAY>") + } + + 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" + ) + assertEquals( + BQType.struct("s" -> BQType.STRING, "b" -> BQType.BOOL).repeated.nullable.bqShow, + bqfr"STRUCT") + } + + test("format dictionaries") { + assertEquals(BQType.StringDictionary.bqShow, bqfr"ARRAY>") + assertEquals(BQType.NumberDictionary.bqShow, bqfr"ARRAY>") + } + +}