def factor_string_length_not_in_range(data_service: TopicDataService,
                                      rule: MonitorRule,
                                      date_range: Tuple[datetime, datetime],
                                      changed_rows_count_in_range: int,
                                      total_rows_count: int) -> RuleResult:
    found, factor = find_factor(data_service, rule.factorId, rule)
    if not found:
        return RuleResult.IGNORED

    count = data_service.count_by_criteria([
        EntityCriteriaJoint(
            conjunction=EntityCriteriaJointConjunction.OR,
            children=[
                EntityCriteriaExpression(
                    left=ComputedLiteral(
                        operator=ComputedLiteralOperator.CHAR_LENGTH,
                        elements=[
                            build_column_name_literal(factor, data_service)
                        ]),
                    operator=EntityCriteriaOperator.LESS_THAN,
                    right=rule.params.min),
                EntityCriteriaExpression(
                    left=ComputedLiteral(
                        operator=ComputedLiteralOperator.CHAR_LENGTH,
                        elements=[
                            build_column_name_literal(factor, data_service)
                        ]),
                    operator=EntityCriteriaOperator.GREATER_THAN,
                    right=rule.params.max)
            ]), *build_date_range_criteria(date_range)
    ])

    return RuleResult.SUCCESS if count == 0 else RuleResult.FAILED
Example #2
0
def factor_value_assert(
    data_service: TopicDataService, rule: MonitorRule,
    date_range: Tuple[datetime, datetime],
    assert_expression: Callable[[Factor],
                                EntityCriteriaExpression]) -> RuleResult:
    found, factor = find_factor(data_service, rule.factorId, rule)
    if not found:
        return RuleResult.IGNORED

    count = data_service.count_by_criteria(
        [assert_expression(factor), *build_date_range_criteria(date_range)])

    return RuleResult.SUCCESS if count == 0 else RuleResult.FAILED
def factor_mismatch_type(data_service: TopicDataService, rule: MonitorRule,
                         date_range: Tuple[datetime, datetime],
                         changed_rows_count_in_range: int,
                         total_rows_count: int) -> RuleResult:
    found, factor = find_factor(data_service, rule.factorId, rule)
    if not found:
        return RuleResult.IGNORED

    should, criteria = build_mismatch_statement(factor, data_service)
    if not should:
        # not need to detect, ignored
        return RuleResult.IGNORED

    count = data_service.count_by_criteria(
        [*criteria, *build_date_range_criteria(date_range)])

    return RuleResult.SUCCESS if count == 0 else RuleResult.FAILED
Example #4
0
def rows_count_mismatch_with_another(data_service: TopicDataService,
                                     rule: Optional[MonitorRule],
                                     date_range: Tuple[datetime, datetime],
                                     has_data: bool) -> int:
    """
	if given count is not none, which means already find the count somewhere, simply use this count as current.
	anyway, returns the current count
	"""
    if has_data:
        # get count of changed rows of current topic
        changed_row_count = data_service.count_by_criteria(
            build_date_range_criteria(date_range))
    else:
        changed_row_count = 0

    do_it(data_service, rule, date_range, changed_row_count)

    return changed_row_count
def factor_empty_over_coverage(
		data_service: TopicDataService, rule: MonitorRule,
		date_range: Tuple[datetime, datetime],
		changed_rows_count_in_range: int, total_rows_count: int
) -> RuleResult:
	if total_rows_count == 0:
		return RuleResult.SUCCESS
	found, factor = find_factor(data_service, rule.factorId, rule)
	if not found:
		return RuleResult.IGNORED

	count = data_service.count_by_criteria([
		EntityCriteriaExpression(
			left=build_column_name_literal(factor, data_service),
			operator=EntityCriteriaOperator.IS_EMPTY
		)
	])
	rate = count / total_rows_count * 100
	return RuleResult.SUCCESS if rate > rule.params.coverageRate else RuleResult.FAILED
Example #6
0
def factor_string_length_mismatch(data_service: TopicDataService,
                                  rule: MonitorRule,
                                  date_range: Tuple[datetime, datetime],
                                  changed_rows_count_in_range: int,
                                  total_rows_count: int) -> RuleResult:
    found, factor = find_factor(data_service, rule.factorId, rule)
    if not found:
        return RuleResult.IGNORED

    count = data_service.count_by_criteria([
        EntityCriteriaExpression(left=ComputedLiteral(
            operator=ComputedLiteralOperator.CHAR_LENGTH,
            elements=[build_column_name_literal(factor, data_service)]),
                                 operator=EntityCriteriaOperator.NOT_EQUALS,
                                 right=rule.params.length),
        *build_date_range_criteria(date_range)
    ])

    return RuleResult.SUCCESS if count == 0 else RuleResult.FAILED
def factor_and_another(
		data_service: TopicDataService, rule: MonitorRule,
		date_range: Tuple[datetime, datetime],
		changed_rows_count_in_range: int, total_rows_count: int
) -> RuleResult:
	found, factor = find_factor(data_service, rule.factorId, rule)
	if not found:
		return RuleResult.IGNORED

	found, another_factor = find_factor(data_service, rule.params.factorId, rule)
	if not found:
		return RuleResult.IGNORED

	count = data_service.count_by_criteria([
		EntityCriteriaExpression(
			left=build_column_name_literal(factor, data_service),
			operator=EntityCriteriaOperator.NOT_EQUALS,
			right=build_column_name_literal(another_factor, data_service),
		),
		*build_date_range_criteria(date_range)
	])

	return RuleResult.SUCCESS if count == 0 else RuleResult.FAILED