From f60d45795d2d9281f6c00ae06035fb8462dc07d3 Mon Sep 17 00:00:00 2001 From: BenHutchison Date: Thu, 9 May 2024 13:47:08 +1000 Subject: [PATCH] Handle Postgres oids greater than Int.MaxValue --- modules/core/shared/src/main/scala/util/Typer.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/core/shared/src/main/scala/util/Typer.scala b/modules/core/shared/src/main/scala/util/Typer.scala index 2459d96a..a160abf9 100644 --- a/modules/core/shared/src/main/scala/util/Typer.scala +++ b/modules/core/shared/src/main/scala/util/Typer.scala @@ -177,7 +177,10 @@ object Typer { case class TypeInfo(oid: Int, name: String, arrayTypeOid: Option[Int], relOid: Option[Int]) implicit class ProtocolOps[F[_]: Functor](p: Protocol[F]) { - val oid: Codec[Int] = Codec.simple(_.toString, _.toInt.asRight, Type.oid) + //Note Postgres defines oids as *unsigned* Ints https://www.postgresql.org/docs/current/datatype-oid.html + //Since Scala currently lacks a built-in unsigned Int type, if the oid exceeds `Int.MaxValue` + //it will be converted to/from a negative Int by this Codec (only observed in CockroachDB) + val oid: Codec[Int] = Codec.simple(java.lang.Integer.toUnsignedLong(_).toString, _.toLong.toInt.asRight, Type.oid) val typeInfoMap: F[Map[Int, TypeInfo]] = {