morrySnow commented on code in PR #23539: URL: https://github.com/apache/doris/pull/23539#discussion_r1309601745
########## fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4: ########## @@ -397,6 +397,18 @@ primaryExpression (INTERVAL unitsAmount=valueExpression unit=datetimeUnit | unitsAmount=valueExpression) RIGHT_PAREN #date_sub + | name=DATE_FLOOR + LEFT_PAREN + timestamp=valueExpression COMMA + (INTERVAL unitsAmount=valueExpression unit=datetimeUnit + | unitsAmount=valueExpression) + RIGHT_PAREN #date_floor + | name=DATE_CEIL + LEFT_PAREN + timestamp=valueExpression COMMA + (INTERVAL unitsAmount=valueExpression unit=datetimeUnit + | unitsAmount=valueExpression) + RIGHT_PAREN #date_ceil Review Comment: ```suggestion RIGHT_PAREN #dateCeil ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/TimeRoundSeries.java: ########## Review Comment: @sohardforaname plz review this file ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java: ########## @@ -206,22 +206,50 @@ public long getDay() { return day; } - public Expression plusDays(int days) { + public Expression plusDays(long days) { return fromJavaDateType(DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusDays(days)); } - public Expression plusMonths(int months) { + public Expression plusMonths(long months) { return fromJavaDateType(DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusMonths(months)); } - public Expression plusYears(int years) { + public Expression plusYears(long years) { return fromJavaDateType(DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusYears(years)); } public LocalDateTime toJavaDateType() { return LocalDateTime.of(((int) getYear()), ((int) getMonth()), ((int) getDay()), 0, 0, 0); } + public long daynr() { + return calcDaynr(this.year, this.month, this.day); + } + + // calculate the number of days from year 0000-00-00 to year-month-day + private long calcDaynr(long year, long month, long day) { Review Comment: do not use unreadable abbr as function name ########## fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java: ########## @@ -1094,6 +1110,64 @@ public Expression visitDate_sub(Date_subContext ctx) { + ", supported time unit: YEAR/MONTH/DAY/HOUR/MINUTE/SECOND", ctx); } + @Override + public Expression visitDate_floor(Date_floorContext ctx) { + Expression timeStamp = (Expression) visit(ctx.timestamp); + Expression amount = (Expression) visit(ctx.unitsAmount); + if (ctx.unit == null) { + // use "SECOND" as unit by default + return new SecondFloor(timeStamp, amount); + } + Expression e = new DateTimeV2Literal(0001L, 01L, 01L, 0L, 0L, 0L, 0L); + + if ("Year".equalsIgnoreCase(ctx.unit.getText())) { Review Comment: please help to refactor like this, thx ```java switch (ctx.unit) { case DorisParser.YEAR: ... break; } ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java: ########## @@ -206,22 +206,50 @@ public long getDay() { return day; } - public Expression plusDays(int days) { + public Expression plusDays(long days) { return fromJavaDateType(DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusDays(days)); } - public Expression plusMonths(int months) { + public Expression plusMonths(long months) { return fromJavaDateType(DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusMonths(months)); } - public Expression plusYears(int years) { + public Expression plusYears(long years) { return fromJavaDateType(DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusYears(years)); } public LocalDateTime toJavaDateType() { return LocalDateTime.of(((int) getYear()), ((int) getMonth()), ((int) getDay()), 0, 0, 0); } + public long daynr() { + return calcDaynr(this.year, this.month, this.day); + } + + // calculate the number of days from year 0000-00-00 to year-month-day + private long calcDaynr(long year, long month, long day) { + long delsum = 0; Review Comment: do not use unreadable abbr as var name ########## fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4: ########## @@ -397,6 +397,18 @@ primaryExpression (INTERVAL unitsAmount=valueExpression unit=datetimeUnit | unitsAmount=valueExpression) RIGHT_PAREN #date_sub + | name=DATE_FLOOR + LEFT_PAREN + timestamp=valueExpression COMMA + (INTERVAL unitsAmount=valueExpression unit=datetimeUnit + | unitsAmount=valueExpression) + RIGHT_PAREN #date_floor Review Comment: ```suggestion RIGHT_PAREN #dateFloor ``` -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org