pick https://github.com/apache/doris/pull/37746 before: ```sql mysql> select date_ceil("2020-12-12 12:12:12.123", interval 2 second); +-----------------------+ | '2020-12-12 12:12:12' | +-----------------------+ | 2020-12-12 12:12:12 | +-----------------------+ 1 row in set (0.10 sec) mysql> select CONVERT_TZ('9999-12-31 23:59:59.999999', 'Pacific/Galapagos', 'Pacific/Galapagos'); +------+ | NULL | +------+ | NULL | +------+ 1 row in set (0.09 sec) mysql [(none)]>select CONVERT_TZ('9999-12-31 23:59:59.999999', 'Pacific/Galapagos', 'Pacific/GalapaGoS'); +-----------------------------------------------------------------------------------------------------------+ | convert_tz(cast('9999-12-31 23:59:59.999999' as DATETIMEV2(6)), 'Pacific/Galapagos', 'Pacific/GalapaGoS') | +-----------------------------------------------------------------------------------------------------------+ | 9999-12-31 23:59:59.999999 | +-----------------------------------------------------------------------------------------------------------+ 1 row in set (0.08 sec) --- gone to BE ``` after: ```sql mysql> select date_ceil("2020-12-12 12:12:12.123", interval 2 second); +------------------------------+ | '2020-12-12 12:12:14.000000' | +------------------------------+ | 2020-12-12 12:12:14 | +------------------------------+ 1 row in set (0.11 sec) mysql> select CONVERT_TZ('9999-12-31 23:59:59.999999', 'Pacific/Galapagos', 'Pacific/Galapagos'); +-----------------------------------------------------------------------------------------------------------+ | convert_tz(cast('9999-12-31 23:59:59.999999' as DATETIMEV2(6)), 'Pacific/Galapagos', 'Pacific/Galapagos') | +-----------------------------------------------------------------------------------------------------------+ | 9999-12-31 23:59:59.999999 | +-----------------------------------------------------------------------------------------------------------+ 1 row in set (0.23 sec) mysql> select CONVERT_TZ('9999-12-31 23:59:59.999999', 'Pacific/Galapagos', 'Pacific/GalapaGoS'); +------------------------------+ | '9999-12-31 23:59:59.999999' | +------------------------------+ | 9999-12-31 23:59:59.999999 | +------------------------------+ 1 row in set (0.11 sec) --- finished in FE ```
This commit is contained in:
@ -51,7 +51,9 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.time.format.ResolverStyle;
|
||||
import java.time.format.TextStyle;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.WeekFields;
|
||||
@ -645,12 +647,22 @@ public class DateTimeExtractAndTransform {
|
||||
return datetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert_tz
|
||||
*/
|
||||
@ExecFunction(name = "convert_tz", argTypes = {"DATETIMEV2", "VARCHAR", "VARCHAR"}, returnType = "DATETIMEV2")
|
||||
public static Expression convertTz(DateTimeV2Literal datetime, StringLikeLiteral fromTz, StringLikeLiteral toTz) {
|
||||
DateTimeFormatter zoneFormatter = new DateTimeFormatterBuilder()
|
||||
.parseCaseInsensitive()
|
||||
.appendZoneOrOffsetId()
|
||||
.toFormatter()
|
||||
.withResolverStyle(ResolverStyle.STRICT);
|
||||
ZoneId fromZone = ZoneId.from(zoneFormatter.parse(fromTz.getStringValue()));
|
||||
ZoneId toZone = ZoneId.from(zoneFormatter.parse(toTz.getStringValue()));
|
||||
|
||||
LocalDateTime localDateTime = datetime.toJavaDateType();
|
||||
ZonedDateTime fromDateTime = localDateTime.atZone(ZoneId.of(fromTz.getStringValue()));
|
||||
ZonedDateTime toDateTime = fromDateTime.withZoneSameInstant(ZoneId.of(toTz.getStringValue()));
|
||||
return DateTimeV2Literal.fromJavaDateType(toDateTime.toLocalDateTime(), datetime.getDataType().getScale());
|
||||
ZonedDateTime resultDateTime = localDateTime.atZone(fromZone).withZoneSameInstant(toZone);
|
||||
return DateTimeV2Literal.fromJavaDateType(resultDateTime.toLocalDateTime(), datetime.getDataType().getScale());
|
||||
}
|
||||
|
||||
@ExecFunction(name = "weekday", argTypes = {"DATE"}, returnType = "TINYINT")
|
||||
|
||||
@ -87,7 +87,7 @@ public class TimeRoundSeries {
|
||||
+ (dt.getHour() - start.getHour()) * 60 * 60
|
||||
+ (dt.getMinute() - start.getMinute()) * 60
|
||||
+ (dt.getSecond() - start.getSecond());
|
||||
trivialPart = 0;
|
||||
trivialPart = dt.getMicroSecond() - start.getMicroSecond();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
||||
@ -46,7 +46,7 @@ public class DateLiteral extends Literal {
|
||||
|
||||
// for cast datetime type to date type.
|
||||
private static final LocalDateTime START_OF_A_DAY = LocalDateTime.of(0, 1, 1, 0, 0, 0);
|
||||
private static final LocalDateTime END_OF_A_DAY = LocalDateTime.of(9999, 12, 31, 23, 59, 59);
|
||||
private static final LocalDateTime END_OF_A_DAY = LocalDateTime.of(9999, 12, 31, 23, 59, 59, 999999000);
|
||||
private static final DateLiteral MIN_DATE = new DateLiteral(0, 1, 1);
|
||||
private static final DateLiteral MAX_DATE = new DateLiteral(9999, 12, 31);
|
||||
private static final int[] DAYS_IN_MONTH = new int[] {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
|
||||
@ -257,7 +257,7 @@ public class DateTimeV2Literal extends DateTimeLiteral {
|
||||
}
|
||||
|
||||
public static Expression fromJavaDateType(LocalDateTime dateTime) {
|
||||
return fromJavaDateType(dateTime, 0);
|
||||
return fromJavaDateType(dateTime, 6);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user