def checkType(self, meta_attribute_definition:dict, meta_attribute_key:str, value:str, primary_key_value:str): # field type check is_valid_type = True if (MetaUtils.exists(meta_attribute_definition, "Type")): # if a default value has been specified then ignore the type check if the value matches the default if (MetaUtils.exists(meta_attribute_definition, "Default")): if (value==meta_attribute_definition["Default"]): is_valid_type = False if (meta_attribute_definition["Type"] in ["int","integer"]): if ( (MetaUtils.isBlankOrNull(value)) or (not MetaUtils.isInt(value)) ): if (not MetaUtils.isAllowBlank(meta_attribute_definition)): self.addDataQualityError(DataQualityError(meta_attribute_key,error_dimension=DataQualityDimension.METADATACOMPLIANCE.value, description="Error: Value '" + value + "' is not an int. An int was expected",primary_key_value=primary_key_value)) is_valid_type = False elif (meta_attribute_definition["Type"] in ["float","number"]): if ( (MetaUtils.isBlankOrNull(value)) or (not MetaUtils.isFloat(value)) ): if (not MetaUtils.isAllowBlank(meta_attribute_definition)): self.addDataQualityError(DataQualityError(meta_attribute_key,error_dimension=DataQualityDimension.METADATACOMPLIANCE.value, description="Error: Value '" + value + "' is not a float. A float was expected",primary_key_value=primary_key_value)) is_valid_type = False elif (meta_attribute_definition["Type"] in ["bool","boolean"]): if ( (MetaUtils.isBlankOrNull(value)) or (not value.lower() in ["false", "true", "f", "t", "n", "y", "no", "yes", "0", "1"]) ): if (not MetaUtils.isAllowBlank(meta_attribute_definition)): self.addDataQualityError(DataQualityError(meta_attribute_key,error_dimension=DataQualityDimension.METADATACOMPLIANCE.value, description="Error: Value '" + value + "' is not a boolean. A boolean was expected",primary_key_value=primary_key_value)) is_valid_type = False # given that min and max checks only apply to int and float values we may as well test for them now if (is_valid_type): self.checkMinMax(meta_attribute_definition, meta_attribute_key, value, primary_key_value)
def checkMandatory(self, meta_attribute_definition: dict, meta_attribute_key: str, value: str, primary_key_value: str): # mandatory field check if (MetaUtils.isTrue(meta_attribute_definition, "Mandatory")): if ((MetaUtils.isBlankOrNull(value)) and (not MetaUtils.isAllowBlank(meta_attribute_definition))): self.addDataQualityError( DataQualityError( meta_attribute_key, error_dimension=DataQualityDimension. COMPLETENESSMANDATORY.value, description= "Error: Mandatory field is BLANK or NULL. A value is required.", primary_key_value=primary_key_value)) else: # optional field check. According to LANG optional fields shpuld contain some sort of default value # i.e. no field shpould ever be blank or NULL. if ((MetaUtils.isBlankOrNull(value)) and (not MetaUtils.isAllowBlank(meta_attribute_definition))): self.addDataQualityError( DataQualityError( meta_attribute_key, error_dimension=DataQualityDimension. COMPLETENESSOPTIONAL.value, description= "Error: Optional field is BLANK or NULL. A default value is required.", primary_key_value=primary_key_value))
def checkSize(self, meta_attribute_definition: dict, meta_attribute_key: str, value: str, primary_key_value: str): # field length check if (MetaUtils.exists(meta_attribute_definition, "Size")): if ((len(value) > int(meta_attribute_definition["Size"])) and (not MetaUtils.isBlankOrNull(value))): self.addDataQualityError( DataQualityError(meta_attribute_key, error_dimension=DataQualityDimension. METADATACOMPLIANCE.value, description="Error: Value '" + value + "' is longer than size '" + str(meta_attribute_definition["Size"]) + "'", primary_key_value=primary_key_value))