Anyone know of a way to select a literal? The actu...
# exposed
a
Anyone know of a way to select a literal? The actual implementation is long and quite specific, but I have something like this:
Copy code
val 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
s
doesnt
row[markerColumn]
work ?
a
because I need the index when creating the marker column it has to be created within the map, so it's unique for each query in the union.
ideally I'd have something like:
Copy code
val 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.
s
I dont think it works but I guess exposed ought to work like this:
Copy code
val alias = intLiteral(-1).alias("inputSource").aliasOnlyExpression()

...

val byString = row[alias]
But looking at the code it seems to boil down to identity equality
Seems like a good case to have supported. You should make a feature request
a
Will do that. Figured I might be missing something, but maybe it's just not possible atm. I think what's needed is some way to add extra columns, because looking in the debugger the key is the literal itself, so it probably isn't possible to get it without knowing what the value is. So using
intLiteral(idx).alias("inputSource")
, I think this might be the only way