You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by da...@apache.org on 2024/09/26 03:05:23 UTC
(doris) 04/04: [Fix](Nerieds) insert into table with default not null but not included in insert schema (#39825)
This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
commit 1083cb0d440cc4ffdfe5bd70c6a65d7e6d2706ac
Author: LiBinfeng <46...@users.noreply.github.com>
AuthorDate: Wed Aug 28 17:21:43 2024 +0800
[Fix](Nerieds) insert into table with default not null but not included in insert schema (#39825)
example:
create table t(k1 int not null, k2 int not null);
insert into t (k1) values (101);
it should be failed because we don't know what value should k2 be
---
.../src/main/java/org/apache/doris/analysis/NativeInsertStmt.java | 3 ++-
.../main/java/org/apache/doris/nereids/rules/analysis/BindSink.java | 2 +-
.../apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java | 2 +-
.../src/test/java/org/apache/doris/nereids/util/ReadLockTest.java | 3 ++-
4 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
index db08e699793..132d2a86b22 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java
@@ -923,7 +923,8 @@ public class NativeInsertStmt extends InsertStmt {
Column col = targetColumns.get(i);
if (expr instanceof DefaultValueExpr) {
- if (targetColumns.get(i).getDefaultValue() == null && !targetColumns.get(i).isAllowNull()) {
+ if (targetColumns.get(i).getDefaultValue() == null && !targetColumns.get(i).isAllowNull()
+ && !targetColumns.get(i).isAutoInc()) {
throw new AnalysisException("Column has no default value, column="
+ targetColumns.get(i).getName());
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
index f7ff692cdbe..c9e7f07f5d0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
@@ -337,7 +337,7 @@ public class BindSink implements AnalysisRuleFactory {
} else if (column.getDefaultValue() == null) {
// throw exception if explicitly use Default value but no default value present
// insert into table t values(DEFAULT)
- if (columnToChildOutput.get(column) instanceof DefaultValueSlot && !column.isAllowNull()) {
+ if (!column.isAllowNull() && !column.isAutoInc()) {
throw new AnalysisException("Column has no default value,"
+ " column=" + column.getName());
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java
index a14539d148d..c5c2197faf0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertUtils.java
@@ -427,7 +427,7 @@ public class InsertUtils {
return new Alias(new NullLiteral(DataType.fromCatalogType(column.getType())), column.getName());
}
if (column.getDefaultValue() == null) {
- if (!column.isAllowNull()) {
+ if (!column.isAllowNull() && !column.isAutoInc()) {
throw new AnalysisException("Column has no default value, column=" + column.getName());
}
}
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/ReadLockTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/ReadLockTest.java
index 9283b286f41..e31fa98af11 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/ReadLockTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/ReadLockTest.java
@@ -109,7 +109,8 @@ public class ReadLockTest extends SSBTestBase {
@Test
public void testInserInto() {
- String sql = "INSERT INTO supplier(s_suppkey) SELECT lo_orderkey FROM lineorder";
+ String sql = "INSERT INTO supplier(s_suppkey, s_name, s_address, s_city, s_nation, s_region, s_phone) "
+ + "SELECT lo_orderkey, '', '', '', '', '', '' FROM lineorder";
StatementContext statementContext = MemoTestUtils.createStatementContext(connectContext, sql);
InsertIntoTableCommand insertIntoTableCommand = (InsertIntoTableCommand) parser.parseSingle(sql);
NereidsPlanner planner = new NereidsPlanner(statementContext);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org