Alexander
01/05/2024, 1:10 PMval queries = inputs.mapIndexed { idx, input ->
val markerColumn = intLiteral(idx).alias("inputSource")
MyTable
.slice(MyTable.columns + markerColumn)
.selectAll { MyTable.id eq input.id }
}.reduce { acc, query -> acc union query }
logic for making them all into a union is a bit trickier in reality, but that's the gist of it. the markerColumn
here is for knowing which input produced a given row.
But how can I get the value of the markerColumn
from a given ResultRow
?
The way it's currently done does not spark joy: row[row.fieldIndex.keys.last()] as Int
spand
01/05/2024, 1:14 PMrow[markerColumn]
work ?Alexander
01/05/2024, 1:15 PMAlexander
01/05/2024, 1:17 PMval columnAlias = Column<Int>("inputSource")
val queries = inputs.mapIndexed { idx, input ->
val markerColumn = intLiteral(idx).alias(columnAlias)
// same as above...
followed by row[columnAlias]
but I haven't figured out a way to do that. If I do MyTable.integer("inputSource")
it almost works, but says that there's an unknown column in the result set or something.spand
01/05/2024, 1:25 PMval alias = intLiteral(-1).alias("inputSource").aliasOnlyExpression()
...
val byString = row[alias]
spand
01/05/2024, 1:26 PMspand
01/05/2024, 1:26 PMAlexander
01/05/2024, 1:36 PMintLiteral(idx).alias("inputSource")
, I think this might be the only way