tensorflow::Status Schema::UpdateFeature()

in tensorflow_data_validation/anomalies/schema.cc [219:289]


tensorflow::Status Schema::UpdateFeature(
    const Updater& updater, const FeatureStatsView& feature_stats_view,
    std::vector<Description>* descriptions,
    absl::optional<tensorflow::metadata::v0::DriftSkewInfo>* drift_skew_info,
    tensorflow::metadata::v0::AnomalyInfo::Severity* severity) {
  *severity = tensorflow::metadata::v0::AnomalyInfo::UNKNOWN;

  Feature* feature = GetExistingFeature(feature_stats_view.GetPath());
  SparseFeature* sparse_feature =
      GetExistingSparseFeature(feature_stats_view.GetPath());
  WeightedFeature* weighted_feature =
      GetExistingWeightedFeature(feature_stats_view.GetPath());
  if (weighted_feature != nullptr) {
    if ((feature != nullptr || sparse_feature != nullptr) &&
        !::tensorflow::data_validation::WeightedFeatureIsDeprecated(
            *weighted_feature)) {
      descriptions->push_back({tensorflow::metadata::v0::AnomalyInfo::
                                   WEIGHTED_FEATURE_NAME_COLLISION,
                               "Weighted feature name collision",
                               "Weighted feature name collision."});
      ::tensorflow::data_validation::DeprecateWeightedFeature(weighted_feature);
      if (feature != nullptr) {
        ::tensorflow::data_validation::DeprecateFeature(feature);
      }
      if (sparse_feature != nullptr) {
        ::tensorflow::data_validation::DeprecateSparseFeature(sparse_feature);
      }
      updater.UpdateSeverityForAnomaly(*descriptions, severity);
      return Status::OK();
    } else {
      *descriptions =
          UpdateWeightedFeature(feature_stats_view, weighted_feature);
      updater.UpdateSeverityForAnomaly(*descriptions, severity);
      return Status::OK();
    }
  }

  if (sparse_feature != nullptr &&
      !::tensorflow::data_validation::SparseFeatureIsDeprecated(
          *sparse_feature)) {
    if (feature != nullptr &&
        !::tensorflow::data_validation::FeatureIsDeprecated(*feature)) {
      descriptions->push_back(
          {tensorflow::metadata::v0::AnomalyInfo::SPARSE_FEATURE_NAME_COLLISION,
           "Sparse feature name collision", "Sparse feature name collision."});
      ::tensorflow::data_validation::DeprecateSparseFeature(sparse_feature);
      ::tensorflow::data_validation::DeprecateFeature(feature);
      updater.UpdateSeverityForAnomaly(*descriptions, severity);
      return Status::OK();
    } else {
      *descriptions = UpdateSparseFeature(feature_stats_view, sparse_feature);
      updater.UpdateSeverityForAnomaly(*descriptions, severity);
      return Status::OK();
    }
  }

  if (feature != nullptr) {
    UpdateFeatureInternal(updater, feature_stats_view, feature, descriptions,
                          drift_skew_info);
    updater.UpdateSeverityForAnomaly(*descriptions, severity);
    return Status::OK();
  } else {
    const Description description = {
        tensorflow::metadata::v0::AnomalyInfo::SCHEMA_NEW_COLUMN, "New column",
        "New column (column in data but not in schema)"};
    *descriptions = {description};
    updater.UpdateSeverityForAnomaly(*descriptions, severity);
    return updater.CreateColumn(feature_stats_view, this, severity);
  }
  return Status::OK();
}