Example #1
0
    def _Validate(self, inputs: Dict[Text, Any], outputs: Dict[Text,
                                                               Any]) -> None:
        """Validate the inputs and put validate result into outputs.

      This is the implementation part of example validator executor. This is
      intended for using or extending the executor without artifact dependecy.

    Args:
      inputs: A dictionary of labeled input values, including:
        - STATISTICS_KEY: the feature statistics to validate
        - SCHEMA_KEY: the schema to respect
        - (Optional) labels.ENVIRONMENT: if an environment is specified, only
          validate the feature statistics of the fields in that environment.
          Otherwise, validate all fields.
        - (Optional) labels.PREV_SPAN_FEATURE_STATISTICS: the feature
          statistics of a previous span.
        - (Optional) labels.PREV_VERSION_FEATURE_STATISTICS: the feature
          statistics of a previous version.
        - (Optional) labels.FEATURES_NEEDED: the feature needed to be
          validated on.
        - (Optional) labels.VALIDATION_CONFIG: the configuration of this
          validation.
        - (Optional) labels.EXTERNAL_CONFIG_VERSION: the version number of
          external config file.
      outputs: A dictionary of labeled output values, including:
          - labels.SCHEMA_DIFF_PATH: the path to write the schema diff to
    """
        schema = value_utils.GetSoleValue(inputs, SCHEMA_KEY)
        stats = value_utils.GetSoleValue(inputs, STATISTICS_KEY)
        schema_diff_path = value_utils.GetSoleValue(outputs,
                                                    labels.SCHEMA_DIFF_PATH)
        anomalies = tfdv.validate_statistics(stats, schema)
        io_utils.write_bytes_file(
            os.path.join(schema_diff_path, DEFAULT_FILE_NAME),
            anomalies.SerializeToString())
Example #2
0
 def testReadWriteBytes(self):
     file_path = os.path.join(self._base_dir, 'test_file')
     content = b'testing read/write'
     io_utils.write_bytes_file(file_path, content)
     read_content = io_utils.read_bytes_file(file_path)
     self.assertEqual(content, read_content)