Uh oh!
There was an error while loading. Please reload this page.
Refactor DateLiteral class in FE - #1644
Conversation
…u/incubator-doris into fe-time-zone-function
…u/incubator-doris into fe-time-zone-function # Conflicts: # fe/src/main/java/org/apache/doris/rewrite/FEFunctions.java
…u/incubator-doris into fe-time-zone-function # Conflicts: # fe/src/main/java/org/apache/doris/rewrite/FEFunctions.java
…u/incubator-doris into fe-time-zone-function
…to fe-time-zone-function Conflicts: fe/src/main/java/org/apache/doris/rewrite/FEFunctions.java
3438f2f to
98d6668Compare| switch (type.getPrimitiveType()) { | ||
| case DATE: | ||
| return this.date.compareTo(TimeUtils.MIN_DATE) == 0; | ||
| return this.getStringValue().compareTo("1900-01-01") == 0; |
There was a problem hiding this comment.
I think min value and max value can be a static final member of DateLiteral?So that you can just use "=" to check this
There was a problem hiding this comment.
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
There was a problem hiding this 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
| .toString(FormatBuilder(pattern).toFormatter()); | ||
| } | ||
| private static DateTimeFormatterBuilder FormatBuilder(String pattern) throws AnalysisException{ |
There was a problem hiding this comment.
| privatestaticDateTimeFormatterBuilderFormatBuilder(Stringpattern) throwsAnalysisException{ | |
| privatestaticDateTimeFormatterBuilderformatBuilder(Stringpattern) throwsAnalysisException{ |
| return hour; | ||
| } | ||
| public void setHour(long hour) { |
There was a problem hiding this comment.
Do we really need these set or get functions? If not, it is better to remove them.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| date = new Date(in.readLong()); | ||
| if (Catalog.getCurrentCatalogJournalVersion() >= FeMetaVersion.VERSION_59) { | ||
| long packed_time = in.readLong(); | ||
| microsecond = (packed_time % (1L << 24)); |
| second = hms % (1 << 6); | ||
| minute = (hms >> 6) % (1 << 6); | ||
| hour = (hms >> 12); | ||
| this.type = Type.DATETIME; |
There was a problem hiding this comment.
why DATETIME? I think it may be DATE
There was a problem hiding this comment.
The dates read from the meta are all datetime types, and Doris explicitly specifies type DATE/DATETIME by setType()
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| return dateLiteral; | ||
| } | ||
| public String dateFormat(String pattern) throws AnalysisException{ |
There was a problem hiding this comment.
You should add comments for this function. It's better to give some example that what function do
| DateLiteral dateLiteral = (DateLiteral) date; | ||
| DateLiteral result = new DateLiteral(dateLiteral); | ||
| result.setDay(dateLiteral.getDay() + day.getLongValue()); |
…tion # Conflicts: # fe/src/main/java/org/apache/doris/common/FeMetaVersion.java # fe/src/main/java/org/apache/doris/rewrite/FEFunctions.java
…u/incubator-doris into fe-time-zone-function
12e3678 to
a4427f7CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| public void readFields(DataInput in) throws IOException { | ||
| super.readFields(in); | ||
| date = new Date(in.readLong()); | ||
| if (Catalog.getCurrentCatalogJournalVersion() >= FeMetaVersion.VERSION_59) { |
There was a problem hiding this comment.
VERSION_59 is used by support strict mode, change to VERSION_60
298dd35 to
58093b8Compare| return new DateLiteral(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth()); | ||
| } else { | ||
| return new DateLiteral(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), | ||
| dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute()); |
There was a problem hiding this comment.
Why not move this logic to DateLiteral. And I think we can make formatter static which is thread-safe.
| date = new Date(in.readLong()); | ||
| if (Catalog.getCurrentCatalogJournalVersion() >= FeMetaVersion.VERSION_60) { | ||
| fromPackedDatetime(in.readLong()); | ||
| } else { |
There was a problem hiding this comment.
I think we should persist type for later use. Or if we want to persist Date, we will have to change the format we use.
58093b8 to
266e74bCompare…to fe-time-zone-function
9ac46ab to
63071d4Compare| public static FloatLiteral timeDiff(LiteralExpr first, LiteralExpr second) throws AnalysisException { | ||
| long timediff = (getTime(first) - getTime(second)) / 1000; | ||
| return new FloatLiteral((double)timediff, Type.TIME); | ||
| SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
There was a problem hiding this comment.
why "yyyy-MM-dd" other than "yyyy-MM-dd hh:mm:ss"
I think we can write a function getTime() for DateLiteral.
| import java.io.IOException; | ||
| import java.nio.ByteBuffer; | ||
| import java.text.ParseException; | ||
| import java.text.SimpleDateFormat; |
There was a problem hiding this comment.
And I see you use SimpleDateFormat and DateTimeFormatter.
Can we unify them to DateTimeFormatter?
| } | ||
| Date date = new Date(unixTime.getLongValue() * 1000); | ||
| return new StringLiteral(dateFormat(date, "%Y-%m-%d %H:%i:%S")); | ||
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
There was a problem hiding this comment.
I think we can create a constructor of DateLiteral with unix timestamp and timezone.
Then this logic can be included in DateLiteral
63071d4 to
08bf2ecCompare08bf2ec to
2412538Compare
1、Add fe time zone function support
2、Refactor DateLiteral class in FE
#1583