diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java index 87ebfceb8c2d9e6..9a25f3dff3c36f2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java @@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableSet; +import java.time.DateTimeException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.Year; @@ -269,8 +270,8 @@ static Result normalize(String s) { } /** parseDateLiteral */ - public static Result parseDateLiteral(String s) { - Result parseResult = parseDateTime(s); + public static Result parseDateLiteral(String s) { + Result parseResult = parseDateTime(s); if (parseResult.isError()) { return parseResult.cast(); } @@ -280,13 +281,13 @@ public static Result parseDateLiteral(String s) int day = DateUtils.getOrDefault(dateTime, ChronoField.DAY_OF_MONTH); if (checkDatetime(dateTime) || checkRange(year, month, day) || checkDate(year, month, day)) { - return Result.err(() -> new AnalysisException("date/datetime literal [" + s + "] is out of range")); + return Result.err(() -> new DateTimeException("date/datetime literal [" + s + "] is out of range")); } return Result.ok(new DateLiteral(year, month, day)); } /** parseDateTime */ - public static Result parseDateTime(String s) { + public static Result parseDateTime(String s) { String originalString = s; try { // fast parse '2022-01-01' @@ -344,13 +345,13 @@ public static Result parseDateTime(String s // if Year is not present, throw exception if (!dateTime.isSupported(ChronoField.YEAR)) { return Result.err( - () -> new AnalysisException("date/datetime literal [" + originalString + "] is invalid") + () -> new DateTimeException("date/datetime literal [" + originalString + "] is invalid") ); } return Result.ok(dateTime); } catch (Exception ex) { - return Result.err(() -> new AnalysisException("date/datetime literal [" + originalString + "] is invalid")); + return Result.err(() -> new DateTimeException("date/datetime literal [" + originalString + "] is invalid")); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteral.java index 27470187eae0d22..40248e9768674ef 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteral.java @@ -30,6 +30,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.time.DateTimeException; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; @@ -132,8 +133,8 @@ public static int determineScale(String s) { } /** parseDateTimeLiteral */ - public static Result parseDateTimeLiteral(String s, boolean isV2) { - Result parseResult = parseDateTime(s); + public static Result parseDateTimeLiteral(String s, boolean isV2) { + Result parseResult = parseDateTime(s); if (parseResult.isError()) { return parseResult.cast(); } @@ -184,7 +185,7 @@ public static Result parseDateTimeLiteral(St } if (checkRange(year, month, day) || checkDate(year, month, day)) { - return Result.err(() -> new AnalysisException("datetime literal [" + s + "] is out of range")); + return Result.err(() -> new DateTimeException("datetime literal [" + s + "] is out of range")); } if (isV2) { 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 90fbcd40422d99f..d309ab05f61800c 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 @@ -371,7 +371,10 @@ public static Plan normalizePlan(LogicalPlan plan, TableIf table, cascadesContext -> buildAnalyzer(plan, cascadesContext) ); - Boolean[] outputSlotNullables = new Boolean[logicalInlineTable.getConstantExprsList().get(0).size()]; + int insertColumnNum = CollectionUtils.isEmpty(unboundLogicalSink.getColNames()) + ? columns.size() + : logicalInlineTable.getConstantExprsList().get(0).size(); + Boolean[] outputSlotNullables = new Boolean[insertColumnNum]; Arrays.fill(outputSlotNullables, false); for (List values : logicalInlineTable.getConstantExprsList()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java index 603a891d2d2a490..a098e9a87bc32e5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java @@ -121,6 +121,7 @@ import java.math.BigDecimal; import java.math.BigInteger; +import java.time.DateTimeException; import java.util.ArrayList; import java.util.List; import java.util.ListIterator; @@ -599,12 +600,12 @@ public static Optional characterLiteralTypeCoercion(String value, Da } else if (dataType.isDateTimeType() && DateTimeChecker.isValidDateTime(value)) { ret = DateTimeLiteral.parseDateTimeLiteral(value, false).orElse(null); } else if (dataType.isDateV2Type() && DateTimeChecker.isValidDateTime(value)) { - Result parseResult + Result parseResult = DateV2Literal.parseDateLiteral(value); if (parseResult.isOk()) { ret = parseResult.get(); } else { - Result parseResult2 + Result parseResult2 = DateTimeV2Literal.parseDateTimeLiteral(value, true); if (parseResult2.isOk()) { ret = parseResult2.get();