diff --git a/cottontaildb-client/src/main/kotlin/org/vitrivr/cottontail/core/database/ColumnDef.kt b/cottontaildb-client/src/main/kotlin/org/vitrivr/cottontail/core/database/ColumnDef.kt index c8b29a3cb..76527edff 100644 --- a/cottontaildb-client/src/main/kotlin/org/vitrivr/cottontail/core/database/ColumnDef.kt +++ b/cottontaildb-client/src/main/kotlin/org/vitrivr/cottontail/core/database/ColumnDef.kt @@ -13,16 +13,6 @@ import org.vitrivr.cottontail.core.types.Value */ @Serializable data class ColumnDef(val name: Name.ColumnName, val type: Types, val nullable: Boolean = true, val primary: Boolean = false, val autoIncrement: Boolean = false) { - - /** - * Validates a value with regard to this [ColumnDef] return a flag indicating whether validation was passed. - * - * @param value The value that should be validated. - * @return True if value passes validation, false otherwise. - */ - fun validate(value: Value?): Boolean - = ((value == null && this.nullable) || (value != null && this.type == value.type)) - /** * Creates and returns a [String] representation of this [ColumnDef]. */ diff --git a/cottontaildb-client/src/main/kotlin/org/vitrivr/cottontail/core/tuple/StandaloneTuple.kt b/cottontaildb-client/src/main/kotlin/org/vitrivr/cottontail/core/tuple/StandaloneTuple.kt index c46b22c21..8252f8996 100644 --- a/cottontaildb-client/src/main/kotlin/org/vitrivr/cottontail/core/tuple/StandaloneTuple.kt +++ b/cottontaildb-client/src/main/kotlin/org/vitrivr/cottontail/core/tuple/StandaloneTuple.kt @@ -30,8 +30,8 @@ class StandaloneTuple(override var tupleId: TupleId, override val columns: Array init { require(this.columns.size == this.values.size) { "Number of values and number of columns must be the same." } - for ((i, c) in this.columns.withIndex()) { - require(c.validate(this.values[i])) { "Value ${this.values[i]} is incompatible with column $c." } + for ((c, v) in this.columns.zip(this.values)) { + require(((v == null && c.nullable) || (v != null && c.type == v.type))) { "Value $v is incompatible with column $c." } } } @@ -72,10 +72,7 @@ class StandaloneTuple(override var tupleId: TupleId, override val columns: Array * @param index The index for which to retrieve the value. * @return The value for the column index. */ - override fun get(index: Int): Value? { - require(index in (0 until this.size)) { "The specified column $index is out of bounds." } - return this.values[index] - } + override fun get(index: Int): Value? = this.values[index] /** * Returns a [List] of [Value]s contained in this [StandaloneTuple]. @@ -91,8 +88,8 @@ class StandaloneTuple(override var tupleId: TupleId, override val columns: Array * @param value The new [Value] */ override fun set(index: Int, value: Value?) { - require(index in (0 until this.size)) { "The specified column $index is out of bounds." } - require(this.columns[index].validate(value)) { "Provided value $value is incompatible with column ${this.columns[index]}." } + val column = this.columns[index] + require(((value == null && column.nullable) || (value != null && value.type == column.type))) { "Provided value $value is incompatible with column ${this.columns[index]}." } this.values[index] = value } diff --git a/cottontaildb-dbms/src/main/kotlin/org/vitrivr/cottontail/dbms/queries/binding/TupleBinding.kt b/cottontaildb-dbms/src/main/kotlin/org/vitrivr/cottontail/dbms/queries/binding/TupleBinding.kt index c7e4d8398..c2641ef34 100644 --- a/cottontaildb-dbms/src/main/kotlin/org/vitrivr/cottontail/dbms/queries/binding/TupleBinding.kt +++ b/cottontaildb-dbms/src/main/kotlin/org/vitrivr/cottontail/dbms/queries/binding/TupleBinding.kt @@ -12,10 +12,18 @@ import org.vitrivr.cottontail.core.types.Value * A [Tuple] implementation that depends on the existence of [Binding]s for the [Value]s it contains. Used for inserts. * * @author Ralph Gasser - * @version 1.1.0 + * @version 1.2.0 */ class TupleBinding(override var tupleId: TupleId, override val columns: Array>, private val values: Array, private val context: BindingContext) : MutableTuple { + init { + require(this.columns.size == this.values.size) { "Number of values and number of columns must be the same." } + for ((c, b) in this.columns.zip(this.values)) { + require(c.nullable == b.canBeNull) { "Value binding $b is incompatible with column $c." } + require(c.type == b.type) { "Value binding $b is incompatible with column $c." } + } + } + /** * Creates a copy of this [TupleBinding] */