Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
924060929 committed Dec 10, 2024
1 parent 58ace8e commit bee14a8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -269,8 +270,8 @@ static Result<String, AnalysisException> normalize(String s) {
}

/** parseDateLiteral */
public static Result<DateLiteral, AnalysisException> parseDateLiteral(String s) {
Result<TemporalAccessor, AnalysisException> parseResult = parseDateTime(s);
public static Result<DateLiteral, DateTimeException> parseDateLiteral(String s) {
Result<TemporalAccessor, DateTimeException> parseResult = parseDateTime(s);
if (parseResult.isError()) {
return parseResult.cast();
}
Expand All @@ -280,13 +281,13 @@ public static Result<DateLiteral, AnalysisException> 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<TemporalAccessor, AnalysisException> parseDateTime(String s) {
public static Result<TemporalAccessor, DateTimeException> parseDateTime(String s) {
String originalString = s;
try {
// fast parse '2022-01-01'
Expand Down Expand Up @@ -344,13 +345,13 @@ public static Result<TemporalAccessor, AnalysisException> 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"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,8 +133,8 @@ public static int determineScale(String s) {
}

/** parseDateTimeLiteral */
public static Result<DateTimeLiteral, AnalysisException> parseDateTimeLiteral(String s, boolean isV2) {
Result<TemporalAccessor, AnalysisException> parseResult = parseDateTime(s);
public static Result<DateTimeLiteral, DateTimeException> parseDateTimeLiteral(String s, boolean isV2) {
Result<TemporalAccessor, DateTimeException> parseResult = parseDateTime(s);
if (parseResult.isError()) {
return parseResult.cast();
}
Expand Down Expand Up @@ -184,7 +185,7 @@ public static Result<DateTimeLiteral, AnalysisException> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NamedExpression> values : logicalInlineTable.getConstantExprsList()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -599,12 +600,12 @@ public static Optional<Expression> 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<DateLiteral, AnalysisException> parseResult
Result<DateLiteral, DateTimeException> parseResult
= DateV2Literal.parseDateLiteral(value);
if (parseResult.isOk()) {
ret = parseResult.get();
} else {
Result<DateTimeLiteral, AnalysisException> parseResult2
Result<DateTimeLiteral, DateTimeException> parseResult2
= DateTimeV2Literal.parseDateTimeLiteral(value, true);
if (parseResult2.isOk()) {
ret = parseResult2.get();
Expand Down

0 comments on commit bee14a8

Please sign in to comment.