def expect_column_value_lengths_to_be_between(self,
                                                  column,
                                                  min_value=None,
                                                  max_value=None,
                                                  mostly=None,
                                                  result_format=None,
                                                  include_config=False,
                                                  catch_exceptions=None,
                                                  meta=None):
        if min_value is None and max_value is None:
            return column.withColumn('__success', lit(True))
        elif min_value is None:
            return column.withColumn(
                '__success',
                when(length_(column[0]) <= max_value,
                     lit(True)).otherwise(lit(False)))
        elif max_value is None:
            return column.withColumn(
                '__success',
                when(length_(column[0]) >= min_value,
                     lit(True)).otherwise(lit(False)))
        # FIXME: whether the below condition is enforced seems to be somewhat inconsistent

        # else:
        #     if min_value > max_value:
        #         raise ValueError("minvalue cannot be greater than max_value")

        return column.withColumn(
            '__success',
            when((min_value <= length_(column[0])) &
                 (length_(column[0]) <= max_value),
                 lit(True)).otherwise(lit(False)))
Ejemplo n.º 2
0
 def expect_column_value_lengths_to_equal(
     self,
     column,
     value, # int
     mostly=None,
     result_format=None,
     include_config=True,
     catch_exceptions=None,
     meta=None,
 ):
     return column.withColumn('__success', when(length_(column[0]) == value, lit(True)).otherwise(lit(False)))