Skip to content

Commit dd51ee2

Browse files
authored
Enable AggregateCursorContinuation serialize to the new implementation (#3495)
AggregateCursorContinuation was introduced in this PR: https://github.com/FoundationDB/fdb-record-layer/pull/3397/files#, but it was not enabled, the continuation was still serialized in the old way, this PR enables it to serialize in the new way.
1 parent 837e02e commit dd51ee2

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/RecordQueryStreamingAggregationPlan.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public RecordQueryStreamingAggregationPlan translateCorrelations(@Nonnull final
222222
groupingKeyAlias,
223223
aggregateAlias,
224224
completeResultValue,
225-
SerializationMode.TO_OLD);
225+
serializationMode);
226226
}
227227

228228
@Nonnull
@@ -234,7 +234,7 @@ public RecordQueryStreamingAggregationPlan withChild(@Nonnull final Reference ch
234234
groupingKeyAlias,
235235
aggregateAlias,
236236
completeResultValue,
237-
SerializationMode.TO_OLD);
237+
serializationMode);
238238
}
239239

240240
@Nonnull
@@ -478,7 +478,7 @@ public static RecordQueryStreamingAggregationPlan of(@Nonnull final Quantifier.P
478478
final var referencedAggregateValue = ObjectValue.of(aggregateAlias, aggregateValue.getResultType());
479479

480480
return new RecordQueryStreamingAggregationPlan(inner, groupingKeyValue, aggregateValue, groupingKeyAlias, aggregateAlias,
481-
resultValueFunction.apply(referencedGroupingKeyValue, referencedAggregateValue), SerializationMode.TO_OLD);
481+
resultValueFunction.apply(referencedGroupingKeyValue, referencedAggregateValue), SerializationMode.TO_NEW);
482482
}
483483

484484
@Nonnull

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/RecordLayerIterator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ private void fetchNextResult() {
9090
noNextReason = result.getNoNextReason();
9191
if (noNextReason == RecordCursor.NoNextReason.SOURCE_EXHAUSTED) {
9292
this.continuation = ContinuationImpl.END;
93+
} else {
94+
this.continuation = ContinuationImpl.fromUnderlyingBytes(result.getContinuation().toBytes());
9395
}
9496
}
9597
}

fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/query/GroupByQueryTests.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ public GroupByQueryTests() {
5050
Utils.enableCascadesDebugger();
5151
}
5252

53-
@Disabled // doesn't work for serializationMode = TO_OLD, re-enable after serializationMode = TO_NEW
5453
@Test
5554
void groupByWithScanLimit() throws Exception {
5655
final String schemaTemplate =
5756
"CREATE TABLE T1(pk bigint, a bigint, b bigint, c bigint, PRIMARY KEY(pk))" +
5857
"CREATE INDEX idx1 as select a, b, c from t1 order by a, b, c";
5958
try (var ddl = Ddl.builder().database(URI.create("/TEST/QT")).relationalExtension(relationalExtension).schemaTemplate(schemaTemplate).build()) {
6059
try (var conn = ddl.setSchemaAndGetConnection()) {
60+
Continuation continuation = null;
6161
conn.setOption(Options.Name.EXECUTION_SCANNED_ROWS_LIMIT, 2);
62+
conn.setOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true);
6263
try (var statement = conn.createStatement()) {
6364
insertT1Record(statement, 2, 1, 1, 20);
6465
insertT1Record(statement, 3, 1, 2, 5);
@@ -70,7 +71,6 @@ void groupByWithScanLimit() throws Exception {
7071
insertT1Record(statement, 9, 2, 1, 90);
7172

7273
String query = "SELECT a AS OK, b, MAX(c) FROM T1 GROUP BY a, b";
73-
Continuation continuation = null;
7474
// scan pk = 2 and pk = 3 and hit SCAN_LIMIT_REACHED
7575
Assertions.assertTrue(statement.execute(query), "Did not return a result set from a select statement!");
7676
try (final RelationalResultSet resultSet = statement.getResultSet()) {
@@ -79,30 +79,34 @@ void groupByWithScanLimit() throws Exception {
7979
.hasNoNextRow();
8080
continuation = resultSet.getContinuation();
8181
}
82+
}
83+
try (var preparedStatement = conn.prepareStatement("EXECUTE CONTINUATION ?param")) {
84+
conn.setOption(Options.Name.EXECUTION_SCANNED_ROWS_LIMIT, 2);
85+
conn.setOption(Options.Name.CONTINUATIONS_CONTAIN_COMPILED_STATEMENTS, true);
8286
// scan pk = 5 and pk = 4 rows, hit SCAN_LIMIT_REACHED
83-
Assertions.assertTrue(statement.execute("EXECUTE CONTINUATION " + Base64.getEncoder().encodeToString(continuation.serialize())), "Did not return a result set from a select statement!");
84-
try (final RelationalResultSet resultSet = statement.getResultSet()) {
87+
preparedStatement.setBytes("param", continuation.serialize());
88+
try (final RelationalResultSet resultSet = preparedStatement.executeQuery()) {
8589
ResultSetAssert.assertThat(resultSet)
8690
.hasNoNextRow();
8791
continuation = resultSet.getContinuation();
8892
}
8993
// scan pk = 6 and pk = 8 rows, hit SCAN_LIMIT_REACHED
90-
Assertions.assertTrue(statement.execute("EXECUTE CONTINUATION " + Base64.getEncoder().encodeToString(continuation.serialize())), "Did not return a result set from a select statement!");
91-
try (final RelationalResultSet resultSet = statement.getResultSet()) {
94+
preparedStatement.setBytes("param", continuation.serialize());
95+
try (final RelationalResultSet resultSet = preparedStatement.executeQuery()) {
9296
ResultSetAssert.assertThat(resultSet).hasNextRow()
9397
.isRowExactly(1L, 2L, 15L)
9498
.hasNoNextRow();
9599
continuation = resultSet.getContinuation();
96100
}
97101
// scan pk = 7 and pk = 9 rows, hit SCAN_LIMIT_REACHED
98-
Assertions.assertTrue(statement.execute("EXECUTE CONTINUATION " + Base64.getEncoder().encodeToString(continuation.serialize())), "Did not return a result set from a select statement!");
99-
try (final RelationalResultSet resultSet = statement.getResultSet()) {
102+
preparedStatement.setBytes("param", continuation.serialize());
103+
try (final RelationalResultSet resultSet = preparedStatement.executeQuery()) {
100104
ResultSetAssert.assertThat(resultSet).hasNoNextRow();
101105
continuation = resultSet.getContinuation();
102106
}
103107
// hit SOURCE_EXHAUSTED
104-
Assertions.assertTrue(statement.execute("EXECUTE CONTINUATION " + Base64.getEncoder().encodeToString(continuation.serialize())), "Did not return a result set from a select statement!");
105-
try (final RelationalResultSet resultSet = statement.getResultSet()) {
108+
preparedStatement.setBytes("param", continuation.serialize());
109+
try (final RelationalResultSet resultSet = preparedStatement.executeQuery()) {
106110
ResultSetAssert.assertThat(resultSet).hasNextRow()
107111
.isRowExactly(2L, 1L, 90L)
108112
.hasNoNextRow();

0 commit comments

Comments
 (0)