-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
98d6668
Compare
} | ||
|
||
@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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static DateTimeFormatterBuilder FormatBuilder(String pattern) throws AnalysisException{ | |
private static DateTimeFormatterBuilder formatBuilder(String pattern) throws AnalysisException{ |
return hour; | ||
} | ||
|
||
public void setHour(long hour) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need these set
or get
functions? If not, it is better to remove them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
date = new Date(in.readLong()); | ||
if (Catalog.getCurrentCatalogJournalVersion() >= FeMetaVersion.VERSION_59) { | ||
long packed_time = in.readLong(); | ||
microsecond = (packed_time % (1L << 24)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it a function
second = hms % (1 << 6); | ||
minute = (hms >> 6) % (1 << 6); | ||
hour = (hms >> 12); | ||
this.type = Type.DATETIME; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why DATETIME? I think it may be DATE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dates read from the meta are all datetime types, and Doris explicitly specifies type DATE/DATETIME by setType()
return dateLiteral; | ||
} | ||
|
||
public String dateFormat(String pattern) throws AnalysisException{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about "2010-01-31" + 10
…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
a4427f7
Compare
} | ||
|
||
@Override | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VERSION_59 is used by support strict mode
, change to VERSION_60
298dd35
to
58093b8
Compare
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
266e74b
Compare
…to fe-time-zone-function
9ac46ab
to
63071d4
Compare
@@ -56,8 +49,13 @@ | |||
*/ | |||
@FEFunction(name = "timediff", argTypes = { "DATETIME", "DATETIME" }, returnType = "TIME") | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.DataInput; | ||
import java.io.DataOutput; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I see you use SimpleDateFormat and DateTimeFormatter.
Can we unify them to DateTimeFormatter?
throw new AnalysisException("unixtime should larger than zero"); | ||
} | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can create a constructor of DateLiteral with unix timestamp and timezone.
Then this logic can be included in DateLiteral
63071d4
to
08bf2ec
Compare
08bf2ec
to
2412538
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
… missing out file (apache#1644)
1、Add fe time zone function support
2、Refactor DateLiteral class in FE
#1583