Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix derived feature list toMap will change the original order #1209

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ private[offline] class DerivedFeatureGenStage(featureGroups: FeatureGroups, logi
* @return all evaluated features including the ones processed here.
*/
override def evaluate(features: Seq[String], keyTags: Seq[Int], context: FeatureDataWithJoinKeys): FeatureDataWithJoinKeys = {
val featureToDerivationMap = features.map(f => (featureGroups.allDerivedFeatures(f), f)).toMap
featureToDerivationMap.foldLeft(context)((accumulator: FeatureDataWithJoinKeys, currFeatureDerivation) => {
val (derivation, derivedFeatureName) = currFeatureDerivation
val featureColumnName = DataFrameColName.genFeatureColumnName(derivedFeatureName)
// Compute the base DataFrame that can be used to compute the derived feature.
val BaseDataFrameMetadata(baseFeatureDataFrame, joinKeys, featuresOnBaseDf) =
evaluateBaseDataFrameForDerivation(derivedFeatureName, derivation, accumulator)
val derivedFeatureDataFrame =
if (baseFeatureDataFrame.df.columns.contains(featureColumnName)) { // if DataFrame already has the feature, no need to apply derivations
baseFeatureDataFrame
} else {
derivedFeatureUtils.evaluate(keyTags, logicalPlan.keyTagIntsToStrings, baseFeatureDataFrame.df, derivation)
}
val columnRenamedDf = dropFrameTagsAndRenameColumn(derivedFeatureDataFrame.df, featureColumnName)
// Update featureTypeMap and features on DataFrame metadata
val updatedFeatureTypeMap = baseFeatureDataFrame.inferredFeatureType ++ derivedFeatureDataFrame.inferredFeatureType
val updatedFeaturesOnDf = featuresOnBaseDf :+ derivedFeatureName
accumulator ++ updatedFeaturesOnDf.map(f => f -> (FeatureDataFrame(columnRenamedDf, updatedFeatureTypeMap), joinKeys)).toMap
features.map(f => (featureGroups.allDerivedFeatures(f), f))
.foldLeft(context)((accumulator: FeatureDataWithJoinKeys, currFeatureDerivation) => {
val (derivation, derivedFeatureName) = currFeatureDerivation
val featureColumnName = DataFrameColName.genFeatureColumnName(derivedFeatureName)
// Compute the base DataFrame that can be used to compute the derived feature.
val BaseDataFrameMetadata(baseFeatureDataFrame, joinKeys, featuresOnBaseDf) =
evaluateBaseDataFrameForDerivation(derivedFeatureName, derivation, accumulator)
val derivedFeatureDataFrame =
if (baseFeatureDataFrame.df.columns.contains(featureColumnName)) { // if DataFrame already has the feature, no need to apply derivations
baseFeatureDataFrame
} else {
derivedFeatureUtils.evaluate(keyTags, logicalPlan.keyTagIntsToStrings, baseFeatureDataFrame.df, derivation)
}
val columnRenamedDf = dropFrameTagsAndRenameColumn(derivedFeatureDataFrame.df, featureColumnName)
// Update featureTypeMap and features on DataFrame metadata
val updatedFeatureTypeMap = baseFeatureDataFrame.inferredFeatureType ++ derivedFeatureDataFrame.inferredFeatureType
val updatedFeaturesOnDf = featuresOnBaseDf :+ derivedFeatureName
accumulator ++ updatedFeaturesOnDf.map(f => f -> (FeatureDataFrame(columnRenamedDf, updatedFeatureTypeMap), joinKeys)).toMap
})
}

Expand Down