kezhenxu94 commented on a change in pull request #4353: Optimizing performance reduces es index queries scope by timebucket URL: https://github.com/apache/skywalking/pull/4353#discussion_r379287530
########## File path: oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/DurationUtils.java ########## @@ -213,4 +213,36 @@ private DateTime parseToDateTime(Downsampling downsampling, long time) { } throw new UnexpectedException("Unexpected downsampling: " + downsampling.name()); } + + public DateTime startTimeBucket2DateTime(Downsampling downsampling, long startTB) { + switch (downsampling) { + case Month: + return YYYYMM.parseDateTime(String.valueOf(startTB)); + case Day: + return YYYYMMDD.parseDateTime(String.valueOf(startTB)); + case Hour: + return YYYYMMDDHH.parseDateTime(String.valueOf(startTB)); + case Minute: + return YYYYMMDDHHMM.parseDateTime(String.valueOf(startTB)); + case Second: + return YYYYMMDDHHMMSS.parseDateTime(String.valueOf(startTB)); + } + throw new UnexpectedException("Unexpected downsampling: " + downsampling.name()); + } + + public DateTime endTimeBucket2DateTime(Downsampling downsampling, long endTB) { + switch (downsampling) { + case Month: + return YYYYMM.parseDateTime(String.valueOf(endTB)); + case Day: + return YYYYMMDD.parseDateTime(String.valueOf(endTB)); + case Hour: + return YYYYMMDDHH.parseDateTime(String.valueOf(endTB)); + case Minute: + return YYYYMMDDHHMM.parseDateTime(String.valueOf(endTB)); + case Second: + return YYYYMMDDHHMMSS.parseDateTime(String.valueOf(endTB)); + } + throw new UnexpectedException("Unexpected downsampling: " + downsampling.name()); Review comment: The logic seems not to be related to `startTime` or `endTime`, so I don't think it's a good method name `endTimeBucket2DateTime ` or `startTimeBucket2DateTime `, and the method body are exactly the same in `parseToDateTime`, if you meant it, simply use `parseToDateTime` is enough? Otherwise, you may forget to `.plusMonths(1)`, `plusDays(1)`, etc. like `org.apache.skywalking.oap.server.core.query.DurationUtils#endTimeToTimestamp` ```java public long endTimeToTimestamp(Step step, String dateStr) { switch (step) { case MONTH: return YYYY_MM.parseDateTime(dateStr).plusMonths(1).getMillis(); case DAY: return YYYY_MM_DD.parseDateTime(dateStr).plusDays(1).getMillis(); case HOUR: return YYYY_MM_DD_HH.parseDateTime(dateStr).plusHours(1).getMillis(); case MINUTE: return YYYY_MM_DD_HHMM.parseDateTime(dateStr).plusMinutes(1).getMillis(); case SECOND: return YYYY_MM_DD_HHMMSS.parseDateTime(dateStr).plusSeconds(1).getMillis(); } throw new UnexpectedException("Unsupported step " + step.name()); } ``` ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services