I don't think this is going to solve it, but I hope it can improve it:
The count (distinct something) is a very intense expression ( it's the same when you run something like this directly on a database). I'm not sure if this is the field you are trying to convert ( unique_impressions).
Buy you could create a field on the script to avoid the count distinct.
let us say that this field is part of a 'Fact' Table.
I would create another table like this:
load distinct unique_impressions, 1 as flag_impression
So there is only one value '1' for each distinct unique_impression. After this, you replace the count(distinct unique_impressions) by sum( flag_impression).
Hope it helps,