I'm trying to extract names of projected fields List[String] from a
List[RexNode]. It seems harder than it should be, which probably means I'm
doing it wrong.
`projects` is a java.util.List[RexNode]:
val projectsOrdered: Map[String, Int] = projects.asScala.zipWithIndex.map
{
case (rexNode: RexNode, index: Int) =>
// TODO: this odesn't work. toString wraps it in single quotes, e.g.
'listingId'
(rexNode.asInstanceOf[RexCall].operands.get(1).toString, index)
}.toMap
1. Is there a better way to do this where I end up with plain "listingId"
instead of "'listingId'"?
2. Alternatively, I noticed the Mongo adapter is using
MongoRules.RexToMongoTranslator. Perhaps this is the "correct" way to do it.
It's my first encounter with this concept (translators/RexVisitorImpls), and
I'm guessing it would handle the nested field case (whereas my List[String]
does not). It looks like it translates a RexNode to Mongo's query syntax. In my
case, I need a data structure that represents the potentially-nested
projection. Would this be an appropriate way to build up such a data structure?
Thanks,
Trevor