Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds JSONL connection #88

Merged
merged 12 commits into from
Aug 6, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private fun convertType(directory: Directory, tagType: Int, type: Type): Value<*
Type.Short -> Value.Short(directory.getObject(tagType) as Short)
Type.String -> Value.String(directory.getString(tagType))
Type.Text -> Value.String(directory.getString(tagType))
Type.UUID -> Value.UUIDValue(UUID.fromString(directory.getString(tagType)))
is Type.BooleanVector -> throw IllegalArgumentException("Unsupported type: $type")
is Type.DoubleVector -> throw IllegalArgumentException("Unsupported type: $type")
is Type.FloatVector -> throw IllegalArgumentException("Unsupported type: $type")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vitrivr.engine.core.model.descriptor

import kotlinx.serialization.Serializable
import org.vitrivr.engine.core.model.types.Type

/** The name of an attribute. */
Expand All @@ -12,4 +13,5 @@ typealias AttributeName = String
* @author Ralph Gasser
* @version 1.0.0
*/
@Serializable
data class Attribute(val name: AttributeName, val type: Type, val nullable: Boolean = false)
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.vitrivr.engine.core.model.descriptor

import kotlinx.serialization.Serializable
import org.vitrivr.engine.core.model.Persistable
import org.vitrivr.engine.core.model.metamodel.Schema
import org.vitrivr.engine.core.model.retrievable.Retrievable
import org.vitrivr.engine.core.model.retrievable.RetrievableId
import org.vitrivr.engine.core.model.serializer.UUIDSerializer
import org.vitrivr.engine.core.model.types.Value
import java.util.*

/** A typealias to identify the [UUID] identifying a [Descriptor]. */
typealias DescriptorId = UUID
typealias DescriptorId = @Serializable(UUIDSerializer::class) UUID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works? Amazing!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was surprized too


/**
* A [Persistable] [Descriptor] that can be used to describe a [Retrievable].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vitrivr.engine.core.model.descriptor.scalar

import kotlinx.serialization.Serializable
import org.vitrivr.engine.core.model.descriptor.Attribute
import org.vitrivr.engine.core.model.descriptor.DescriptorId
import org.vitrivr.engine.core.model.descriptor.scalar.ScalarDescriptor.Companion.VALUE_ATTRIBUTE_NAME
Expand All @@ -14,7 +15,6 @@ import org.vitrivr.engine.core.model.types.Value
* @author Ralph Gasser
* @version 1.0.0
*/

data class FloatDescriptor(
override var id: DescriptorId,
override var retrievableId: RetrievableId?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vitrivr.engine.core.model.descriptor.scalar


import org.vitrivr.engine.core.model.descriptor.Attribute
import org.vitrivr.engine.core.model.descriptor.DescriptorId
import org.vitrivr.engine.core.model.descriptor.scalar.ScalarDescriptor.Companion.VALUE_ATTRIBUTE_NAME
Expand All @@ -14,7 +15,6 @@ import org.vitrivr.engine.core.model.types.Value
* @author Ralph Gasser
* @version 1.0.0
*/

data class LongDescriptor(
override var id: DescriptorId,
override var retrievableId: RetrievableId?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vitrivr.engine.core.model.descriptor.scalar

import kotlinx.serialization.Serializable
import org.vitrivr.engine.core.model.descriptor.AttributeName
import org.vitrivr.engine.core.model.descriptor.Descriptor
import org.vitrivr.engine.core.model.types.Value
Expand All @@ -10,6 +11,7 @@ import org.vitrivr.engine.core.model.types.Value
* @author Ralph Gasser
* @version 1.1.0
*/
@Serializable
sealed interface ScalarDescriptor<T : Value.ScalarValue<*>> : Descriptor {

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.vitrivr.engine.core.model.retrievable

import kotlinx.serialization.Serializable
import org.vitrivr.engine.core.model.Persistable
import org.vitrivr.engine.core.model.content.element.ContentElement
import org.vitrivr.engine.core.model.descriptor.Descriptor
import org.vitrivr.engine.core.model.relationship.Relationship
import org.vitrivr.engine.core.model.retrievable.attributes.RetrievableAttribute
import org.vitrivr.engine.core.model.serializer.UUIDSerializer
import java.util.*
import java.util.function.Predicate

/** A typealias to identify the [UUID] identifying a [Retrievable]. */
typealias RetrievableId = UUID
typealias RetrievableId = @Serializable(UUIDSerializer::class) UUID

/**
* A [Persistable] and [Retrievable] unit of information stored by vitrivr.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.vitrivr.engine.core.model.serializer

import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import java.util.*

object DateSerializer: KSerializer<Date> {
override val descriptor = PrimitiveSerialDescriptor("Date", PrimitiveKind.LONG)
override fun serialize(encoder: Encoder, value: Date) = encoder.encodeLong(value.time)
override fun deserialize(decoder: Decoder): Date = Date(decoder.decodeLong())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.vitrivr.engine.core.model.serializer

import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import org.vitrivr.engine.core.model.types.Value
import java.util.*

object DateTimeSerializer: KSerializer<Value.DateTime> {
override val descriptor = PrimitiveSerialDescriptor("DateTime", PrimitiveKind.LONG)
override fun serialize(encoder: Encoder, value: Value.DateTime) = encoder.encodeLong(value.value.time)
override fun deserialize(decoder: Decoder): Value.DateTime = Value.DateTime(Date(decoder.decodeLong()))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.vitrivr.engine.core.model.serializer

import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import java.util.UUID

object UUIDSerializer: KSerializer<UUID> {
override val descriptor = PrimitiveSerialDescriptor("UUID", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: UUID) = encoder.encodeString(value.toString())
override fun deserialize(decoder: Decoder): UUID = UUID.fromString(decoder.decodeString())
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.vitrivr.engine.core.model.types

import kotlinx.serialization.Serializable
import java.util.*

/**
Expand Down Expand Up @@ -55,6 +56,7 @@ sealed interface Type {
*
* Primarily needed, since simple strings and longer texts are treated differently by certain databases.
*/
@Serializable
data object Text : Type {
override val dimensions: kotlin.Int = 1
override fun defaultValue(): Value<*> = Value.String("")
Expand All @@ -65,6 +67,7 @@ sealed interface Type {
*
* Primarily needed, since simple strings and longer texts are treated differently by certain databases.
*/
@Serializable
data object String : Type {
override val dimensions: kotlin.Int = 1
override fun defaultValue(): Value<*> = Value.String("")
Expand All @@ -73,6 +76,7 @@ sealed interface Type {
/**
* A [Type] that represents a [Boolean] value.
*/
@Serializable
data object Boolean : Type {
override val dimensions: kotlin.Int = 1
override fun defaultValue(): Value<*> = Value.Boolean(false)
Expand All @@ -81,6 +85,7 @@ sealed interface Type {
/**
* A [Type] that represents a [Byte] value.
*/
@Serializable
data object Byte : Type {
override val dimensions: kotlin.Int = 1
override fun defaultValue(): Value<*> = Value.Byte(0)
Expand All @@ -89,6 +94,7 @@ sealed interface Type {
/**
* A [Type] that represents a [Short] value.
*/
@Serializable
data object Short : Type {
override val dimensions: kotlin.Int = 1
override fun defaultValue(): Value<*> = Value.Short(0)
Expand All @@ -97,6 +103,7 @@ sealed interface Type {
/**
* A [Type] that represents a [Int] value.
*/
@Serializable
data object Int : Type {
override val dimensions: kotlin.Int = 1
override fun defaultValue(): Value<*> = Value.Int(0)
Expand All @@ -105,6 +112,7 @@ sealed interface Type {
/**
* A [Type] that represents a [Long] value.
*/
@Serializable
data object Long : Type {
override val dimensions: kotlin.Int = 1
override fun defaultValue(): Value<*> = Value.Long(0L)
Expand All @@ -113,6 +121,7 @@ sealed interface Type {
/**
* A [Type] that represents a [Float] value.
*/
@Serializable
data object Float : Type {
override val dimensions: kotlin.Int = 1
override fun defaultValue(): Value<*> = Value.Float(0.0f)
Expand All @@ -121,6 +130,7 @@ sealed interface Type {
/**
* A [Type] that represents a [Double] value.
*/
@Serializable
data object Double : Type {
override val dimensions: kotlin.Int = 1
override fun defaultValue(): Value<*> = Value.Double(0.0)
Expand All @@ -129,42 +139,57 @@ sealed interface Type {
/**
* A [Type] that represents a [Datetime] value.
*/
@Serializable
data object Datetime : Type {
override val dimensions: kotlin.Int = 1
override fun defaultValue(): Value<*> = Value.DateTime(Date())
}

/**
* A [Type] that represents a [UUID] value.
*/
@Serializable
data object UUID : Type {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so I can understand why this is needed: UUIDs (thus far) are only used internally by the engine as IDs. Adding this as a type basically means, that we want to be able to actually use UUIDs as fields. Is that the intent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I had to touch the type system anyway to make everything serializable, I thought adding this would be nice for completeness' sake. This way, the type can be used, for example, in a struct descriptor that needs to deal with external identifiers.

override val dimensions: kotlin.Int = 1
override fun defaultValue(): Value<*> = Value.UUIDValue(java.util.UUID(0L, 0L))
}

/**
* A [Type] that represents a [BooleanVector] value.
*/
@Serializable
data class BooleanVector(override val dimensions: kotlin.Int) : Type {
override fun defaultValue(): Value<*> = Value.BooleanVector(this.dimensions)
}

/**
* A [Type] that represents a [IntVector] value.
*/
@Serializable
data class IntVector(override val dimensions: kotlin.Int) : Type {
override fun defaultValue(): Value<*> = Value.IntVector(this.dimensions)
}

/**
* A [Type] that represents a [LongVector] value.
*/
@Serializable
data class LongVector(override val dimensions: kotlin.Int) : Type {
override fun defaultValue(): Value<*> = Value.LongVector(this.dimensions)
}

/**
* A [Type] that represents a [FloatVector] value.
*/
@Serializable
data class FloatVector(override val dimensions: kotlin.Int) : Type {
override fun defaultValue(): Value<*> = Value.FloatVector(this.dimensions)
}

/**
* A [Type] that represents a [DoubleVector] value.
*/
@Serializable
data class DoubleVector(override val dimensions: kotlin.Int) : Type {
override fun defaultValue(): Value<*> = Value.DoubleVector(this.dimensions)
}
Expand Down
Loading