Skip to content

Commit 41ae9b7

Browse files
committed
rollups work
1 parent b9cda6b commit 41ae9b7

File tree

5 files changed

+43
-19
lines changed

5 files changed

+43
-19
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/AggregateIndexMatchCandidate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ public NonnullPair<List<Value>, Value> getGroupingAndAggregateAccessors(final in
505505
Verify.verify(deconstructedRecord.size() > numGroupings);
506506
final var groupingAccessorValues =
507507
ImmutableList.copyOf(deconstructedRecord.subList(0, numGroupings));
508-
final var aggregateAccessorValue = deconstructedRecord.get(deconstructedRecord.size() - 1);
508+
final var aggregateAccessorValue = deconstructedRecord.get(numGroupings);
509509
return NonnullPair.of(groupingAccessorValues, aggregateAccessorValue);
510510
}
511511

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/RequestedOrdering.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.apple.foundationdb.record.query.plan.cascades.values.Values;
3030
import com.apple.foundationdb.record.query.plan.cascades.values.simplification.OrderingValueComputationRuleSet;
3131
import com.apple.foundationdb.record.query.plan.cascades.values.simplification.RequestedOrderingValueSimplificationRuleSet;
32+
import com.apple.foundationdb.record.query.plan.cascades.values.translation.TranslationMap;
3233
import com.google.common.base.Suppliers;
3334
import com.google.common.base.Verify;
3435
import com.google.common.collect.ImmutableList;
@@ -88,6 +89,7 @@ private RequestedOrdering(@Nonnull final List<RequestedOrderingPart> orderingPar
8889
this.valueRequestedSortOrderMapSupplier = Suppliers.memoize(this::computeValueSortOrderMap);
8990
}
9091

92+
@Nonnull
9193
public Distinctness getDistinctness() {
9294
return distinctness;
9395
}
@@ -222,6 +224,20 @@ public RequestedOrdering pushDown(@Nonnull final Value value,
222224
return new RequestedOrdering(pushedDownOrderingPartsBuilder.build(), Distinctness.PRESERVE_DISTINCTNESS, isExhaustive());
223225
}
224226

227+
@Nonnull
228+
public RequestedOrdering translate(@Nonnull TranslationMap translationMap) {
229+
//
230+
// Need to push every participating value of this requested ordering through the value.
231+
//
232+
final var pushedDownOrderingPartsBuilder = ImmutableList.<RequestedOrderingPart>builder();
233+
for (final var orderingPart : orderingParts) {
234+
final var orderingValue = orderingPart.getValue();
235+
final var translatedOrderingValue = orderingValue.translateCorrelations(translationMap);
236+
pushedDownOrderingPartsBuilder.add(new RequestedOrderingPart(translatedOrderingValue, orderingPart.getSortOrder()));
237+
}
238+
return new RequestedOrdering(pushedDownOrderingPartsBuilder.build(), Distinctness.PRESERVE_DISTINCTNESS, isExhaustive());
239+
}
240+
225241
@Nonnull
226242
private Map<Value, RequestedSortOrder> computeValueSortOrderMap() {
227243
return getOrderingParts()
Binary file not shown.
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
agg-empty-table-tests:
2-
- query: EXPLAIN select sum(col2) / count(col2) from T2 group by col1;
3-
explain: 'AISCAN(T2_I6 <,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) ∩ AISCAN(T2_I4
4-
<,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) COMPARE BY (_._0._0) WITH q0,
5-
q1 RETURN (q0._0 AS _0, q0._1 AS _1, q1._1 AS _2) | MAP (_._1 / _._2 AS _0)'
6-
task_count: 317
7-
task_total_time_ms: 11
8-
transform_count: 115
9-
transform_time_ms: 10
10-
transform_yield_count: 51
11-
insert_time_ms: 0
12-
insert_new_count: 16
13-
insert_reused_count: 0
2+
- query: EXPLAIN select col1, min(col2) from T3 group by col1, col3;
3+
explain: 'AISCAN(T3_I2 <,> BY_GROUP -> [_0: KEY:[0], _1: KEY:[2], _2: KEY:[1]])
4+
| MAP (_._0 AS COL1, _._2 AS _1)'
5+
task_count: 418
6+
task_total_time_ms: 105
7+
transform_count: 145
8+
transform_time_ms: 82
9+
transform_yield_count: 50
10+
insert_time_ms: 3
11+
insert_new_count: 50
12+
insert_reused_count: 4

yaml-tests/src/test/resources/composite-aggregates.yamsql

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121
schema_template:
2222
create table t1(id bigint, col1 bigint, col2 bigint, col3 bigint, primary key(id))
2323
create table t2(id bigint, col1 bigint, col2 bigint, primary key(id))
24-
create table t3(id bigint, col1 bigint, col2 bigint, primary key(id))
25-
create index t1_i1 as select sum(col1) from t1 group by col2, col3
26-
create index t1_i2 as select count(*) from t1 group by col2
24+
create table t3(id bigint, col1 bigint, col2 bigint, col3 bigint, primary key(id))
25+
create index t1_i1 as select count(col1) from t1 group by col2, col3
26+
create index t1_i2 as select col2, sum(col1) from t1 group by col2
2727
create index t2_i1 as select count(*) from t2
2828
create index t2_i2 as select count(*) from t2 group by col1
2929
create index t2_i3 as select count(col2) from t2
3030
create index t2_i4 as select count(col2) from t2 group by col1
3131
create index t2_i5 as select sum(col1) from t2
3232
create index t2_i6 as select sum(col2) from t2 group by col1
3333
create index t2_i7 as select count(*) from t2 group by col1, col2
34+
create index t3_i1 as select col1, max(col2), col3 from T3 group by col1, col3 order by col1, max(col2), col3
35+
create index t3_i2 as select col1, min(col2), col3 from T3 group by col1, col3 order by col1, min(col2), col3
3436

3537
---
3638
setup:
@@ -93,9 +95,16 @@ test_block:
9395
# - query: select sum(col2), count(col2) from T2 where col1 < 2 group by col1 having sum(col2) = 17;
9496
# - explain: "AISCAN(T2_I6 [[LESS_THAN promote(@c16 AS LONG)]] BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) ∩ AISCAN(T2_I4 [[LESS_THAN promote(@c16 AS LONG)]] BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) COMPARE BY (_._0._0) WITH q0, q1 RETURN (q0._0 AS _0, q0._1 AS _1, q1._1 AS _2) | FILTER _._1 EQUALS promote(@c26 AS LONG) | MAP (_._1 AS _0, _._2 AS _1)"
9597
# - result: [{!l 17, !l 4}]
98+
#-
99+
# - query: select sum(col1) / count(col1) from T1 group by col2;
100+
# - explain: "AISCAN(T2_I6 <,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) ∩ AISCAN(T2_I4 <,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) COMPARE BY (_._0._0) WITH q0, q1 RETURN (q0._0 AS _0, q0._1 AS _1, q1._1 AS _2) | MAP (_._1 / _._2 AS _0)"
101+
# - result: []
102+
#-
103+
# - query: select col2, sum(col1) / count(col1) from T1 where col2 < 2 group by col2 having sum(col1) = 17;
104+
# - explain: "AISCAN(T1_I2 [[LESS_THAN promote(@c16 AS LONG)]] BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) ∩ AISCAN(T1_I1 [[LESS_THAN promote(@c16 AS LONG)]] BY_GROUP -> [_0: KEY:[0], _1: KEY:[1], _2: VALUE:[0]]) | AGG sum_l(_._1) GROUP BY (_._0 AS _0) COMPARE BY (_._0._0) WITH q0, q1 RETURN (q0._0 AS _0, q0._1 AS _1, q1._1 AS _2) | FILTER _._1 EQUALS promote(@c26 AS LONG) | MAP (_._1 / _._2 AS _0)"
105+
# - result: []
96106
-
97-
- query: select sum(col1) / count(*) from T1 group by col2;
98-
- explain: "AISCAN(T2_I6 <,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) ∩ AISCAN(T2_I4 <,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) COMPARE BY (_._0._0) WITH q0, q1 RETURN (q0._0 AS _0, q0._1 AS _1, q1._1 AS _2) | MAP (_._1 / _._2 AS _0)"
107+
- query: select col1, min(col2), max(col2) from T3 group by col1, col3;
108+
- explain: "AISCAN(T3_I2 <,> BY_GROUP -> [_0: KEY:[0], _1: KEY:[2], _2: KEY:[1]]) | MAP (_._0 AS COL1, _._2 AS _1)"
99109
- result: []
100-
101110
...

0 commit comments

Comments
 (0)