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 @@ -920,11 +920,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
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,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 @@ -344,7 +344,7 @@ private static Map<String, NamedExpression> getColumnToOutput(
} 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) {
if (columnToChildOutput.get(column) instanceof DefaultValueSlot && !column.isAllowNull()) {
throw new AnalysisException("Column has no default value,"
+ " column=" + column.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ public static TableIf getTargetTable(Plan plan, ConnectContext ctx) {
private static NamedExpression generateDefaultExpression(Column column) {
try {
if (column.getDefaultValue() == null) {
throw new AnalysisException("Column has no default value, column=" + column.getName());
if (!column.isAllowNull()) {
throw new AnalysisException("Column has no default value, column=" + column.getName());
}
}
if (column.getDefaultValueExpr() != null) {
Expression defualtValueExpression = new NereidsParser().parseExpression(
Expand Down