Skip to content

Commit

Permalink
[Bug](datev2) Fix compatible problems caused by datev2 (#15131)
Browse files Browse the repository at this point in the history
This bug is introduced by #15094
  • Loading branch information
Gabriel39 committed Dec 16, 2022
1 parent be2f1df commit 67b9d46
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Expand Up @@ -769,6 +769,33 @@ public void readFields(DataInput in) throws IOException {
}
}

@Override
public void checkValueValid() throws AnalysisException {
if (year < 0 || year > 9999) {
throw new AnalysisException("DateLiteral has invalid year value: " + year);
}
if (month < 1 || month > 12) {
throw new AnalysisException("DateLiteral has invalid month value: " + month);
}
if (day < 1 || day > 31) {
throw new AnalysisException("DateLiteral has invalid day value: " + day);
}
if (type.isDatetimeV2() || type.isDatetime()) {
if (hour < 0 || hour > 24) {
throw new AnalysisException("DateLiteral has invalid hour value: " + hour);
}
if (minute < 0 || minute > 60) {
throw new AnalysisException("DateLiteral has invalid minute value: " + minute);
}
if (second < 0 || second > 60) {
throw new AnalysisException("DateLiteral has invalid second value: " + second);
}
if (type.isDatetimeV2() && (microsecond < 0 || microsecond > 999999)) {
throw new AnalysisException("DateLiteral has invalid microsecond value: " + microsecond);
}
}
}

public static DateLiteral read(DataInput in) throws IOException {
DateLiteral literal = new DateLiteral();
literal.readFields(in);
Expand Down Expand Up @@ -1621,4 +1648,14 @@ public void fromDateStr(String dateStr) throws AnalysisException {
throw new AnalysisException("Datetime value is out of range: " + dateStr);
}
}

public void setMinValue() {
year = 0;
month = 1;
day = 1;
hour = 0;
minute = 0;
second = 0;
microsecond = 0;
}
}
Expand Up @@ -338,6 +338,16 @@ public void readFields(DataInput in) throws IOException {
if (type != PrimitiveType.DATETIMEV2) {
literal.setType(Type.fromPrimitiveType(type));
}
if (type.isDateV2Type()) {
try {
literal.checkValueValid();
} catch (AnalysisException e) {
LOG.warn("Value {} for partition key [type = {}] is invalid! This is a bug exists in Doris "
+ "1.2.0 and fixed since Doris 1.2.1. You should create this table again using Doris "
+ "1.2.1+ .", literal.getStringValue(), type);
((DateLiteral) literal).setMinValue();
}
}
keys.add(literal);
}
}
Expand Down

0 comments on commit 67b9d46

Please sign in to comment.