From d9409b15bd5815de35aab969575cdafab59ff407 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 20 May 2020 17:37:10 +0200 Subject: [PATCH] misc: truncate schema_temp to 63 characters (#43165) --- wcs_olap/feeder.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wcs_olap/feeder.py b/wcs_olap/feeder.py index a742c57..a48f155 100644 --- a/wcs_olap/feeder.py +++ b/wcs_olap/feeder.py @@ -20,6 +20,17 @@ psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY) +def truncate_pg_identifier(identifier, hash_length=6, force_hash=False): + if len(identifier) < 64 and not force_hash: + return identifier + else: + # insert hash in the middle, to keep some readability + return ( + identifier[:(63 - hash_length) // 2] + + hashlib.md5(identifier.encode('utf-8')).hexdigest()[:hash_length] + + identifier[-(63 - hash_length) // 2:]) + + def quote(name): return '"%s"' % name @@ -79,7 +90,7 @@ class WcsOlapFeeder(object): self.ctx = Context() self.ctx.push({ 'schema': self.schema, - 'schema_temp': self.schema + '_temp', + 'schema_temp': truncate_pg_identifier(schema + '_temp'), 'role_table': 'role', 'channel_table': 'channel', 'category_table': 'category',