feat(engine): extend Executor with buildInsertRow
This commit is contained in:
1 parent
469d310982
commit
2a0c532de3
1 file changed
+30
-2
@@ -1303,13 +1303,41 @@ class Executor(private val catalog: Catalog) : SequenceAccess {
|
|||||||
ForeignKeyEnforcer.validateRow(catalog, schema, row.values, uncommittedSiblings = newRows)
|
ForeignKeyEnforcer.validateRow(catalog, schema, row.values, uncommittedSiblings = newRows)
|
||||||
enforceChecks(schema, row)
|
enforceChecks(schema, row)
|
||||||
}
|
}
|
||||||
|
enforcePrimaryKeyUniqueness(schema, table.rows + newRows)
|
||||||
|
enforceUniqueConstraints(schema, table.rows + newRows)
|
||||||
|
enforceUniqueIndexes(schema, table.rows + newRows)
|
||||||
|
table.rows.addAll(newRows)
|
||||||
|
catalog.reindexTable(schema.name)
|
||||||
|
fireRowTriggers(schema, TriggerTiming.After, TriggerEvent.Insert, newRows.map { null to it })
|
||||||
|
val returning = statement.returning?.let { evaluateReturning(schema, newRows, it) }
|
||||||
|
return InsertResult(newRows.size, returning)
|
||||||
|
}
|
||||||
|
return executeInsertWithConflictHandling(schema, table, newRows, onConflict, statement.returning, triggerContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildInsertRow(
|
||||||
|
schema: TableSchema,
|
||||||
|
targetIndices: List<Int>,
|
||||||
|
rawRow: List<Expression?>,
|
||||||
|
evaluator: Evaluator
|
||||||
|
): Row {
|
||||||
|
if (rawRow.size != targetIndices.size) {
|
||||||
|
throw KestrelException(
|
||||||
|
"table ${schema.name} expects ${targetIndices.size} values but ${rawRow.size} were supplied"
|
||||||
|
)
|
||||||
|
}
|
||||||
val values = MutableList<Value>(schema.columns.size) { Value.NullValue }
|
val values = MutableList<Value>(schema.columns.size) { Value.NullValue }
|
||||||
|
val touched = BooleanArray(schema.columns.size)
|
||||||
for ((position, expression) in rawRow.withIndex()) {
|
for ((position, expression) in rawRow.withIndex()) {
|
||||||
val columnIndex = targetIndices[position]
|
val columnIndex = targetIndices[position]
|
||||||
|
// A literal DEFAULT in the VALUES list is left untouched here, exactly like a
|
||||||
|
// column missing from an explicit INSERT column list - both fall through to the
|
||||||
|
// same default-filling loop below, matching UPDATE ... SET col = DEFAULT semantics.
|
||||||
|
if (expression != null) {
|
||||||
|
rejectGeneratedAssignment(schema.columns[columnIndex], explicitValueGiven = true)
|
||||||
values[columnIndex] = coerceForColumn(evaluator.evaluate(expression), schema.columns[columnIndex])
|
values[columnIndex] = coerceForColumn(evaluator.evaluate(expression), schema.columns[columnIndex])
|
||||||
|
touched[columnIndex] = true
|
||||||
}
|
}
|
||||||
validateNotNull(schema, values)
|
|
||||||
Row(values)
|
|
||||||
}
|
}
|
||||||
enforcePrimaryKeyUniqueness(schema, table.rows + newRows)
|
enforcePrimaryKeyUniqueness(schema, table.rows + newRows)
|
||||||
table.rows.addAll(newRows)
|
table.rows.addAll(newRows)
|
||||||
|
|||||||
Reference in new issue
Block a user