Skip to content

Commit

Permalink
Allow the null default in insert into stmt (apache#1556)
Browse files Browse the repository at this point in the history
The default value of null is forbidden in insert into stmt while null column has not been mentioned in stmt.
This is a bug because the unmentioned column has default value. The values should be inserted successfully although the default value is null.

So the column may simply be not assigned default value when the column is not allowed null and the default value of column is null.
  • Loading branch information
EmmyMiao87 authored and morningman committed Jul 28, 2019
1 parent b64ad22 commit fefd996
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions fe/src/main/java/org/apache/doris/analysis/InsertStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private void checkColumnCoverage(Set<String> mentionedCols, List<Column> baseCol
if (mentionedCols.contains(col.getName())) {
continue;
}
if (col.getDefaultValue() == null) {
if (col.getDefaultValue() == null && !col.isAllowNull()) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_COL_NOT_MENTIONED, col.getName());
}
}
Expand Down Expand Up @@ -500,7 +500,18 @@ public void prepareExpressions() throws UserException {
if (exprByName.containsKey(col.getName())) {
resultExprs.add(exprByName.get(col.getName()));
} else {
resultExprs.add(checkTypeCompatibility(col, new StringLiteral(col.getDefaultValue())));
if (col.getDefaultValue() == null) {
/*
The import stmt has been filtered in function checkColumnCoverage when
the default value of column is null and column is not nullable.
So the default value of column may simply be null when column is nullable
*/
Preconditions.checkState(col.isAllowNull());
resultExprs.add(NullLiteral.create(col.getType()));
}
else {
resultExprs.add(checkTypeCompatibility(col, new StringLiteral(col.getDefaultValue())));
}
}
}
}
Expand Down

0 comments on commit fefd996

Please sign in to comment.