From 278b79fb2c3a1fb7fe0524eec35587fef1b85634 Mon Sep 17 00:00:00 2001 From: Ralph Gasser Date: Wed, 27 Mar 2024 11:52:16 +0100 Subject: [PATCH] FieldLookup now appends descriptor instead of a property map. --- .../engine/query/transform/FieldLookup.kt | 27 +++++-------------- .../query/transform/FieldLookupFactory.kt | 16 +++-------- 2 files changed, 9 insertions(+), 34 deletions(-) diff --git a/vitrivr-engine-query/src/main/kotlin/org/vitrivr/engine/query/transform/FieldLookup.kt b/vitrivr-engine-query/src/main/kotlin/org/vitrivr/engine/query/transform/FieldLookup.kt index df02223d..dad41134 100644 --- a/vitrivr-engine-query/src/main/kotlin/org/vitrivr/engine/query/transform/FieldLookup.kt +++ b/vitrivr-engine-query/src/main/kotlin/org/vitrivr/engine/query/transform/FieldLookup.kt @@ -6,6 +6,7 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.toList import org.vitrivr.engine.core.database.descriptor.DescriptorReader import org.vitrivr.engine.core.model.retrievable.Retrieved +import org.vitrivr.engine.core.model.retrievable.attributes.DescriptorAttribute import org.vitrivr.engine.core.model.retrievable.attributes.PropertyAttribute import org.vitrivr.engine.core.operators.Operator import org.vitrivr.engine.core.operators.retrieve.Transformer @@ -13,39 +14,23 @@ import org.vitrivr.engine.core.operators.retrieve.Transformer /** * Appends stringified key-value pairs to a [Retrieved] based on the values of a [Field], if available */ -class FieldLookup( - override val input: Operator, - private val reader: DescriptorReader<*>, - private val keys: Collection - -) : Transformer { +class FieldLookup(override val input: Operator, private val reader: DescriptorReader<*>) : Transformer { override fun toFlow(scope: CoroutineScope): Flow = flow { - + /* Parse input IDs.*/ val inputRetrieved = input.toFlow(scope).toList() - val ids = inputRetrieved.map { it.id }.toSet() - if (ids.isEmpty()) { return@flow } - val descriptors = - reader.getAllBy(ids, "retrievableId").filter { it.retrievableId != null }.associateBy { it.retrievableId!! } - + /* Perform lookup. */ + val descriptors = reader.getAllBy(ids, "retrievableId").filter { it.retrievableId != null }.associateBy { it.retrievableId!! } inputRetrieved.forEach { retrieved -> - val descriptor = descriptors[retrieved.id] - if (descriptor != null) { - val values = descriptor.values().toMap().mapValues { it.toString() } - val attribute = PropertyAttribute(values) - retrieved.addAttribute(attribute) + retrieved.addAttribute(DescriptorAttribute(descriptor)) } - emit(retrieved) - } - } - } \ No newline at end of file diff --git a/vitrivr-engine-query/src/main/kotlin/org/vitrivr/engine/query/transform/FieldLookupFactory.kt b/vitrivr-engine-query/src/main/kotlin/org/vitrivr/engine/query/transform/FieldLookupFactory.kt index ac29d0d9..6e6ae45d 100644 --- a/vitrivr-engine-query/src/main/kotlin/org/vitrivr/engine/query/transform/FieldLookupFactory.kt +++ b/vitrivr-engine-query/src/main/kotlin/org/vitrivr/engine/query/transform/FieldLookupFactory.kt @@ -5,21 +5,11 @@ import org.vitrivr.engine.core.model.retrievable.Retrieved import org.vitrivr.engine.core.operators.Operator import org.vitrivr.engine.core.operators.retrieve.TransformerFactory -class FieldLookupFactory( - -) : TransformerFactory { - override fun newTransformer( - input: Operator, - schema: Schema, - properties: Map - ): FieldLookup { - +class FieldLookupFactory() : TransformerFactory { + override fun newTransformer(input: Operator, schema: Schema, properties: Map): FieldLookup { val keys = properties["keys"]?.split(",")?.map { s -> s.trim() } ?: emptyList() val field = properties["field"] ?: throw IllegalArgumentException("expected 'field' to be defined in properties") val reader = (schema[field] ?: throw IllegalArgumentException("Field '$field' not defined in schema")).getReader() - - return FieldLookup( - input, reader, keys - ) + return FieldLookup(input, reader) } } \ No newline at end of file