[Feature](materialized-view) support some case unmached to materialized-view (#30036)
same column appears in key and value like select id,count(id) group by id; complex expr in sum select sum(if(xxx));
This commit is contained in:
@ -159,6 +159,7 @@ public class BinaryPredicate extends Predicate implements Writable {
|
||||
// for restoring
|
||||
public BinaryPredicate() {
|
||||
super();
|
||||
printSqlInParens = true;
|
||||
}
|
||||
|
||||
public BinaryPredicate(Operator op, Expr e1, Expr e2) {
|
||||
@ -169,6 +170,7 @@ public class BinaryPredicate extends Predicate implements Writable {
|
||||
children.add(e1);
|
||||
Preconditions.checkNotNull(e2);
|
||||
children.add(e2);
|
||||
printSqlInParens = true;
|
||||
}
|
||||
|
||||
public BinaryPredicate(Operator op, Expr e1, Expr e2, Type retType, NullableMode nullableMode) {
|
||||
@ -181,6 +183,7 @@ public class BinaryPredicate extends Predicate implements Writable {
|
||||
children.add(e2);
|
||||
fn = new Function(new FunctionName(op.name), Lists.newArrayList(e1.getType(), e2.getType()), retType,
|
||||
false, true, nullableMode);
|
||||
printSqlInParens = true;
|
||||
}
|
||||
|
||||
protected BinaryPredicate(BinaryPredicate other) {
|
||||
@ -188,6 +191,7 @@ public class BinaryPredicate extends Predicate implements Writable {
|
||||
op = other.op;
|
||||
slotIsleft = other.slotIsleft;
|
||||
isInferred = other.isInferred;
|
||||
printSqlInParens = true;
|
||||
}
|
||||
|
||||
public boolean isInferred() {
|
||||
|
||||
@ -1103,7 +1103,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
}
|
||||
if (isInputSlotsContainsNone(
|
||||
predicates.stream().filter(e -> !indexConjuncts.contains(e.toSql())).collect(Collectors.toList()),
|
||||
slotsToReplace) && isInputSlotsContainsNone(groupingExprs, slotsToReplace)) {
|
||||
slotsToReplace)) {
|
||||
ImmutableSet<Slot> newRequiredSlots = requiredScanOutput.stream()
|
||||
.map(slot -> (Slot) ExpressionUtils.replace(slot, slotMap)).collect(ImmutableSet.toImmutableSet());
|
||||
return new AggRewriteResult(index, true, newRequiredSlots, exprRewriteMap);
|
||||
@ -1522,8 +1522,7 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
if (result != sum) {
|
||||
return result;
|
||||
}
|
||||
Optional<Slot> slotOpt = ExpressionUtils.extractSlotOrCastOnSlot(sum.child(0));
|
||||
if (!sum.isDistinct() && slotOpt.isPresent()) {
|
||||
if (!sum.isDistinct()) {
|
||||
Expression expr = castIfNeed(sum.child(), BigIntType.INSTANCE);
|
||||
String sumColumn = normalizeName(CreateMaterializedViewStmt.mvColumnBuilder(AggregateType.SUM,
|
||||
CreateMaterializedViewStmt.mvColumnBuilder(expr.toSql())));
|
||||
@ -1532,7 +1531,9 @@ public class SelectMaterializedIndexWithAggregate extends AbstractSelectMaterial
|
||||
Slot sumSlot = context.checkContext.scan.getOutputByIndex(context.checkContext.index).stream()
|
||||
.filter(s -> sumColumn.equalsIgnoreCase(normalizeName(s.getName()))).findFirst()
|
||||
.orElseThrow(() -> new AnalysisException("cannot find sum slot when select mv"));
|
||||
context.exprRewriteMap.slotMap.put(slotOpt.get(), sumSlot);
|
||||
for (Slot slot : sum.child().getInputSlots()) {
|
||||
context.exprRewriteMap.slotMap.put(slot, sumSlot);
|
||||
}
|
||||
context.exprRewriteMap.projectExprMap.put(sum.child(), sumSlot);
|
||||
Sum newSum = new Sum(sumSlot);
|
||||
context.exprRewriteMap.aggFuncMap.put(sum, newSum);
|
||||
|
||||
Reference in New Issue
Block a user