Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions zoe-core/src/functions/poll.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.fasterxml.jackson.annotation.JsonValue
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.NullNode
import com.fasterxml.jackson.databind.node.ObjectNode
import com.fasterxml.jackson.databind.node.TextNode
import org.apache.avro.generic.GenericDatumWriter
import org.apache.avro.generic.GenericRecord
import org.apache.avro.io.EncoderFactory
Expand Down Expand Up @@ -213,7 +214,7 @@ private class ProgressListener(val consumer: Consumer<*, *>) {

object Jsonifiers {
// TODO : enable injection of custom jsonifiers
private val jsonifiers = sequenceOf(GenericRecordToAvroJson(), RawToJson()).map { it.name() to it }.toMap()
private val jsonifiers = sequenceOf(GenericRecordToAvroJson(), RawToJson(), RawToTextNode()).map { it.name() to it }.toMap()

fun get(name: String): Jsonifier =
jsonifiers[name] ?: throw IllegalArgumentException("jsonifier not found : $name")
Expand Down Expand Up @@ -245,10 +246,15 @@ class GenericRecordToAvroJson : Jsonifier {
}

class RawToJson : Jsonifier {
override fun name(): String = "raw"
override fun name(): String = "json"
override fun format(input: Any): JsonNode = json.readTree(input.toString())
}

class RawToTextNode : Jsonifier {
override fun name(): String = "raw"
override fun format(input: Any): JsonNode = TextNode(input.toString())
}

data class PartitionProgress(
val topic: String,
val partition: Int,
Expand Down Expand Up @@ -293,4 +299,4 @@ enum class JsonQueryDialect(@JsonValue val code: String) { Jmespath("jmespath"),
fun JsonQueryDialect.createInstance(): JsonSearch = when (this) {
JsonQueryDialect.Jmespath -> JmespathImpl()
JsonQueryDialect.Jq -> JqImpl()
}
}