Skip to content
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
3 changes: 2 additions & 1 deletion spark/src/main/scala/ai/chronon/spark/GroupBy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,8 @@ object GroupBy {
tableUtils.scanDfBase(
selects,
if (mutations) source.getEntities.mutationTable.cleanSpec else source.table,
Option(source.query.wheres).map(_.toScala).getOrElse(Seq.empty[String]) ++ partitionConditions,
Option(source.query.wheres).map(_.toScala).getOrElse(Seq.empty[String]),
partitionConditions,
Some(metaColumns ++ keys.map(_ -> null))
)
}
Expand Down
4 changes: 2 additions & 2 deletions spark/src/main/scala/ai/chronon/spark/Join.scala
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ class Join(joinConf: api.Join,
} else {
leftRange
}
val wheres = Seq(s"ds >= '${effectiveRange.start}'", s"ds <= '${effectiveRange.end}'")
val wheres = effectiveRange.whereClauses("ds")
val sql = QueryUtils.build(null, partTable, wheres)
logger.info(s"Pulling data from joinPart table with: $sql")
(joinPart, tableUtils.scanDfBase(null, partTable, wheres))
(joinPart, tableUtils.scanDfBase(null, partTable, List.empty, wheres, None))
}
}

Expand Down
8 changes: 6 additions & 2 deletions spark/src/main/scala/ai/chronon/spark/TableUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,8 @@ case class TableUtils(sparkSession: SparkSession) {

def scanDfBase(selectMap: Map[String, String],
table: String,
wheres: scala.collection.Seq[String],
wheres: Seq[String],
rangeWheres: Seq[String],
fallbackSelects: Option[Map[String, String]] = None): DataFrame = {
val dp = DataPointer(table)
var df = dp.toDf(sparkSession)
Expand All @@ -798,9 +799,12 @@ case class TableUtils(sparkSession: SparkSession) {
| ${selects.mkString("\n ").green}
| wheres:
| ${wheres.mkString(",\n ").green}
| partition filters:
| ${rangeWheres.mkString(",\n ").green}
|""".stripMargin.yellow)
if (selects.nonEmpty) df = df.selectExpr(selects: _*)
if (wheres.nonEmpty) df = df.where(wheres.map(w => s"($w)").mkString(" AND "))
if (rangeWheres.nonEmpty) df = df.where(rangeWheres.map(w => s"($w)").mkString(" AND "))
df
}

Expand All @@ -822,7 +826,7 @@ case class TableUtils(sparkSession: SparkSession) {

val selects = Option(query).flatMap(q => Option(q.selects)).map(_.toScala).getOrElse(Map.empty)

scanDfBase(selects, table, wheres, fallbackSelects)
scanDfBase(selects, table, wheres, rangeWheres, fallbackSelects)
}

def partitionRange(table: String): PartitionRange = {
Expand Down
Loading