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

Allow spark expressions in field mapping during Ingestion #1122

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
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 @@ -18,7 +18,7 @@ package feast.ingestion

import org.apache.spark.SparkConf
import org.apache.spark.sql.{Column, SparkSession}
import org.apache.spark.sql.functions.col
import org.apache.spark.sql.functions.expr
import org.apache.spark.sql.streaming.StreamingQuery

trait BasePipeline {
Expand Down Expand Up @@ -87,7 +87,7 @@ trait BasePipeline {
.map(e => (e.name, e.name))

(featureColumns ++ entitiesColumns ++ timestampColumn).map { case (alias, source) =>
col(source).alias(alias)
expr(source).alias(alias)
}.toArray
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,38 @@ class BatchPipelineIT extends SparkSpec with ForAllTestContainer {
)
})
}

"Spark expressions" should "be allowed in mapping" in new Scope {
val gen = rowGenerator(DateTime.parse("2020-08-01"), DateTime.parse("2020-09-01"))
val rows = generateDistinctRows(gen, 100, groupByEntity)

val tempPath = storeAsParquet(sparkSession, rows)

val configWithMapping = config.copy(
source = FileSource(
tempPath,
Map(
"feature1" -> "feature1 + 1",
"feature2" -> "feature1 + feature2 * 2"
),
"eventTimestamp"
)
)

BatchPipeline.createPipeline(sparkSession, configWithMapping)

val featureKeyEncoder: String => String = encodeFeatureKey(config.featureTable)

rows.foreach(r => {
val storedValues =
jedis.hgetAll(encodeEntityKey(r, configWithMapping.featureTable)).asScala.toMap
storedValues should beStoredRow(
Map(
featureKeyEncoder("feature1") -> (r.feature1 + 1),
featureKeyEncoder("feature2") -> (r.feature1 + r.feature2 * 2),
"_ts:test-fs" -> r.eventTimestamp
)
)
})
}
}