Skip to content

Instantly share code, notes, and snippets.

@albinkjellin
Created August 18, 2023 14:51
Show Gist options
  • Save albinkjellin/3bd81b8577eeea262a3c2a082aadbca6 to your computer and use it in GitHub Desktop.
Save albinkjellin/3bd81b8577eeea262a3c2a082aadbca6 to your computer and use it in GitHub Desktop.
Generate Soda CL based on a csv
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