def __get_valid_condition(self, column_metadata: ColumnMetadata, validity: Validity, dialect: Dialect): qualified_column_name = dialect.qualify_column_name( column_metadata.name, column_metadata.data_type) if validity is None: return '', True validity_clauses = [] if validity.format is not None and self.is_text: format_regex = Validity.FORMATS.get(validity.format) qualified_regex = dialect.qualify_regex(format_regex) validity_clauses.append( dialect.sql_expr_regexp_like(qualified_column_name, qualified_regex)) if validity.regex is not None and self.is_text: qualified_regex = dialect.qualify_regex(validity.regex) validity_clauses.append( dialect.sql_expr_regexp_like(qualified_column_name, qualified_regex)) if validity.values is not None: valid_values_sql = dialect.sql_expr_list(column_metadata, validity.values) validity_clauses.append( dialect.sql_expr_in(qualified_column_name, valid_values_sql)) if validity.min_length is not None and self.is_text: validity_clauses.append( f'{dialect.sql_expr_length(qualified_column_name)} >= {validity.min_length}' ) if validity.max_length is not None and self.is_text: validity_clauses.append( f'{dialect.sql_expr_length(qualified_column_name)} <= {validity.max_length}' ) if validity.min is not None and self.is_number: validity_clauses.append( f'{qualified_column_name} >= {validity.min}') if validity.max is not None and self.is_number: validity_clauses.append( f'{qualified_column_name} <= {validity.max}') if validity.min is not None and self.is_text: validity_clauses.append( f'{dialect.sql_expr_cast_text_to_number(qualified_column_name, self.validity_format)} >= {validity.min}' ) if validity.max is not None and self.is_text: validity_clauses.append( f'{dialect.sql_expr_cast_text_to_number(qualified_column_name, self.validity_format)} <= {validity.max}' ) if len(validity_clauses) != 0: return '(' + ' AND '.join(validity_clauses) + ')', len( validity_clauses) == 0 else: return '', True
def __get_valid_condition(cls, column_metadata: ColumnMetadata, validity: Validity, dialect: Dialect): qualified_column_name = dialect.qualify_column_name( column_metadata.name) if validity is None: return '', True validity_clauses = [] if validity.format: format_regex = Validity.FORMATS.get(validity.format) qualified_regex = dialect.qualify_regex(format_regex) validity_clauses.append( dialect.sql_expr_regexp_like(qualified_column_name, qualified_regex)) if validity.regex: qualified_regex = dialect.qualify_regex(validity.regex) validity_clauses.append( dialect.sql_expr_regexp_like(qualified_column_name, qualified_regex)) if validity.values: valid_values_sql = dialect.literal_list(validity.values) validity_clauses.append( dialect.sql_expr_in(qualified_column_name, valid_values_sql)) if validity.min_length: validity_clauses.append( f'{dialect.sql_expr_length(qualified_column_name)} >= {validity.min_length}' ) if validity.max_length: validity_clauses.append( f'{dialect.sql_expr_length(qualified_column_name)} <= {validity.max_length}' ) if validity.min: validity_clauses.append( f'{qualified_column_name} >= {validity.min}') if validity.max: validity_clauses.append( f'{qualified_column_name} <= {validity.max}') return '(' + ' AND '.join(validity_clauses) + ')', len( validity_clauses) == 0