diff --git a/integration/src/test/scala/com/spotify/scio/bigquery/types/BigQueryStorageIT.scala b/integration/src/test/scala/com/spotify/scio/bigquery/types/BigQueryStorageIT.scala index 7affc8bfd6..d2a8f66551 100644 --- a/integration/src/test/scala/com/spotify/scio/bigquery/types/BigQueryStorageIT.scala +++ b/integration/src/test/scala/com/spotify/scio/bigquery/types/BigQueryStorageIT.scala @@ -49,7 +49,9 @@ class BigQueryStorageIT extends AnyFlatSpec with Matchers { t.plus(Duration.millis(i.toLong)), dt.toLocalDate.plusDays(i), dt.toLocalTime.plusMillis(i), - dt.toLocalDateTime.plusMillis(i) + dt.toLocalDateTime.plusMillis(i), + s"POINT($i $i)", // geography is not an avro logical type + s"""{"value":$i}""" // json is not an avro logical type ) }.asJava val (sc, _) = ContextAndArgs( @@ -74,7 +76,9 @@ class BigQueryStorageIT extends AnyFlatSpec with Matchers { Some(t.plus(Duration.millis(i.toLong))), Some(dt.toLocalDate.plusDays(i)), Some(dt.toLocalTime.plusMillis(i)), - Some(dt.toLocalDateTime.plusMillis(i)) + Some(dt.toLocalDateTime.plusMillis(i)), + Some(s"POINT($i $i)"), // geography is not an avro logical type + Some(s"""{"value":$i}""") // json is not an avro logical type ) }.asJava val (sc, _) = ContextAndArgs( @@ -99,7 +103,9 @@ class BigQueryStorageIT extends AnyFlatSpec with Matchers { List(t.plus(Duration.millis(i.toLong))), List(dt.toLocalDate.plusDays(i)), List(dt.toLocalTime.plusMillis(i)), - List(dt.toLocalDateTime.plusMillis(i)) + List(dt.toLocalDateTime.plusMillis(i)), + List(s"POINT($i $i)"), // geography is not an avro logical type + List(s"""{"value":$i}""") // json is not an avro logical type ) }.asJava val (sc, _) = ContextAndArgs( @@ -184,7 +190,9 @@ class BigQueryStorageIT extends AnyFlatSpec with Matchers { Some(t.plus(Duration.millis(i.toLong))), Some(dt.toLocalDate.plusDays(i)), Some(dt.toLocalTime.plusMillis(i)), - Some(dt.toLocalDateTime.plusMillis(i)) + Some(dt.toLocalDateTime.plusMillis(i)), + Some(Geography(s"POINT($i $i)")), + Some(Json(s"""{"value":$i}""")) ) }.asJava val (sc, _) = ContextAndArgs( @@ -211,7 +219,9 @@ class BigQueryStorageIT extends AnyFlatSpec with Matchers { t.plus(Duration.millis(i.toLong)), dt.toLocalDate.plusDays(i), dt.toLocalTime.plusMillis(i), - dt.toLocalDateTime.plusMillis(i) + dt.toLocalDateTime.plusMillis(i), + Geography(s"POINT($i $i)"), + Json(s"""{"value":$i}""") ) }.asJava val (sc, _) = ContextAndArgs( @@ -248,7 +258,9 @@ class BigQueryStorageIT extends AnyFlatSpec with Matchers { Some(t.plus(Duration.millis(i.toLong))), Some(dt.toLocalDate.plusDays(i)), Some(dt.toLocalTime.plusMillis(i)), - Some(dt.toLocalDateTime.plusMillis(i)) + Some(dt.toLocalDateTime.plusMillis(i)), + Some(Geography(s"POINT($i $i)")), + Some(Json(s"""{"value":$i}""")) ) }.asJava val (sc, _) = ContextAndArgs( diff --git a/scio-google-cloud-platform/src/main/scala/com/spotify/scio/bigquery/types/TypeProvider.scala b/scio-google-cloud-platform/src/main/scala/com/spotify/scio/bigquery/types/TypeProvider.scala index f1d865ede8..28744e3629 100644 --- a/scio-google-cloud-platform/src/main/scala/com/spotify/scio/bigquery/types/TypeProvider.scala +++ b/scio-google-cloud-platform/src/main/scala/com/spotify/scio/bigquery/types/TypeProvider.scala @@ -262,31 +262,31 @@ private[types] object TypeProvider { val provider: OverrideTypeProvider = OverrideTypeProviderFinder.getProvider // Returns: (raw type, e.g. Int, String, NestedRecord, nested case class definitions) - def getRawType(tfs: TableFieldSchema): (Tree, Seq[Tree]) = + def getRawType(tfs: TableFieldSchema): (Tree, Seq[Tree]) = { + // format: off tfs.getType match { - case _ if provider.shouldOverrideType(tfs) => - (provider.getScalaType(c)(tfs), Nil) - case "BOOLEAN" | "BOOL" => (tq"_root_.scala.Boolean", Nil) - case "INTEGER" | "INT64" => (tq"_root_.scala.Long", Nil) - case "FLOAT" | "FLOAT64" => (tq"_root_.scala.Double", Nil) - case "STRING" => (tq"_root_.java.lang.String", Nil) - case "NUMERIC" => (tq"_root_.scala.BigDecimal", Nil) - case "BIGNUMERIC" => (tq"_root_.scala.BigDecimal", Nil) - case "BYTES" => (tq"_root_.com.google.protobuf.ByteString", Nil) - case "TIMESTAMP" => (tq"_root_.org.joda.time.Instant", Nil) - case "DATE" => (tq"_root_.org.joda.time.LocalDate", Nil) - case "TIME" => (tq"_root_.org.joda.time.LocalTime", Nil) - case "DATETIME" => (tq"_root_.org.joda.time.LocalDateTime", Nil) - case "GEOGRAPHY" => - (tq"_root_.com.spotify.scio.bigquery.types.Geography", Nil) - case "JSON" => - (tq"_root_.com.spotify.scio.bigquery.types.Json", Nil) + case _ if provider.shouldOverrideType(tfs) => (provider.getScalaType(c)(tfs), Nil) + case "BOOLEAN" | "BOOL" => (tq"_root_.scala.Boolean", Nil) + case "INTEGER" | "INT64" => (tq"_root_.scala.Long", Nil) + case "FLOAT" | "FLOAT64" => (tq"_root_.scala.Double", Nil) + case "STRING" => (tq"_root_.java.lang.String", Nil) + case "NUMERIC" => (tq"_root_.scala.BigDecimal", Nil) + case "BIGNUMERIC" => (tq"_root_.scala.BigDecimal", Nil) + case "BYTES" => (tq"_root_.com.google.protobuf.ByteString", Nil) + case "TIMESTAMP" => (tq"_root_.org.joda.time.Instant", Nil) + case "DATE" => (tq"_root_.org.joda.time.LocalDate", Nil) + case "TIME" => (tq"_root_.org.joda.time.LocalTime", Nil) + case "DATETIME" => (tq"_root_.org.joda.time.LocalDateTime", Nil) + case "GEOGRAPHY" => (tq"_root_.com.spotify.scio.bigquery.types.Geography", Nil) + case "JSON" => (tq"_root_.com.spotify.scio.bigquery.types.Json", Nil) case "RECORD" | "STRUCT" => val name = NameProvider.getUniqueName(tfs.getName) val (fields, records) = toFields(tfs.getFields) (q"${Ident(TypeName(name))}", Seq(q"case class ${TypeName(name)}(..$fields)") ++ records) case t => c.abort(c.enclosingPosition, s"type: $t not supported") } + // format: on + } // Returns: (field type, e.g. T/Option[T]/List[T], nested case class definitions) def getFieldType(tfs: TableFieldSchema): (Tree, Seq[Tree]) = {