WingsGo commented on a change in pull request #3679:
URL: https://github.com/apache/incubator-doris/pull/3679#discussion_r429878339



##########
File path: 
fe/src/main/java/org/apache/doris/common/util/DynamicPartitionUtil.java
##########
@@ -273,34 +321,110 @@ public static String getPartitionFormat(Column column) 
throws DdlException {
         }
     }
 
-    public static String getFormattedPartitionName(String name, String 
timeUnit) {
-        name = name.replace("-", "").replace(":", "").replace(" ", "");
+    public static String getFormattedPartitionName(TimeZone tz, String 
formattedDateStr, String timeUnit) {
+        formattedDateStr = formattedDateStr.replace("-", "").replace(":", 
"").replace(" ", "");
         if (timeUnit.equalsIgnoreCase(TimeUnit.DAY.toString())) {
-            return name.substring(0, 8);
+            return formattedDateStr.substring(0, 8);
         } else if (timeUnit.equalsIgnoreCase(TimeUnit.MONTH.toString())) {
-            return name.substring(0, 6);
+            return formattedDateStr.substring(0, 6);
         } else {
-            name = name.substring(0, 8);
-            Calendar calendar = Calendar.getInstance();
+            formattedDateStr = formattedDateStr.substring(0, 8);
+            Calendar calendar = Calendar.getInstance(tz);
             try {
-                calendar.setTime(new SimpleDateFormat("yyyyMMdd").parse(name));
+                calendar.setTime(new 
SimpleDateFormat("yyyyMMdd").parse(formattedDateStr));
             } catch (ParseException e) {
                 LOG.warn("Format dynamic partition name error. Error={}", 
e.getMessage());
-                return name;
+                return formattedDateStr;
+            }
+            int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);
+            if (weekOfYear <= 1 && calendar.get(Calendar.MONTH) >= 11) {
+                // eg: JDK think 2019-12-30 as the first week of year 2020, we 
need to handle this.
+                // to make it as the 53rd week of year 2019.
+                weekOfYear += 52;
             }
-            return String.format("%s_%02d", calendar.get(Calendar.YEAR), 
calendar.get(Calendar.WEEK_OF_YEAR));
+            return String.format("%s_%02d", calendar.get(Calendar.YEAR), 
weekOfYear);
         }
     }
 
-    public static String getPartitionRange(String timeUnit, int offset, 
Calendar calendar, String format) {
+    // return the partition range date string formatted as yyyy-MM-dd[ 
HH:mm::ss]
+    // TODO: support HOUR and YEAR
+    public static String getPartitionRangeString(DynamicPartitionProperty 
property, Calendar current,
+            int offset, String format) {
+        String timeUnit = property.getTimeUnit();
+        TimeZone tz = property.getTimeZone();
         if (timeUnit.equalsIgnoreCase(TimeUnit.DAY.toString())) {
-            calendar.add(Calendar.DAY_OF_MONTH, offset);
+            return getPartitionRangeOfDay(current, offset, tz, format);
         } else if (timeUnit.equalsIgnoreCase(TimeUnit.WEEK.toString())) {
-            calendar.add(Calendar.WEEK_OF_MONTH, offset);
-        } else {
-            calendar.add(Calendar.MONTH, offset);
+            return getPartitionRangeOfWeek(current, offset, 
property.getStartOfWeek(), tz, format);
+        } else { // MONTH
+            return getPartitionRangeOfMonth(current, offset, 
property.getStartOfMonth(), tz, format);
+        }
+    }
+    
+    /*

Review comment:
       It looks good.




----------------------------------------------------------------
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to