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',