Skip to content

Commit

Permalink
#1000 Resolved issue with calc columns not working on joined tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjstevo committed Jan 28, 2024
1 parent 3ddf8a8 commit 370cc4e
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 120 deletions.
4 changes: 3 additions & 1 deletion vuu/src/main/scala/org/finos/vuu/core/table/Column.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ object Columns {

def aliased(table: TableDef, aliases: (String, String)*): Array[Column] = {
val aliased = aliases.map(tuple => tuple._1 -> tuple._2).toMap
table.columns.filter(c => aliased.contains(c.name)) map (c => new AliasedJoinColumn(aliased.get(c.name).get, c.index, c.dataType, table, c).asInstanceOf[Column])
table.columns.filter(c => aliased.contains(c.name)) map (c => new AliasedJoinColumn(aliased(c.name), c.index, c.dataType, table, c).asInstanceOf[Column])
}

//def calculated(name: String, definition: String): Array[Column] = ???
Expand Down Expand Up @@ -124,6 +124,8 @@ class AliasedJoinColumn(name: String, index: Int, dataType: Class[_], sourceTabl

class JoinColumn(name: String, index: Int, dataType: Class[_], val sourceTable: TableDef, val sourceColumn: Column) extends SimpleColumn(name, index, dataType) {

override def toString: String = s"JoinColumn($name, ${sourceTable.name}:${sourceColumn.name})"

override def hashCode(): Int = (sourceTable.name + "." + sourceColumn + "@" + name).hashCode

override def getDataFullyQualified(data: RowData): Any = data.get(sourceTable.fullyQuallifiedColumnName(name))
Expand Down
109 changes: 58 additions & 51 deletions vuu/src/main/scala/org/finos/vuu/core/table/JoinTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ case class JoinDataTableData(tableDef: JoinTableDef, var keysByJoinIndex: Array[
}

def primaryKeyIndicesByTable: List[Boolean] = {
columns.map(c => c match {
columns.map {
case jc: JoinColumn => isPrimaryKeyColumn(jc)

}).toList
case _ => false
}.toList
}

def getKeyValuesByTable(origPrimaryKey: String): Map[String, String] = {
Expand Down Expand Up @@ -429,7 +429,7 @@ class JoinTable(val tableDef: JoinTableDef, val sourceTables: Map[String, DataTa
.map(c => c.asInstanceOf[JoinColumn]).groupBy(_.sourceTable.name)

val calculatedColumns = columns.getColumns()
.filter(_.isInstanceOf[CalculatedColumn]).toList
.filter(_.isInstanceOf[CalculatedColumn])

val keysByTable = joinData.getKeyValuesByTable(key)

Expand Down Expand Up @@ -469,53 +469,60 @@ class JoinTable(val tableDef: JoinTableDef, val sourceTables: Map[String, DataTa

override def pullRowAsArray(key: String, columns: ViewPortColumns): Array[Any] = {

val columnsByTable = columns.getColumns()
.map(c => c.asInstanceOf[JoinColumn])
.groupBy(_.sourceTable.name)

val keysByTable = joinData.getKeyValuesByTable(key)

if (keysByTable == null || !keyExistsInLeftMostSourceTable(key))
Array()
else {

val foldedMap = columnsByTable.foldLeft(Map[JoinColumn, Any]())({ case (previous, (tableName, columnList)) =>

val table = sourceTables(tableName)

val fk = if (keysByTable == null) null
else
keysByTable.get(tableName) match {
case Some(fk) => fk
case None => null
}

//val sourceColumns = columnList.map(jc => jc.sourceColumn)
val sourceColumns = ViewPortColumnCreator.create(table, columnList.map(jc => jc.sourceColumn).map(_.name))

if (fk == null) {
logger.info(s"No foreign key for table $tableName found in join ${tableDef.name} for primary key $key")
previous
}
else {
table.pullRow(fk, sourceColumns) match {
case EmptyRowData =>
previous
case data: RowWithData =>
previous ++ columnList.map(column => (column -> column.sourceColumn.getData(data)))
}
}
})

if (foldedMap.isEmpty) {
Array()
} else {
columns.getColumns().map(c => foldedMap.get(c.asInstanceOf[JoinColumn]) match {
case None => ""
case Some(x) => x
}).toArray[Any]
}
}
val asRowData = pullRow(key, columns)

val asArray = asRowData.toArray(columns.getColumns())

asArray

// val columnsByTable = columns.getColumns()
// .filter(_.isInstanceOf[JoinColumn])
// .map(c => c.asInstanceOf[JoinColumn])
// .groupBy(_.sourceTable.name)
//
// val keysByTable = joinData.getKeyValuesByTable(key)
//
// if (keysByTable == null || !keyExistsInLeftMostSourceTable(key))
// Array()
// else {
//
// val foldedMap = columnsByTable.foldLeft(Map[JoinColumn, Any]())({ case (previous, (tableName, columnList)) =>
//
// val table = sourceTables(tableName)
//
// val fk = if (keysByTable == null) null
// else
// keysByTable.get(tableName) match {
// case Some(fk) => fk
// case None => null
// }
//
// //val sourceColumns = columnList.map(jc => jc.sourceColumn)
// val sourceColumns = ViewPortColumnCreator.create(table, columnList.map(jc => jc.sourceColumn).map(_.name))
//
// if (fk == null) {
// logger.info(s"No foreign key for table $tableName found in join ${tableDef.name} for primary key $key")
// previous
// }
// else {
// table.pullRow(fk, sourceColumns) match {
// case EmptyRowData =>
// previous
// case data: RowWithData =>
// previous ++ columnList.map(column => (column -> column.sourceColumn.getData(data)))
// }
// }
// })
//
// if (foldedMap.isEmpty) {
// Array()
// } else {
// columns.getColumns().map(c => foldedMap.get(c.asInstanceOf[JoinColumn]) match {
// case None => ""
// case Some(x) => x
// }).toArray[Any]
// }
// }
}

def notifyListeners(rowKey: String): Unit = {
Expand Down
Loading

0 comments on commit 370cc4e

Please sign in to comment.