def validate_metadata_for_table(table, key, out_str, lgr, verbose): helper.log_info(lgr, "Validating " + out_str + " key: " + str(key), verbose) assert isinstance(key, basestring) is True, "Key attribute must be a string." assert helper.check_attrs_present(table, key) is True, "Key attribute is not present in the " + out_str + " table" assert is_key_attribute(table, key, verbose) == True, ( "Attribute " + str(key) + " in the " + out_str + " table " "does not qualify to be the key" ) helper.log_info(lgr, "..... Done", verbose)
def check_fk_constraint(df_foreign, attr_foreign, df_base, attr_base): """ Check if the foreign key is a primary key Args: df_foreign (pandas dataframe): Foreign dataframe attr_foreign (str): Attribute in the foreign dataframe df_base (pandas dataframe): Base dataframe attr_base (str): Attribute in the base dataframe Returns: result (bool). Returns True if the foreign key contraint is satisfied, else returns False Notes: This is an internal helper function """ if isinstance(attr_base, basestring) is False: return False if helper.check_attrs_present(df_base, attr_base) is False: return False t = df_base[df_base[attr_base].isin(pd.unique(df_foreign[attr_foreign]))] return is_key_attribute(t, attr_base)