Skip to content

Commit

Permalink
allow numbers and underscores in names (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
leahmcguire authored and tovbinm committed Aug 25, 2018
1 parent b57ab91 commit 5823a87
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions features/src/main/scala/com/salesforce/op/stages/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ package object stages {
private[stages] def makeOutputName(
featureUid: String, inputs: Seq[TransientFeature], numberOperations: Int = 1
): String = {
val origins = inputs.flatMap(_.originFeatures).distinct.sorted.mkString("-").replaceAll("[^A-Za-z-]+", "")
val origins = inputs.flatMap(_.originFeatures).distinct.sorted.mkString("-").replaceAll("[^A-Za-z-_0-9]+", "")
val stages = inputs.flatMap(_.stages).distinct.length + numberOperations
s"${origins}_$stages-stagesApplied_$featureUid"
}
Expand All @@ -74,23 +74,4 @@ package object stages {
makeOutputName(featureUid, inputs, numberOperations)
}

/**
* Replace feature names for multistage spark wrappers (gross-ness) that have had the output name overridden
*
* @param newName override name
* @param oldName default name
* @param numberOperations number of stages applied to add to stages from features (used in multistage operations)
* @return name of the output ex: "f1-f2_4-stagesApplied_Real_0183nsdk"
*/
private[stages] def updateOutputName(
newName: String, oldName: String, numberOperations: Int
): String = {
val name = raw"([A-Za-z-]+)_([0-9]+)-stagesApplied_([A-Za-z0-9_-]+)".r
(newName, oldName) match {
// old uid because stages are different
case (nn, on) if nn == on => nn
case (name(orig, sz, _), name(_, _, uid)) => s"${orig}_${sz.toInt + numberOperations}-stagesApplied_$uid"
case (_, _) => throw new IllegalArgumentException(s"Cannot override output name $oldName with $newName")
}
}
}

0 comments on commit 5823a87

Please sign in to comment.