in scripts/anonymize.py [0:0]
def anonymize_job_Presto(self, input_dir, file_name):
print("processing", os.path.join(input_dir, file_name))
# header: starttimems,job_id,template_id,walltimems,
# db_name,table_name,uown_names,date,inputDataSize,cputime,start_time,duration,outputDataSize
df = pd.read_csv(os.path.join(input_dir, file_name))
df.drop(columns=['starttimems', 'walltimems'], inplace=True)
counter_a, counter_d, counter_t = self.get_counters()
# anonymization
for index, row in df.iterrows():
a_string = row['template_id']
d_string = row['db_name']
t_string = row['table_name']
if a_string not in self.abFP:
self.abFP[a_string] = counter_a
counter_a += 1
if d_string not in self.db:
self.db[d_string] = counter_d
counter_d += 1
if t_string not in self.table:
self.table[t_string] = counter_t
counter_t += 1
print("mapping updated into", counter_a, counter_d, counter_t)
# Apply mappings to anonymize the data
df['template_id'] = df['template_id'].map(self.abFP)
df['db_name'] = df['db_name'].map(self.db)
df['table_name'] = df['table_name'].map(self.table)
# if 'uown_names' column exists, anonymize it
if 'uown_names' in df.columns:
df['uown_names'] = df['uown_names'].apply(lambda x: False if pd.isna(x) or x.strip() == "" else True)
# Generate a new CSV file with anonymized data
anonymized_file_name = "anonymized_" + file_name
df.to_csv(os.path.join(self.dir_path, anonymized_file_name), index=False)