Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
seawinde committed Jun 2, 2024
1 parent 69d543a commit 08a7871
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ public static RelatedTableInfo getRelatedTableInfo(String column, String timeUni
if (columnExpr == null) {
return RelatedTableInfo.failWith("partition column can not find from sql select column");
}
Expression dateTrunc = null;
if (timeUnit != null) {
Expression dateTrunc = new DateTrunc(columnExpr, new VarcharLiteral(timeUnit));
dateTrunc = new DateTrunc(columnExpr, new VarcharLiteral(timeUnit));
dateTrunc = ExpressionUtils.shuttleExpressionWithLineage(dateTrunc, materializedViewPlan, new BitSet());
// merge date_trunc
dateTrunc = new ExpressionNormalization().rewrite(dateTrunc,
Expand Down Expand Up @@ -141,7 +142,7 @@ public static RelatedTableInfo getRelatedTableInfo(String column, String timeUni
// TODO support to return only one related table info, support multi later
for (Map.Entry<TableIf, Column> entry : partitionRelatedTableAndColumnMap.entries()) {
return RelatedTableInfo.successWith(new BaseTableInfo(entry.getKey()), true,
entry.getValue().getName());
entry.getValue().getName(), dateTrunc);
}
return RelatedTableInfo.failWith("can't not find valid partition track column finally");
}
Expand Down Expand Up @@ -520,20 +521,26 @@ public static final class RelatedTableInfo {
private final boolean pctPossible;
private final String column;
private final Set<String> failReasons = new HashSet<>();
// This records the partition expression
private Optional<Expression> partitionExpression;

public RelatedTableInfo(BaseTableInfo tableInfo, boolean pctPossible, String column, String failReason) {
public RelatedTableInfo(BaseTableInfo tableInfo, boolean pctPossible, String column, String failReason,
Expression partitionExpression) {
this.tableInfo = tableInfo;
this.pctPossible = pctPossible;
this.column = column;
this.failReasons.add(failReason);
this.partitionExpression = Optional.ofNullable(partitionExpression);
}

public static RelatedTableInfo failWith(String failReason) {
return new RelatedTableInfo(null, false, null, failReason);
return new RelatedTableInfo(null, false, null, failReason,
null);
}

public static RelatedTableInfo successWith(BaseTableInfo tableInfo, boolean pctPossible, String column) {
return new RelatedTableInfo(tableInfo, pctPossible, column, "");
public static RelatedTableInfo successWith(BaseTableInfo tableInfo, boolean pctPossible, String column,
Expression partitionExpression) {
return new RelatedTableInfo(tableInfo, pctPossible, column, "", partitionExpression);
}

public BaseTableInfo getTableInfo() {
Expand All @@ -555,5 +562,9 @@ public void addFailReason(String failReason) {
public String getFailReason() {
return String.join(",", failReasons);
}

public Optional<Expression> getPartitionExpression() {
return partitionExpression;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import org.apache.doris.nereids.rules.exploration.mv.MaterializedViewUtils;
import org.apache.doris.nereids.rules.exploration.mv.MaterializedViewUtils.RelatedTableInfo;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.functions.scalar.DateTrunc;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
Expand Down Expand Up @@ -87,9 +89,6 @@ public MTMVPartitionInfo analyzeAndTransferToMTMVPartitionInfo(NereidsPlanner pl
? ((UnboundSlot) functionCallExpression.getArgument(0)).getName() : null;
timeUnit = functionCallExpression.getArguments().get(1).isLiteral()
? ((Literal) functionCallExpression.getArgument(1)).getStringValue() : null;
// todo use new expression?
mtmvPartitionInfo.setExpr(new FunctionCallExpr(functionName,
new FunctionParams(convertToLegacyArguments(functionCallExpression.children()))));
} else {
throw new AnalysisException(
"unsupported auto partition expr " + functionCallExpression.toString());
Expand All @@ -102,6 +101,16 @@ public MTMVPartitionInfo analyzeAndTransferToMTMVPartitionInfo(NereidsPlanner pl
RelatedTableInfo relatedTableInfo = getRelatedTableInfo(planner, ctx, logicalQuery, partitionColName, timeUnit);
mtmvPartitionInfo.setRelatedCol(relatedTableInfo.getColumn());
mtmvPartitionInfo.setRelatedTable(relatedTableInfo.getTableInfo());
if (relatedTableInfo.getPartitionExpression().isPresent()) {
// Set mv partition expr by relatedTableInfo, this is used for partition rollup and so on
if (relatedTableInfo.getPartitionExpression().get().getExpressionName()
.equalsIgnoreCase(PARTITION_BY_FUNCTION_NAME)) {
DateTrunc dateTrunc = (DateTrunc) relatedTableInfo.getPartitionExpression().get();
// todo use new expression?
mtmvPartitionInfo.setExpr(new FunctionCallExpr(dateTrunc.getName(),
new FunctionParams(convertToLegacyArguments(dateTrunc.children()))));
}
}
if (this.partitionType == MTMVPartitionType.EXPR) {
try {
MTMVPartitionExprFactory.getExprService(mtmvPartitionInfo.getExpr()).analyze(mtmvPartitionInfo);
Expand Down Expand Up @@ -157,8 +166,8 @@ private RelatedTableInfo getRelatedTableInfo(NereidsPlanner planner, ConnectCont

private static List<Expr> convertToLegacyArguments(List<Expression> children) {
return children.stream().map(child -> {
if (child instanceof UnboundSlot) {
return new SlotRef(null, ((UnboundSlot) child).getName());
if (child instanceof Slot) {
return new SlotRef(null, ((Slot) child).getName());
} else if (child instanceof Literal) {
return new StringLiteral(((Literal) child).getStringValue());
} else {
Expand Down

0 comments on commit 08a7871

Please sign in to comment.