jackwener commented on code in PR #27618:
URL: https://github.com/apache/doris/pull/27618#discussion_r1405830706
##########
fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java:
##########
@@ -485,10 +492,30 @@ private void init(String s, Type type) throws
AnalysisException {
minute = getOrDefault(dateTime, ChronoField.MINUTE_OF_HOUR, 0);
second = getOrDefault(dateTime, ChronoField.SECOND_OF_MINUTE, 0);
microsecond = getOrDefault(dateTime, ChronoField.MICRO_OF_SECOND,
0);
- if (microsecond != 0 && type.isDatetime()) {
- int dotIndex = s.lastIndexOf(".");
- int scale = s.length() - dotIndex - 1;
- type = ScalarType.createDatetimeV2Type(scale);
+
+ if (type != null) {
+ if (microsecond != 0 && type.isDatetime()) {
+ int dotIndex = s.lastIndexOf(".");
+ int scale = s.length() - dotIndex - 1;
+ type = ScalarType.createDatetimeV2Type(scale);
+ }
+ } else {
+ if (hour == 0 && minute == 0 && second == 0 && microsecond ==
0) {
+ type = ScalarType.getDefaultDateType(Type.DATE);
+ } else {
+ type = ScalarType.getDefaultDateType(Type.DATETIME);
+ if (type.isDatetimeV2() && microsecond != 0) {
+ int scale = 6;
+ for (int i = 0; i < 6; i++) {
+ if (microsecond % Math.pow(10.0, i + 1) > 0) {
+ break;
+ } else {
+ scale -= 1;
+ }
+ }
+ type = ScalarType.createDatetimeV2Type(scale);
+ }
+ }
Review Comment:
move it from `fromDateStr(String dateStr)`
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]