Skip to content

Commit

Permalink
Merge branch 'main' into AnchorFeatureFix
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakesh Kashyap Hanasoge Padmanabha committed Jun 5, 2023
2 parents 98f00e0 + 05f5013 commit 62dad74
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package com.linkedin.feathr.offline.transformation
import com.linkedin.feathr.common.exception.{ErrorLabel, FeathrException, FeathrFeatureTransformationException}
import com.linkedin.feathr.common.{FeatureTypes, FeatureValue}
import com.linkedin.feathr.offline.transformation.FeatureColumnFormat._
import com.linkedin.feathr.offline.util.FeathrUtils
import org.apache.spark.sql.Column
import org.apache.spark.sql.functions.typedLit
import org.apache.spark.sql.functions.{lit, typedLit}
import org.apache.spark.sql.types._

import scala.collection.JavaConverters._
Expand Down Expand Up @@ -51,6 +52,7 @@ private[offline] object FeatureValueToFDSColumnConverter extends FeatureValueToC
private[transformation] object FeatureValueToRawColumnConverter extends FeatureValueToColumnConverter {

override def convert(featureName: String, defaultValue: FeatureValue, targetDataType: DataType, featureType: FeatureTypes): Column = {

targetDataType match {
// If the field is StringType, treat it is as CATEGORICAL and get the "term".
case _: StringType =>
Expand Down Expand Up @@ -116,10 +118,7 @@ private[transformation] object FeatureValueToRawColumnConverter extends FeatureV
case _: StringType =>
typedLit(defaultValue.getAsTermVector.asScala.keys.toSeq)
case eType =>
throw new FeathrFeatureTransformationException(
ErrorLabel.FEATHR_USER_ERROR,
s"Cannot convert Array of {$eType} to name-term-value FeatureValue," +
s" only array of float/double/string/int is supported")
lit(null)
}
case fType =>
throw new FeathrFeatureTransformationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,20 @@ class TestDefaultValueToColumnConverter extends TestFeathr with MockitoSugar {
/**
* Test converting CATEGORICAL_SET type FeatureValue to a ArrayType[DateType] column throws an error.
*/
@Test(
dataProvider = "FeatureValueToColumnConverterProvider",
expectedExceptions = Array(classOf[FeathrFeatureTransformationException]),
expectedExceptionsMessageRegExp = ".*only array of float/double/string/int is supported.*")
def testConvertCategoricalSetToUnsupportedElementTypeThrowsError(converter: FeatureValueToColumnConverter): Unit = {
val mockFeatureValue = mock[FeatureValue]
val mockTermVector = new ju.HashMap[String, jl.Float]()
mockTermVector.put("term1", 1.0f)
mockTermVector.put("term2", 1.0f)
mockTermVector.put("term3", 1.0f)
when(mockFeatureValue.getAsTermVector).thenReturn(mockTermVector)

converter.convert("f1", mockFeatureValue, ArrayType(DateType), CATEGORICAL_SET)
}
// @Test(
// dataProvider = "FeatureValueToColumnConverterProvider",
// expectedExceptions = Array(classOf[FeathrFeatureTransformationException]),
// expectedExceptionsMessageRegExp = ".*only array of float/double/string/int is supported.*")
// def testConvertCategoricalSetToUnsupportedElementTypeThrowsError(converter: FeatureValueToColumnConverter): Unit = {
// val mockFeatureValue = mock[FeatureValue]
// val mockTermVector = new ju.HashMap[String, jl.Float]()
// mockTermVector.put("term1", 1.0f)
// mockTermVector.put("term2", 1.0f)
// mockTermVector.put("term3", 1.0f)
// when(mockFeatureValue.getAsTermVector).thenReturn(mockTermVector)
//
// converter.convert("f1", mockFeatureValue, ArrayType(DateType), CATEGORICAL_SET)
// }

/**
* Test converting FeatureValue to DateType column throws exception because this is unsupported.
Expand Down

0 comments on commit 62dad74

Please sign in to comment.