Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logical properties #43524

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
import org.apache.doris.common.Id;
import org.apache.doris.nereids.trees.expressions.ExprId;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.expressions.literal.Literal;

import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -42,11 +45,18 @@ public class LogicalProperties {
protected final Supplier<Map<Slot, Slot>> outputMapSupplier;
protected final Supplier<Set<ExprId>> outputExprIdSetSupplier;
protected final Supplier<DataTrait> dataTraitSupplier;

protected final HashMap<SlotReference, Set<Literal>> literalMap = new HashMap<>();
private Integer hashCode = null;

public LogicalProperties(Supplier<List<Slot>> outputSupplier,
Supplier<DataTrait> dataTraitSupplier, HashMap<SlotReference, Set<Literal>> literalMap) {
this(outputSupplier, dataTraitSupplier, ImmutableList::of, literalMap);
}

public LogicalProperties(Supplier<List<Slot>> outputSupplier,
Supplier<DataTrait> dataTraitSupplier) {
this(outputSupplier, dataTraitSupplier, ImmutableList::of);
this(outputSupplier, dataTraitSupplier, ImmutableList::of, new HashMap<>());
}

/**
Expand All @@ -57,7 +67,8 @@ public LogicalProperties(Supplier<List<Slot>> outputSupplier,
*/
public LogicalProperties(Supplier<List<Slot>> outputSupplier,
Supplier<DataTrait> dataTraitSupplier,
Supplier<List<Slot>> nonUserVisibleOutputSupplier) {
Supplier<List<Slot>> nonUserVisibleOutputSupplier,
HashMap<SlotReference, Set<Literal>> literalMap) {
this.outputSupplier = Suppliers.memoize(
Objects.requireNonNull(outputSupplier, "outputSupplier can not be null")
);
Expand Down Expand Up @@ -98,6 +109,7 @@ public LogicalProperties(Supplier<List<Slot>> outputSupplier,
this.dataTraitSupplier = Suppliers.memoize(
Objects.requireNonNull(dataTraitSupplier, "Data Trait can not be null")
);
this.literalMap.putAll(literalMap);
}

public List<Slot> getOutput() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import org.apache.doris.nereids.trees.AbstractTreeNode;
import org.apache.doris.nereids.trees.expressions.ExprId;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.expressions.StatementScopeIdGenerator;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.plans.TreeStringPlan.TreeStringNode;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.util.MutableState;
Expand All @@ -40,6 +42,7 @@
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -87,6 +90,10 @@ protected AbstractPlan(PlanType type, Optional<GroupExpression> groupExpression,
this.id = zeroId;
}

public HashMap<SlotReference, Set<Literal>> collectColumnValues() {
return new HashMap<>();
}

@Override
public PlanType getType() {
return type;
Expand Down Expand Up @@ -205,7 +212,7 @@ public LogicalProperties computeLogicalProperties() {
Supplier<DataTrait> fdSupplier = () -> this instanceof LogicalPlan
? ((LogicalPlan) this).computeDataTrait()
: DataTrait.EMPTY_TRAIT;
return new LogicalProperties(outputSupplier, fdSupplier);
return new LogicalProperties(outputSupplier, fdSupplier, collectColumnValues());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
import org.apache.doris.nereids.memo.GroupExpression;
import org.apache.doris.nereids.properties.DataTrait.Builder;
import org.apache.doris.nereids.properties.LogicalProperties;
import org.apache.doris.nereids.trees.expressions.EqualTo;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.expressions.SubqueryExpr;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.nereids.trees.plans.algebra.Filter;
Expand All @@ -34,8 +37,13 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -175,4 +183,33 @@ public void computeEqualSet(Builder builder) {
public void computeFd(Builder builder) {
builder.addFuncDepsDG(child().getLogicalProperties().getTrait());
}

private Pair<SlotReference, Literal> slotEqualsToLiteral(EqualTo equal){
if (equal.left() instanceof SlotReference && equal.right() instanceof Literal) {
return Pair.of((SlotReference) equal.left(), (Literal) equal.right());
} else if (equal.left() instanceof Literal && equal.right() instanceof SlotReference) {
return Pair.of((SlotReference) equal.right(), (Literal) equal.left());
}
return null;
}

@Override
public HashMap<SlotReference, Set<Literal>> collectColumnValues() {
HashMap<SlotReference, Set<Literal>> literalMap = new HashMap<>();
Set<SlotReference> blackList = new HashSet<>();
for (Expression conj : conjuncts) {
if (conj instanceof EqualTo) {
Pair<SlotReference, Literal> pair = slotEqualsToLiteral((EqualTo) conj);
if (pair != null) {
if (literalMap.containsKey(pair.first)) {
blackList.add(pair.first);
} else {
literalMap.put(pair.first, Sets.newHashSet(pair.second));
}
}
}
}
return literalMap;
}

}
Loading