Skip to content

Commit

Permalink
add annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
yujun777 committed Dec 10, 2024
1 parent 2dde0ad commit d4e6a2c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
import java.util.function.BinaryOperator;
import java.util.stream.Collectors;

/**
* collect range of expression
*/
public class RangeInference extends ExpressionVisitor<RangeInference.ValueDesc, ExpressionRewriteContext> {

/*
Expand Down Expand Up @@ -156,7 +159,10 @@ private ValueDesc simplify(ExpressionRewriteContext context,
return new UnknownValue(context, originExpr, valuePerRefs, isAnd);
}

public static abstract class ValueDesc {
/**
* value desc
*/
public abstract static class ValueDesc {
ExpressionRewriteContext context;
Expression toExpr;
Expression reference;
Expand All @@ -181,6 +187,7 @@ public ExpressionRewriteContext getExpressionRewriteContext() {

public abstract ValueDesc union(ValueDesc other);

/** or */
public static ValueDesc union(ExpressionRewriteContext context,
RangeValue range, DiscreteValue discrete, boolean reverseOrder) {
long count = discrete.values.stream().filter(x -> range.range.test(x)).count();
Expand All @@ -195,8 +202,10 @@ public static ValueDesc union(ExpressionRewriteContext context,
return new UnknownValue(context, toExpr, sourceValues, false);
}

/** intersect */
public abstract ValueDesc intersect(ValueDesc other);

/** intersect */
public static ValueDesc intersect(ExpressionRewriteContext context, RangeValue range, DiscreteValue discrete) {
DiscreteValue result = new DiscreteValue(context, discrete.reference, discrete.toExpr);
discrete.values.stream().filter(x -> range.range.contains(x)).forEach(result.values::add);
Expand All @@ -207,7 +216,7 @@ public static ValueDesc intersect(ExpressionRewriteContext context, RangeValue r
return new EmptyValue(context, range.reference, originExpr);
}

public static ValueDesc range(ExpressionRewriteContext context, ComparisonPredicate predicate) {
private static ValueDesc range(ExpressionRewriteContext context, ComparisonPredicate predicate) {
Literal value = (Literal) predicate.right();
if (predicate instanceof EqualTo) {
return new DiscreteValue(context, predicate.left(), predicate, value);
Expand All @@ -233,6 +242,9 @@ public static ValueDesc discrete(ExpressionRewriteContext context, InPredicate i
}
}

/**
* empty range
*/
public static class EmptyValue extends ValueDesc {

public EmptyValue(ExpressionRewriteContext context, Expression reference, Expression toExpr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ private Expression getExpression(DiscreteValue value) {
}

private Expression getExpression(UnknownValue value) {
Expression reference = value.getReference();
List<ValueDesc> sourceValues = value.getSourceValues();
Expression originExpr = value.getOriginExpr();
if (sourceValues.isEmpty()) {
Expand Down

0 comments on commit d4e6a2c

Please sign in to comment.