Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
Signed-off-by: shuming.li <[email protected]>
  • Loading branch information
LiShuMing committed Oct 14, 2024
1 parent a71acc1 commit fca6261
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@
import static com.starrocks.sql.optimizer.rule.transformation.materialization.common.AggregatePushDownUtils.getPushDownRollupFinalAggregateOpt;
import static com.starrocks.sql.optimizer.rule.transformation.materialization.common.AggregatePushDownUtils.getRollupPartialAggregate;

/**
* In time-series business scenarios, metrics are aggregated based on the time dimension, with historical
* data continuously being archived (rolled up, compressed), while new data flows in real-time.
* By using Materialized Views (MVs) to speed up, different time granularity of MVs can be constructed,
* the most common being day, month, and year. However, when querying the base table (original table),
* it is hoped that the archived year, month, and day data can be used to speed up time slicing.
*
* <p> Implementation </p>
* Place the logic of splitting time predicates in time-series scenarios + the logic of aggregation push-down into a Rule. When
* it can be rewritten, rewrite the output; otherwise, do not change the original Query.
* Reuse the aggregation push-down + rewriting capabilities, and implement aggregation push-down + rolling up based on the
* aggregation status defined by the materialized view (later, general aggregation status can be used).
* Reuse the capability of nested MV rewriting, recursively call this Rule,
* and rewrite the scope of granularity as much as possible in one go.
*/
public class AggregatedTimeSeriesRewriter extends MaterializedViewRewriter {
private static final Logger LOG = LogManager.getLogger(AggregatedTimeSeriesRewriter.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ public class ColumnRangePredicate extends RangePredicate {

private TreeRangeSet<ConstantOperator> canonicalColumnRanges;

public static ColumnRangePredicate FALSE = new ColumnRangePredicate(TreeRangeSet.create());

public ColumnRangePredicate(TreeRangeSet<ConstantOperator> columnRanges) {
this.columnRanges = columnRanges;
this.expression = null;
this.columnRef = null;
this.canonicalColumnRanges = columnRanges;
}

public ColumnRangePredicate(ScalarOperator expression, TreeRangeSet<ConstantOperator> columnRanges) {
this.expression = expression;
List<ColumnRefOperator> columns = Utils.collect(expression, ColumnRefOperator.class);
Expand Down Expand Up @@ -99,15 +108,15 @@ public static ColumnRangePredicate andRange(
for (Range<ConstantOperator> otherRange : otherRangePredicate.columnRanges.asRanges()) {
// once there is a range that is not connected with the range, the result is null
if (!range.isConnected(otherRange)) {
return null;
return FALSE;
}
Range<ConstantOperator> intersection = range.intersection(otherRange);
if (!intersection.isEmpty()) {
ranges.add(intersection);
}
}
} else {
return null;
return FALSE;
}
}
return new ColumnRangePredicate(rangePredicate.getExpression(), TreeRangeSet.create(ranges));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ private void mergeColumnRange(
if (columnRangePredicateMap.containsKey(columnRangePredicate.getExpression())) {
ColumnRangePredicate newRangePredicate = columnRangePredicateMap.get(columnRangePredicate.getExpression());
newRangePredicate = mergeOp.apply(newRangePredicate, columnRangePredicate);
if (newRangePredicate == null) {
rangePredicates.add(new ConstRangePredicate(false));
if (newRangePredicate.equals(ColumnRangePredicate.FALSE)) {
rangePredicates.add(newRangePredicate);
return;
}
if (newRangePredicate.isUnbounded()) {
Expand Down

0 comments on commit fca6261

Please sign in to comment.