def runSqlValidations(self, interfaces, jobId, fileType, shortColnames, writer, warningWriter, rowNumber): """ Run all SQL rules for this file type Args: interfaces: InterfaceHolder object jobId: ID of current job fileType: Type of file for current job shortColnames: Dict mapping short field names to long writer: CsvWriter object waringWriter: CsvWriter for warnings rowNumber: Current row number Returns: a list of the row numbers that failed one of the sql-based validations """ errorInterface = interfaces.errorDb errorRows = [] sqlFailures = Validator.validateFileBySql( interfaces.jobDb.getSubmissionId(jobId), fileType, interfaces) for failure in sqlFailures: # convert shorter, machine friendly column names used in the # SQL validation queries back to their long names if failure[0] in shortColnames: fieldName = shortColnames[failure[0]] else: fieldName = failure[0] error = failure[1] failedValue = failure[2] row = failure[3] original_label = failure[4] fileTypeId = failure[5] targetFileId = failure[6] severityId = failure[7] if severityId == interfaces.validationDb.getRuleSeverityId( "fatal"): errorRows.append(row) try: # If error is an int, it's one of our prestored messages errorType = int(error) errorMsg = ValidationError.getErrorMessage(errorType) except ValueError: # If not, treat it literally errorMsg = error if severityId == interfaces.validationDb.getRuleSeverityId( "fatal"): writer.write([ fieldName, errorMsg, str(row), failedValue, original_label ]) elif severityId == interfaces.validationDb.getRuleSeverityId( "warning"): # write to warnings file warningWriter.write([ fieldName, errorMsg, str(row), failedValue, original_label ]) errorInterface.recordRowError(jobId, self.filename, fieldName, error, rowNumber, original_label, file_type_id=fileTypeId, target_file_id=targetFileId, severity_id=severityId) return errorRows
def runSqlValidations(self, job, file_type, short_colnames, writer, warning_writer, row_number, error_list): """ Run all SQL rules for this file type Args: job: Current job file_type: Type of file for current job short_colnames: Dict mapping short field names to long writer: CsvWriter object warning_writer: CsvWriter for warnings row_number: Current row number error_list: instance of ErrorInterface to keep track of errors Returns: a list of the row numbers that failed one of the sql-based validations """ sess = GlobalDB.db().session job_id = job.job_id error_rows = [] sql_failures = Validator.validateFileBySql(job.submission_id, file_type, self.short_to_long_dict) for failure in sql_failures: # convert shorter, machine friendly column names used in the # SQL validation queries back to their long names if failure[0] in short_colnames: field_name = short_colnames[failure[0]] else: field_name = failure[0] error = failure[1] failed_value = failure[2] row = failure[3] original_label = failure[4] file_type_id = failure[5] target_file_id = failure[6] severity_id = failure[7] if severity_id == RULE_SEVERITY_DICT['fatal']: error_rows.append(row) try: # If error is an int, it's one of our prestored messages error_type = int(error) error_msg = ValidationError.getErrorMessage(error_type) except ValueError: # If not, treat it literally error_msg = error if severity_id == RULE_SEVERITY_DICT['fatal']: writer.write([ field_name, error_msg, str(row), failed_value, original_label ]) elif severity_id == RULE_SEVERITY_DICT['warning']: # write to warnings file warning_writer.write([ field_name, error_msg, str(row), failed_value, original_label ]) error_list.recordRowError(job_id, job.filename, field_name, error, row_number, original_label, file_type_id=file_type_id, target_file_id=target_file_id, severity_id=severity_id) return error_rows