Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -853,11 +853,15 @@ private void analyzeRow(Analyzer analyzer, List<Column> targetColumns, List<Arra
Column col = targetColumns.get(i);

if (expr instanceof DefaultValueExpr) {
if (targetColumns.get(i).getDefaultValue() == null) {
if (targetColumns.get(i).getDefaultValue() == null && !targetColumns.get(i).isAllowNull()) {
throw new AnalysisException("Column has no default value, column="
+ targetColumns.get(i).getName());
}
expr = new StringLiteral(targetColumns.get(i).getDefaultValue());
if (targetColumns.get(i).getDefaultValue() == null) {
expr = new NullLiteral();
} else {
expr = new StringLiteral(targetColumns.get(i).getDefaultValue());
}
}
if (expr instanceof Subquery) {
throw new AnalysisException("Insert values can not be query");
Expand Down
3 changes: 3 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ public String getDefaultValue() {
}

public Expr getDefaultValueExpr() throws AnalysisException {
if (defaultValue == null) {
return null;
}
StringLiteral defaultValueLiteral = new StringLiteral(defaultValue);
if (getDataType() == PrimitiveType.VARCHAR) {
return defaultValueLiteral;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ public List<Rule> buildRules() {
// should not contain these unmentioned columns, so we just skip them.
continue;
} else if (column.getDefaultValue() == null) {
// throw exception if explicitly use Default value null when not nullable
// insert into table t values(DEFAULT)
if (!column.isAllowNull()) {
throw new AnalysisException("Column has no default value,"
+ " column=" + column.getName());
}
// Otherwise, the unmentioned columns should be filled with default values
// or null values
columnToOutput.put(column.getName(), new Alias(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public void testScalarSubQuery() {

@Test
public void testInsertInto() {
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);
boolean originalDML = connectContext.getSessionVariable().enableNereidsDML;
connectContext.getSessionVariable().enableNereidsDML = true;
Expand Down