Skip to content

Commit

Permalink
add more log
Browse files Browse the repository at this point in the history
  • Loading branch information
seawinde committed Dec 27, 2023
1 parent 19e6e0a commit c0a62f5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ protected Plan rewriteQueryByView(MatchMode matchMode,
Pair<Plan, LogicalAggregate<Plan>> viewTopPlanAndAggPair = splitToTopPlanAndAggregate(viewStructInfo);
if (viewTopPlanAndAggPair == null) {
materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(),
String.format("split to view to top plan and agg fail, view plan is %s",
String.format("view split to top plan and agg fail, view plan = %s\n",
viewStructInfo.getOriginalPlan().treeString()));
return null;
}
Pair<Plan, LogicalAggregate<Plan>> queryTopPlanAndAggPair = splitToTopPlanAndAggregate(queryStructInfo);
if (queryTopPlanAndAggPair == null) {
materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(),
String.format("split to query to top plan and agg fail, query plan is %s",
String.format("query split to top plan and agg fail, query plan = %s\n",
queryStructInfo.getOriginalPlan().treeString()));
return null;
}
Expand Down Expand Up @@ -120,9 +120,11 @@ protected Plan rewriteQueryByView(MatchMode matchMode,
if (rewrittenQueryGroupExpr.isEmpty()) {
// can not rewrite, bail out.
materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(),
String.format("can not rewrite expression when not need roll up, expressionToWrite is %s,"
+ "mvExprToMvScanExprMapping is %s", queryTopPlan.getExpressions(),
materializationContext.getMvExprToMvScanExprMapping()));
String.format("can not rewrite expression when need no roll up, expressionToWrite = %s,\n"
+ "mvExprToMvScanExprMapping = %s,\n queryToViewSlotMapping = %s",
queryTopPlan.getExpressions(),
materializationContext.getMvExprToMvScanExprMapping(),
queryToViewSlotMapping));
return null;
}
return new LogicalProject<>(
Expand All @@ -138,7 +140,7 @@ protected Plan rewriteQueryByView(MatchMode matchMode,
&& ((AggregateFunction) expr).isDistinct()))) {
// if mv aggregate function contains distinct, can not roll up, bail out.
materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(),
String.format("view contains distinct function so can not roll up, view plan is %s",
String.format("view contains distinct function so can not roll up, view plan = %s",
viewAggregate.getOutputExpressions()));
return null;
}
Expand All @@ -148,7 +150,7 @@ protected Plan rewriteQueryByView(MatchMode matchMode,
if (queryGroupAndFunctionPair == null) {
materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(),
String.format("query top plan split to group by and function fail,"
+ "queryTopPlan is %s, agg is %s",
+ "queryTopPlan = %s,\n agg = %s",
queryTopPlanAndAggPair.key().treeString(), queryTopPlanAndAggPair.value().treeString()));
return null;
}
Expand Down Expand Up @@ -176,6 +178,10 @@ protected Plan rewriteQueryByView(MatchMode matchMode,
Function rollupAggregateFunction = rollup(queryFunction, queryFunctionShuttled,
mvExprToMvScanExprQueryBased);
if (rollupAggregateFunction == null) {
materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(),
String.format("query function roll up fail, queryFunction = %s,\n"
+ "mvExprToMvScanExprQueryBased = %s",
queryFunction, mvExprToMvScanExprQueryBased));
return null;
}
// key is query need roll up expr, value is mv scan based roll up expr
Expand All @@ -189,8 +195,9 @@ protected Plan rewriteQueryByView(MatchMode matchMode,
false);
if (rewrittenFunctionExpression == null) {
materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(),
String.format("roll up expression can not rewrite by view, topExpression is %s,"
+ "needRollupExprMapping is %s", topExpression, needRollupExprMapping));
String.format("roll up expression can not rewrite by view, topExpression = %s,\n"
+ "needRollupExprMapping = %s,\n queryToViewSlotMapping = %s",
topExpression, needRollupExprMapping, queryToViewSlotMapping));
return null;
}
finalAggregateExpressions.add((NamedExpression) rewrittenFunctionExpression);
Expand All @@ -202,7 +209,7 @@ protected Plan rewriteQueryByView(MatchMode matchMode,
// group expr can not rewrite by view
materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(),
String.format("view group expressions doesn't not contains the query group by expression,"
+ "mvExprToMvScanExprQueryBased is %s,queryGroupShuttledExpr is %s",
+ "mvExprToMvScanExprQueryBased is %s,\nqueryGroupShuttledExpr is %s",
mvExprToMvScanExprQueryBased, queryGroupShuttledExpr));
return null;
}
Expand All @@ -219,8 +226,9 @@ protected Plan rewriteQueryByView(MatchMode matchMode,
if (rewrittenGroupExpression == null) {
materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(),
String.format("query top group expression can not be rewritten by view,"
+ "topExpression is %s, groupRewrittenExprMapping is %s",
topExpression, groupRewrittenExprMapping));
+ "topExpression is %s,\n groupRewrittenExprMapping is %s,\n"
+ "queryToViewSlotMapping = %s",
topExpression, groupRewrittenExprMapping, queryToViewSlotMapping));
return null;
}
finalAggregateExpressions.add((NamedExpression) rewrittenGroupExpression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ protected Plan rewriteQueryByView(MatchMode matchMode,
if (expressionsRewritten.isEmpty()
|| expressionsRewritten.stream().anyMatch(expr -> !(expr instanceof NamedExpression))) {
materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(),
String.format("join rewrite query by view fail, expressionToRewritten is %s, "
+ "mvExprToMvScanExprMapping is %s",
queryStructInfo.getExpressions(), materializationContext.getMvExprToMvScanExprMapping()));
String.format("join rewrite query by view fail, expressionToRewritten is %s,\n"
+ "mvExprToMvScanExprMapping is %s,\n queryToViewSlotMapping = %s",
queryStructInfo.getExpressions(), materializationContext.getMvExprToMvScanExprMapping(),
queryToViewSlotMapping));
return null;
}
// record the group id in materializationContext, and when rewrite again in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ protected List<Plan> rewrite(Plan queryPlan, CascadesContext cascadesContext) {
if (viewStructInfos.size() > 1) {
// view struct info should only have one
materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(),
"the num of view struct info is more then one");
String.format("the num of view struct info is more then one, mv plan is %s",
materializationContext.getMvPlan().treeString()));
return rewriteResults;
}
StructInfo viewStructInfo = viewStructInfos.get(0);
Expand Down Expand Up @@ -175,9 +176,10 @@ protected List<Plan> rewrite(Plan queryPlan, CascadesContext cascadesContext) {
true);
if (rewriteCompensatePredicates.isEmpty()) {
materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), String.format(
"rewrite compensate predicate fail, compensatePredicates = %s,"
+ "mvExprToMvScanExprMapping = %s", compensatePredicates,
materializationContext.getMvExprToMvScanExprMapping()));
"rewrite compensate predicate fail, compensatePredicates = %s,\n"
+ "mvExprToMvScanExprMapping = %s\n, queryToViewSlotMapping = %s",
compensatePredicates, materializationContext.getMvExprToMvScanExprMapping(),
queryToViewSlotMapping));
continue;
}
rewrittenPlan = new LogicalFilter<>(Sets.newHashSet(rewriteCompensatePredicates), mvScan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private ComparisonResult buildComparisonRes() {
*/
public String getErrorMessage() {
return String.format(
"graph logical not equals, query join edges is %s,\n" + "query filter edges is %s,\n"
"graph logical is not equal, query join edges is %s,\n" + "query filter edges is %s,\n"
+ "view join edges is %s,\n" + "view filter edges is %s\n" + "inferred edge with conds %s",
getQueryJoinEdges(),
getQueryFilterEdges(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(exprId);
}

@Override
public String toString() {
return "MappedSlot{" + "slot=" + slot + '}';
}
}

/** Chain fold tow mapping, such as this mapping is {[a -> b]}, the target mapping is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public Map<SlotReference, SlotReference> toSlotReferenceMap() {
this.slotReferenceMap = slotReferenceSlotReferenceMap;
return this.slotReferenceMap;
}

@Override
public String toString() {
return "SlotMapping{" + "relationSlotMap=" + relationSlotMap + '}';
}
}

0 comments on commit c0a62f5

Please sign in to comment.