I am writing scala code to load data from db (postgres) using following sql.
SELECT
a.id,
a.act_type_id AS actTypeId
COALESCE(json_agg(x.procedure_id), '[]'::json) as actProcIds
FROM
act a
INNER JOIN (
SELECT
*
FROM
act_procedure p
WHERE
p.procedure_id IN (?, ?)
) x ON a.id = x.act_id
WHERE
(a.act_type_id = ?)
GROUP BY
a.id
ORDER BY
a.id ASC
LIMIT
10
and I got result below:
id |acttypeid |actprocids
------------------------------------+------------------------------------+----------------------------------------
e33681a3-7d1a-4f7b-af32-b9ad59f55052|84bc042c-155c-40ef-88ca-6b0be127d87c|["aa5b40f6-0e83-4680-9ce6-76cf1b3b80c9"]
The domain file is
case class ActProcedureDomain(
id: FUUID,
actTypeId: Option[FUUID],
actProcIds: List[FUUID]
)
Below is the code to call the sql
def getPaginatedList(param: ListInput[Q])(implicit sync: Sync[F]): EitherT[F, MyCustomizedError, ListOutput[O]] = {
val result = EitherT(
param.xNextToken
.flatMap(token => {
if (token.queryParamHash == param.queryParams.hashCode()) None
else QueryParamsConflictError("Prev params and current version do not match.", encode(token)).some
}).fold(
paginate(param, xa)
.leftSemiflatMap(error =>
logAndReturn(RepositoryError(s"Issue retrieving paginated list based on params=$param: ${error.getMessage}")))
.value
)(error => logAndReturn(error).map(Left[MyCustomizedError, ListOutput[O]])))
val res = result.andLogIfSlow("getPaginatedList")
println("yyy ->")
res
}
And I can see "yyy ->" was printed in the log. Howeve, I can not see the log after this. For instance,
entity <- repository.getPaginatedList(input) _ = println("zzz -> ")
above doesn't print "zzz ->" in log. But I did see the error below:
Caused by: java.lang.ArrayIndexOutOfBoundsException: 40
at org.postgresql.jdbc.PgArray.buildArrayList(PgArray.java:449)
at org.postgresql.jdbc.PgArray.getArrayImpl(PgArray.java:167)
at org.postgresql.jdbc.PgArray.getArray(PgArray.java:127)
at doobie.util.Get$Advanced$.$anonfun$array$1(get.scala:145)
at doobie.util.Get$Advanced$.$anonfun$array$1$adapted(get.scala:143)
at doobie.util.Get.unsafeGetNullable(get.scala:37)
at doobie.util.Read$.$anonfun$fromGetOption$1(read.scala:78)
at doobie.util.Read$.$anonfun$fromGetOption$1$adapted(read.scala:78)
at doobie.util.Read.$anonfun$map$1(read.scala:51)
at doobie.util.Read.$anonfun$map$1$adapted(read.scala:51)
at doobie.util.LowerPriorityRead.$anonfun$product$1(read.scala:99)
at doobie.util.LowerPriorityRead.$anonfun$product$1$adapted(read.scala:99)
at doobie.util.LowerPriorityRead.$anonfun$product$1(read.scala:99)
at doobie.util.LowerPriorityRead.$anonfun$product$1$adapted(read.scala:99)
at doobie.util.LowerPriorityRead.$anonfun$product$1(read.scala:99)
at doobie.util.LowerPriorityRead.$anonfun$product$1$adapted(read.scala:99)
at doobie.util.LowerPriorityRead.$anonfun$product$1(read.scala:99)
...
That makes me believe that the loading that json data into the List attribute of the domain object gives e trouble.
By checking online, I then import following class into my repository file (only import it but not use the actProcsMeta in any way), but it didn't solve the issue.
object ActsDoobieMeta {
implicit val actProcsMeta: Meta[List[FUUID]] =
Meta[Json].imap(json => json.as[List[FUUID]].getOrElse(List()))(procs => proc.asJson)
}
Can anyone please help here? Thanks in advance.