morrySnow commented on code in PR #35562: URL: https://github.com/apache/doris/pull/35562#discussion_r1620237363
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/ExpressionNormalization.java: ########## @@ -53,7 +54,8 @@ public class ExpressionNormalization extends ExpressionRewrite { DigitalMaskingConvert.INSTANCE, SimplifyArithmeticComparisonRule.INSTANCE, ConvertAggStateCast.INSTANCE, - CheckCast.INSTANCE + CheckCast.INSTANCE, Review Comment: check cast should the last rule ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/MTMVPartitionDefinition.java: ########## @@ -78,23 +78,28 @@ public MTMVPartitionInfo analyzeAndTransferToMTMVPartitionInfo(NereidsPlanner pl return mtmvPartitionInfo; } String partitionColName; + String timeUnit; if (this.partitionType == MTMVPartitionType.EXPR) { - Expr expr; - if (functionCallExpression instanceof UnboundFunction) { - UnboundFunction function = (UnboundFunction) functionCallExpression; - expr = new FunctionCallExpr(function.getName(), - new FunctionParams(convertToLegacyArguments(function.children()))); + String functionName = ((UnboundFunction) functionCallExpression).getName(); + if (functionCallExpression instanceof UnboundFunction + && functionName.equals(PARTITION_BY_FUNCTION_NAME)) { Review Comment: ```suggestion && functionName.equalsIgnoreCase(PARTITION_BY_FUNCTION_NAME)) { ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Interval.java: ########## @@ -61,30 +63,51 @@ public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { * Supported time unit. */ public enum TimeUnit { - YEAR("YEAR", false), - MONTH("MONTH", false), - WEEK("WEEK", false), - DAY("DAY", false), - HOUR("HOUR", true), - MINUTE("MINUTE", true), - SECOND("SECOND", true); + YEAR("YEAR", false, 800), Review Comment: why 800 not 8? ########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/MergeDateTrunc.java: ########## @@ -0,0 +1,84 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.rules.expression.rules; + +import org.apache.doris.nereids.rules.expression.ExpressionPatternMatcher; +import org.apache.doris.nereids.rules.expression.ExpressionPatternRuleFactory; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.scalar.DateTrunc; +import org.apache.doris.nereids.trees.expressions.literal.Interval.TimeUnit; +import org.apache.doris.nereids.trees.expressions.literal.Literal; +import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral; + +import com.google.common.collect.ImmutableList; + +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +/** + * Rewrite rule to convert + * For example: + * date_trunc(date_trunc(data_slot, 'hour'), 'day') -> date_trunc(data_slot, 'day') + */ +public class MergeDateTrunc implements ExpressionPatternRuleFactory { + + public static MergeDateTrunc INSTANCE = new MergeDateTrunc(); + public static Set<TimeUnit> UN_SUPPORT_TIME_UNIT = new HashSet<>(); Review Comment: ImmutableSet.of(TimeUnit.WEEK, TimeUnit.QUARTER); ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Interval.java: ########## @@ -61,30 +63,51 @@ public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { * Supported time unit. */ public enum TimeUnit { - YEAR("YEAR", false), - MONTH("MONTH", false), - WEEK("WEEK", false), - DAY("DAY", false), - HOUR("HOUR", true), - MINUTE("MINUTE", true), - SECOND("SECOND", true); + YEAR("YEAR", false, 800), + MONTH("MONTH", false, 700), + QUARTER("QUARTER", false, 600), + WEEK("WEEK", false, 500), + DAY("DAY", false, 400), + HOUR("HOUR", true, 300), + MINUTE("MINUTE", true, 200), + SECOND("SECOND", true, 100); private final String description; - private final boolean isDateTimeUnit; + /** + * Time unit level, second level is low, year level is high + */ + private final int level; - TimeUnit(String description, boolean isDateTimeUnit) { + TimeUnit(String description, boolean isDateTimeUnit, int level) { this.description = description; this.isDateTimeUnit = isDateTimeUnit; + this.level = level; } public boolean isDateTimeUnit() { return isDateTimeUnit; } + public int getLevel() { + return level; + } + @Override public String toString() { return description; } + + /** + * Construct time unit by name + */ + public static Optional<TimeUnit> of(String name) { + for (TimeUnit unit : TimeUnit.values()) { + if (unit.toString().equalsIgnoreCase(name)) { + return Optional.of(unit); + } + } Review Comment: ```suggestion try { return Optional.of(TimeUnit.valueOf(name.toUpperCase())) } catch (IllegalArgumentException e) { return Optional.empty(); } ``` or u could use `org.apache.commons.lang3.EnumUtils#getEnumIgnoreCase` ```java return Optional.ofNullable(EnumUtils.getEnumIgnoreCase(TimeUnit.class, name, null)); ``` -- 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