From 95b20592ac2f6effce656150bd326baf859aec57 Mon Sep 17 00:00:00 2001
From: discord9 <55937128+discord9@users.noreply.github.com>
Date: Tue, 14 Jan 2025 17:06:53 +0800
Subject: [PATCH] fix: handle insert default value (#5307)
* fix: handle flow inserts with default values
* test: sqlness
* chore: typo
* chore: newline
* feat(WIP): impure default filler
* feat: fill impure default values
* test: add test for default fill impure
* feat: check for impure
* fix: also handle stmt to region
* refactor: per review
* refactor: per review
* chore: rebase fix
* chore: clippy
* chore: per review
---
src/datatypes/src/schema/column_schema.rs | 17 ++
src/datatypes/src/schema/constraint.rs | 51 ++++
src/flow/src/adapter/flownode_impl.rs | 62 ++++-
src/flow/src/adapter/node_context.rs | 2 +-
src/flow/src/adapter/table_source.rs | 58 ++++-
src/flow/src/adapter/util.rs | 15 +-
src/mito2/src/error.rs | 17 +-
src/mito2/src/request.rs | 61 ++++-
src/operator/src/insert.rs | 81 ++++--
src/operator/src/req_convert/insert.rs | 2 +
.../req_convert/insert/fill_impure_default.rs | 242 ++++++++++++++++++
.../src/req_convert/insert/stmt_to_region.rs | 25 +-
.../common/flow/flow_ins_default.result | 70 +++++
.../common/flow/flow_ins_default.sql | 41 +++
14 files changed, 685 insertions(+), 59 deletions(-)
create mode 100644 src/operator/src/req_convert/insert/fill_impure_default.rs
create mode 100644 tests/cases/standalone/common/flow/flow_ins_default.result
create mode 100644 tests/cases/standalone/common/flow/flow_ins_default.sql
diff --git a/src/datatypes/src/schema/column_schema.rs b/src/datatypes/src/schema/column_schema.rs
index ffe9d2eb4a..c22b9f7b4a 100644
--- a/src/datatypes/src/schema/column_schema.rs
+++ b/src/datatypes/src/schema/column_schema.rs
@@ -123,6 +123,14 @@ impl ColumnSchema {
self.default_constraint.as_ref()
}
+ /// Check if the default constraint is a impure function.
+ pub fn is_default_impure(&self) -> bool {
+ self.default_constraint
+ .as_ref()
+ .map(|c| c.is_function())
+ .unwrap_or(false)
+ }
+
#[inline]
pub fn metadata(&self) -> &Metadata {
&self.metadata
@@ -290,6 +298,15 @@ impl ColumnSchema {
}
}
+ /// Creates an impure default value for this column, only if it have a impure default constraint.
+ /// Otherwise, returns `Ok(None)`.
+ pub fn create_impure_default(&self) -> Result