This is an automated email from the ASF dual-hosted git repository.
starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new c965db6e969 [Fix](Nerieds) insert into table with default not null but
not included in insert schema (#39825)
c965db6e969 is described below
commit c965db6e969234ed9847d29c2f6fd195a7b1db72
Author: LiBinfeng <[email protected]>
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 64ab872ea8b..b950df695ac 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 6c4763afcfb..3d9ec401a37 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: [email protected]
For additional commands, e-mail: [email protected]