morningman commented on a change in pull request #1644: Refactor DateLiteral
class in FE
URL: https://github.com/apache/incubator-doris/pull/1644#discussion_r315653644
##########
File path: fe/src/main/java/org/apache/doris/analysis/DateLiteral.java
##########
@@ -61,66 +78,77 @@ public DateLiteral(String s, Type type) throws
AnalysisException {
analysisDone();
}
- protected DateLiteral(DateLiteral other) {
+ public DateLiteral(DateLiteral other) {
super(other);
- date = other.date;
+ hour = other.hour;
+ minute = other.minute;
+ second = other.second;
+ year = other.year;
+ month = other.month;
+ day = other.day;
+ microsecond = other.microsecond;
+
+ type = other.type;
}
@Override
public Expr clone() {
return new DateLiteral(this);
}
- public static DateLiteral createMinValue(Type type) {
- DateLiteral dateLiteral = new DateLiteral();
- dateLiteral.type = type;
- if (type == Type.DATE) {
- dateLiteral.date = TimeUtils.MIN_DATE;
- } else {
- dateLiteral.date = TimeUtils.MIN_DATETIME;
- }
-
- return dateLiteral;
+ public static DateLiteral createMinValue(Type type) throws
AnalysisException {
+ return new DateLiteral(type, false);
}
private void init(String s, Type type) throws AnalysisException {
- Preconditions.checkArgument(type.isDateType());
- date = TimeUtils.parseDate(s, type);
- if (type.isScalarType(PrimitiveType.DATE)) {
- if (date.compareTo(TimeUtils.MAX_DATE) > 0 ||
date.compareTo(TimeUtils.MIN_DATE) < 0) {
- throw new AnalysisException("Date type column should range
from [" + TimeUtils.MIN_DATE + "] to ["
- + TimeUtils.MAX_DATE + "]");
- }
- } else {
- if (date.compareTo(TimeUtils.MAX_DATETIME) > 0 ||
date.compareTo(TimeUtils.MIN_DATETIME) < 0) {
- throw new AnalysisException("Datetime type column should range
from [" + TimeUtils.MIN_DATETIME
- + "] to [" + TimeUtils.MAX_DATETIME + "]");
+ try {
+ Preconditions.checkArgument(type.isDateType());
+ LocalDateTime dateTime;
+ if (type == Type.DATE) {
+ dateTime =
FormatBuilder("%Y-%m-%d").toFormatter().parseLocalDateTime(s);
+ } else {
+ dateTime = FormatBuilder("%Y-%m-%d
%H:%i:%s").toFormatter().parseLocalDateTime(s);
}
+ year = dateTime.getYear();
+ month = dateTime.getMonthOfYear();
+ day = dateTime.getDayOfMonth();
+ hour = dateTime.getHourOfDay();
+ minute = dateTime.getMinuteOfHour();
+ second = dateTime.getSecondOfMinute();
+ this.type = type;
+ } catch (Exception ex) {
+ throw new AnalysisException("date literal [" + s + "] is valid");
}
- this.type = type;
}
@Override
public boolean isMinValue() {
switch (type.getPrimitiveType()) {
case DATE:
- return this.date.compareTo(TimeUtils.MIN_DATE) == 0;
+ return this.getStringValue().compareTo("1900-01-01") == 0;
Review comment:
ok
> We can create a static for min/max value. But we can't not use == to check
if it is a minimal value. Because user can construct another object with
minimal value string
ok
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]