-
-
Save albinkjellin/3bd81b8577eeea262a3c2a082aadbca6 to your computer and use it in GitHub Desktop.
Generate Soda CL based on a csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import pandas as pd | |
import yaml | |
# Provide a link to the csv file with the rules. | |
file_name = 'rules.csv' | |
df = pd.read_csv(file_name) | |
df = df.reset_index() # make sure indexes pair with number of rows | |
df.fillna("nan",inplace=True) | |
checks = [] | |
table_name = '' | |
agreement = [] | |
for index, row in df.iterrows(): | |
if(row['script'] != 'nan'): | |
rule = { | |
'failed rows': { | |
'name': row['pk_control_id'], | |
'attributes': { | |
'criticality': row['criticality'], | |
'fk_dim': row['fk_dim'], | |
'environment': row['environment'], | |
}, | |
'fail query': row['script'] | |
} | |
} | |
checks.append(rule) | |
if (table_name != row['table_name']): | |
table_name = row['table_name'] | |
checks_dict = { | |
'checks for ' + row['table_name']: checks | |
} | |
print(yaml.dump(checks_dict)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment