From d6f4f08dcc14c435cb721e5009c162478a1ab25e Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 16 Dec 2022 21:52:39 +0800 Subject: [PATCH] [Bug](datev2) Fix compatible problems caused by datev2 (#15131) This bug is introduced by #15094 --- .../apache/doris/analysis/DateLiteral.java | 37 +++++++++++++++++++ .../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 2a6efebd4072bb..2377351822f662 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 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); @@ -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; + } } 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 68b49c29740ae3..6f26d4ff3a0214 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 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); } }