Bug in the filter_thread_work algorithm for Postgres backend
Motivation
----------
The partitioning algorithm sometimes fails with `Details: (psycopg2.errors.NumericValueOutOfRange) integer out of range` for Postgres backend, e.g. : 
```
rucio=> select abs(('x'||md5(requests.id::text))::bit(64)::int) from requests limit 1;
ERROR:  integer out of range
rucio=> select abs(('x'||md5(requests.id::text))::bit(64)::bigint) from requests limit 1;
         abs         
---------------------
 9096650785057471382
(1 row)
```




diff --git a/lib/rucio/db/sqla/__init__.py b/lib/rucio/db/sqla/__init__.py
index 0bb6b89e2..d4b8aebec 100644
--- a/lib/rucio/db/sqla/__init__.py
+++ b/lib/rucio/db/sqla/__init__.py
@@ -1,8 +1,24 @@
-# Copyright European Organization for Nuclear Research (CERN)
+# -*- coding: utf-8 -*-
+# Copyright 2013-2022 CERN
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
-# You may not use this file except in compliance with the License.
-# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Authors:
+# - Vincent Garonne <vincent.garonne@cern.ch>, 2013-2015
+# - Brandon White <bjwhite@fnal.gov>, 2019
+# - Martin Barisits <martin.barisits@cern.ch>, 2020
+# - Radu Carpa <radu.carpa@cern.ch>, 2021
+# - Cedric Serfon <cedric.serfon@cern.ch>, 2022
 
 from sqlalchemy.sql.expression import bindparam, text
 
@@ -23,7 +39,7 @@ def filter_thread_work(session, query, total_threads, thread_id, hash_variable=N
                 query = query.filter(text('mod(md5(%s), %s) = %s' % (hash_variable, total_threads, thread_id)))
         elif session.bind.dialect.name == 'postgresql':
             if not hash_variable:
-                query = query.filter(text('mod(abs((\\'x\\'||md5(id::text))::bit(32)::int), %s) = %s' % (total_threads, thread_id)))
+                query = query.filter(text('mod(abs((\\'x\\'||md5(id::text))::bit(32)::bigint), %s) = %s' % (total_threads, thread_id)))
             else:
-                query = query.filter(text('mod(abs((\\'x\\'||md5(%s::text))::bit(32)::int), %s) = %s' % (hash_variable, total_threads, thread_id)))
+                query = query.filter(text('mod(abs((\\'x\\'||md5(%s::text))::bit(32)::bigint), %s) = %s' % (hash_variable, total_threads, thread_id)))
     return query
['lib/rucio/db/sqla/__init__.py']