Skip to content

Commit c31591e

Browse files
committed
feat(SplitNodeHandler): support path expressions
1 parent 67d9292 commit c31591e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

integrations/builtin/src/main/kotlin/me/snoty/integration/builtin/split/SplitNodeHandler.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package me.snoty.integration.builtin.split
22

33
import kotlinx.serialization.Serializable
4+
import me.snoty.backend.utils.bson.getByPath
5+
import me.snoty.backend.utils.bson.setByPath
46
import me.snoty.integration.common.annotation.RegisterNode
57
import me.snoty.integration.common.model.NodePosition
68
import me.snoty.integration.common.model.metadata.EmptySchema
@@ -55,7 +57,7 @@ class SplitNodeHandler : NodeHandler {
5557
input: Collection<IntermediateData>
5658
): NodeOutput = mapInputWithSettings<Document, SplitSettings>(input, node) { data, settings ->
5759
val key = settings.key
58-
val splitData = data[key] ?: throw IllegalArgumentException("Key '$key' not found in input data")
60+
val splitData = data.getByPath(key) ?: throw IllegalArgumentException("Key '$key' not found in input data")
5961

6062
val list = when (splitData) {
6163
is List<*> -> splitData.filterNotNull()
@@ -68,7 +70,7 @@ class SplitNodeHandler : NodeHandler {
6870
SplitBehavior.REPLACE_ROOT -> serializePolymorphic(item)
6971
SplitBehavior.REPLACE_KEY -> {
7072
val document = Document(data)
71-
document.put(key, item)
73+
document.setByPath(key, item)
7274
serializeBson(document)
7375
}
7476
}

0 commit comments

Comments
 (0)