Skip to content

Commit

Permalink
Fixed id-based query
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaro committed Nov 18, 2023
1 parent 4352a44 commit 17de019
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ abstract class AbstractDescriptorReader<D : Descriptor>(final override val field
*
* @return [Sequence] of all [Descriptor]s.
*/
override fun get(id: UUID): D? {
override fun get(id: UUID): D? = getBy(id, CottontailConnection.DESCRIPTOR_ID_COLUMN_NAME)

override fun getBy(id: UUID, columnName: String): D? {
val query = org.vitrivr.cottontail.client.language.dql.Query(this.entityName)
.where(Compare(Column(this.entityName.column(CottontailConnection.DESCRIPTOR_ID_COLUMN_NAME)), Compare.Operator.EQUAL, Literal(id.toString())))
.where(Compare(Column(this.entityName.column(columnName)), Compare.Operator.EQUAL, Literal(id.toString())))
return try {
val result = this.connection.client.query(query)
val ret = if (result.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ internal class RetrievableReader(private val connection: CottontailConnection) :
* @param id [RetrievableId]s to return.
* @return A [Sequence] of all [Retrievable].
*/
override fun get(id: RetrievableId): Retrievable? {
override fun get(id: RetrievableId): Retrievable? = getBy(id, RETRIEVABLE_ID_COLUMN_NAME)

override fun getBy(id: UUID, columnName: String): Retrievable? {
val query = Query(this.entityName).where(
Compare(
Column(this.entityName.column(RETRIEVABLE_ID_COLUMN_NAME)),
Column(this.entityName.column(columnName)),
Compare.Operator.EQUAL,
Literal(id.toString())
)
Expand All @@ -60,8 +62,8 @@ internal class RetrievableReader(private val connection: CottontailConnection) :
if (it.hasNext()) {
val tuple = it.next()
val retrievableId = UUID.fromString(
tuple.asString(RETRIEVABLE_ID_COLUMN_NAME)
?: throw IllegalArgumentException("The provided tuple is missing the required field '${RETRIEVABLE_ID_COLUMN_NAME}'.")
tuple.asString(columnName)
?: throw IllegalArgumentException("The provided tuple is missing the required field '${columnName}'.")
)
val type = tuple.asString(RETRIEVABLE_TYPE_COLUMN_NAME)
Retrieved.Default(retrievableId, type, false) /* TODO: Use UUID type once supported. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ import java.util.*
*/
interface Reader<out T : Persistable> {
/**
* Returns a [Persistable] of type [T] that corresponds to the provided [UUID].
* Returns a [Persistable] of type [T] that corresponds to the provided [UUID].
*
* @param id The [UUID] to return.
* @return [Sequence] of [Persistable] of type [T]
*/
operator fun get(id: UUID): T?

/**
* Returns a [Persistable] of type [T] that corresponds to the provided [UUID] in a specified columnName.
*/
fun getBy(id: UUID, columnName: String): T?

/**
* Checks if a [Persistable] of type [T] with the provided [UUID] exists.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class RetrievalRuntime {
val id = UUID.fromString((inputDescription as RetrievableIdInputData).id)

val reader = field.getReader()
val descriptor = reader[id] ?: throw IllegalArgumentException("No retrievable with id '$id' present in ${field.fieldName}")
val descriptor = reader.getBy(id, "retrievableId") ?: throw IllegalArgumentException("No retrievable with id '$id' present in ${field.fieldName}")

field.getRetrieverForDescriptor(descriptor, informationNeed.context)

Expand Down

0 comments on commit 17de019

Please sign in to comment.