Skip to content

Commit 4c9ec49

Browse files
committed
rebased; regular intersections work; pre rollup
1 parent 2d51836 commit 4c9ec49

File tree

6 files changed

+83
-7
lines changed

6 files changed

+83
-7
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -983,10 +983,10 @@ private static Ordering orderingFromOrderingParts(final @Nonnull List<MatchedOrd
983983
protected static boolean isCompatibleComparisonKey(@Nonnull Collection<Value> comparisonKeyValues,
984984
@Nonnull List<Value> commonPrimaryKeyValues,
985985
@Nonnull ImmutableSet<Value> equalityBoundKeyValues) {
986-
if (comparisonKeyValues.isEmpty()) {
987-
// everything is in one row
988-
return true;
989-
}
986+
// if (comparisonKeyValues.isEmpty()) {
987+
// // everything is in one row
988+
// return true;
989+
// }
990990

991991
return commonPrimaryKeyValues
992992
.stream()

fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/query/plan/cascades/MacroFunctionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void testColumnProjection() {
4343
Type.Record.Field.of(Type.primitiveType(Type.TypeCode.STRING), Optional.of("name")),
4444
Type.Record.Field.of(Type.primitiveType(Type.TypeCode.LONG), Optional.of("id")));
4545
Type record = Type.Record.fromFields(false, fields);
46-
QuantifiedObjectValue param = QuantifiedObjectValue.of(CorrelationIdentifier.uniqueID(), record);
46+
QuantifiedObjectValue param = QuantifiedObjectValue.of(CorrelationIdentifier.uniqueId(), record);
4747
FieldValue bodyValue = FieldValue.ofFieldName(param, "name");
4848
MacroFunction macroFunction = new MacroFunction("getName", ImmutableList.of(param), bodyValue);
4949

@@ -60,8 +60,8 @@ void testAdd() {
6060
ImmutableList<Type.Record.Field> fields = ImmutableList.of(
6161
Type.Record.Field.of(Type.primitiveType(Type.TypeCode.LONG), Optional.of("id")));
6262
Type record = Type.Record.fromFields(false, fields);
63-
QuantifiedObjectValue param1 = QuantifiedObjectValue.of(CorrelationIdentifier.uniqueID(), record);
64-
QuantifiedObjectValue param2 = QuantifiedObjectValue.of(CorrelationIdentifier.uniqueID(), record);
63+
QuantifiedObjectValue param1 = QuantifiedObjectValue.of(CorrelationIdentifier.uniqueId(), record);
64+
QuantifiedObjectValue param2 = QuantifiedObjectValue.of(CorrelationIdentifier.uniqueId(), record);
6565

6666
ArithmeticValue bodyValue = new ArithmeticValue(ArithmeticValue.PhysicalOperator.ADD_LL, param1, param2);
6767
MacroFunction macroFunction = new MacroFunction("add", ImmutableList.of(param1, param2), bodyValue);

yaml-tests/src/test/java/YamlIntegrationTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,10 @@ public void recursiveCte(YamlTest.Runner runner) throws Exception {
253253
public void enumTest(YamlTest.Runner runner) throws Exception {
254254
runner.runYamsql("enum.yamsql");
255255
}
256+
257+
@TestTemplate
258+
@MaintainYamlTestConfig(YamlTestConfigFilters.CORRECT_EXPLAIN_AND_METRICS)
259+
public void compositeAggregates(YamlTest.Runner runner) throws Exception {
260+
runner.runYamsql("composite-aggregates.yamsql");
261+
}
256262
}
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
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
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# composite-aggregates.yamsql
3+
#
4+
# This source file is part of the FoundationDB open source project
5+
#
6+
# Copyright 2021-2025 Apple Inc. and the FoundationDB project authors
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
20+
---
21+
schema_template:
22+
create table t1(id bigint, col1 bigint, col2 bigint, primary key(id))
23+
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 t2_i1 as select count(*) from t2
26+
create index t2_i2 as select count(*) from t2 group by col1
27+
create index t2_i3 as select count(col2) from t2
28+
create index t2_i4 as select count(col2) from t2 group by col1
29+
create index t2_i5 as select sum(col1) from t2
30+
create index t2_i6 as select sum(col2) from t2 group by col1
31+
create index t2_i7 as select count(*) from t2 group by col1, col2
32+
create index t3_i1 as select col1 from t3
33+
create index t3_i2 as select col2 from t3
34+
35+
---
36+
test_block:
37+
name: agg-empty-table-tests
38+
preset: single_repetition_ordered
39+
tests:
40+
#-
41+
# - query: select count(*) from T2 group by col1, col2;
42+
# - explain: "AISCAN(T2_I7 <,> BY_GROUP -> [_0: KEY:[0], _1: KEY:[1], _2: VALUE:[0]]) | MAP (_._2 AS _0)"
43+
# - result: []
44+
#-
45+
# - query: select count(*) from T2 group by col2, col1;
46+
# - explain: "AISCAN(T2_I7 <,> BY_GROUP -> [_0: KEY:[0], _1: KEY:[1], _2: VALUE:[0]]) | MAP (_._2 AS _0)"
47+
# - result: []
48+
#-
49+
# - query: select count(*) from T2 where col1 = 3 group by col2;
50+
# - explain: "AISCAN(T2_I7 [EQUALS promote(@c11 AS LONG)] BY_GROUP -> [_0: KEY:[0], _1: KEY:[1], _2: VALUE:[0]]) | MAP (_._2 AS _0)"
51+
# - result: []
52+
-
53+
- query: select sum(col2) / count(col2) from T2 group by col1;
54+
- 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)"
55+
- result: []
56+
...
57+

0 commit comments

Comments
 (0)