This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit d6f4f08dcc14c435cb721e5009c162478a1ab25e Author: Gabriel <gabrielleeb...@gmail.com> AuthorDate: Fri Dec 16 21:52:39 2022 +0800 [Bug](datev2) Fix compatible problems caused by datev2 (#15131) This bug is introduced by #15094 --- .../org/apache/doris/analysis/DateLiteral.java | 37 ++++++++++++++++++++++ .../org/apache/doris/catalog/PartitionKey.java | 10 ++++++ 2 files changed, 47 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java index 2a6efebd40..2377351822 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java @@ -769,6 +769,33 @@ public class DateLiteral extends LiteralExpr { } } + @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); @@ -1621,4 +1648,14 @@ public class DateLiteral extends LiteralExpr { 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; + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionKey.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionKey.java index 68b49c2974..6f26d4ff3a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionKey.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/PartitionKey.java @@ -338,6 +338,16 @@ public class PartitionKey implements Comparable<PartitionKey>, Writable { 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); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org