Skip to content

Commit

Permalink
some basic/flawed (not supporting escape characters) to handle both l…
Browse files Browse the repository at this point in the history
…ookup values AND properties
  • Loading branch information
timvw committed Nov 7, 2023
1 parent bf25a02 commit 7fbb17a
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ case class ListLookupValuesContributor(lookupFilesByName: Map[String, File], sou
private case class ListLookupRule(lookupfileName: String, phyiscalColumnName: String, resultSchemaField: StructField)

private val listLookupRules = List(
ListLookupRule(LookupFile.Names.event, "event_list", StructField("event_list", ArrayType(StringType))),
ListLookupRule(LookupFile.Names.event, "post_event_list", StructField("post_event_list", ArrayType(StringType))))

override def getFieldsWhichCanBeContributed(): List[StructField] = rulesWhichCanContribute.map(_.resultSchemaField)
Expand All @@ -34,9 +35,16 @@ case class ListLookupValuesContributor(lookupFilesByName: Map[String, File], sou
(row: GenericInternalRow, columns: Array[String]) => {
val parsedValue = columns(physicalFieldIndex)
val value = if (parsedValue == null) null else {
val listValues = parsedValue.split(",")
val lookedupValues = listValues.map(x => lookupDatabase.get(x.getBytes))
ArrayData.toArrayData(lookedupValues.map(x => if (x == null) null else UTF8String.fromBytes(x)))
val items = parsedValue.split(",")
val lookupedValuesAndProperties = items.map(x => {
if(x.contains("=")) {
UTF8String.fromString(x)
} else {
val foundValue = lookupDatabase.get(x.getBytes)
if (foundValue == null) null else UTF8String.fromBytes(foundValue)
}
})
ArrayData.toArrayData(lookupedValuesAndProperties)
}
row.update(requestedFieldIndex, value)
}
Expand Down

0 comments on commit 7fbb17a

Please sign in to comment.