Skip to content

Commit bbd1998

Browse files
stringalingabsurdfarce
authored andcommitted
CASSJAVA-3: Fix ordering of LIMIT and PER PARTITION LIMIT clauses
patch by David Stringer; reviewed by Lukasz Antoniak and Bret McGuire reference: #2022
1 parent 27e2bfa commit bbd1998

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

query-builder/src/main/java/com/datastax/oss/driver/internal/querybuilder/select/DefaultSelect.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,6 @@ public String asCql() {
425425

426426
orderingClause.ifPresent(c -> c.appendTo(builder));
427427

428-
if (limit != null) {
429-
builder.append(" LIMIT ");
430-
if (limit instanceof BindMarker) {
431-
((BindMarker) limit).appendTo(builder);
432-
} else {
433-
builder.append(limit);
434-
}
435-
}
436-
437428
if (perPartitionLimit != null) {
438429
builder.append(" PER PARTITION LIMIT ");
439430
if (perPartitionLimit instanceof BindMarker) {
@@ -443,6 +434,15 @@ public String asCql() {
443434
}
444435
}
445436

437+
if (limit != null) {
438+
builder.append(" LIMIT ");
439+
if (limit instanceof BindMarker) {
440+
((BindMarker) limit).appendTo(builder);
441+
} else {
442+
builder.append(limit);
443+
}
444+
}
445+
446446
if (allowsFiltering) {
447447
builder.append(" ALLOW FILTERING");
448448
}

query-builder/src/test/java/com/datastax/oss/driver/api/querybuilder/select/SelectLimitTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,10 @@ public void should_use_last_per_partition_limit_if_called_multiple_times() {
4949
assertThat(selectFrom("foo").all().perPartitionLimit(1).perPartitionLimit(2))
5050
.hasCql("SELECT * FROM foo PER PARTITION LIMIT 2");
5151
}
52+
53+
@Test
54+
public void should_put_limit_after_partition_limit() {
55+
assertThat(selectFrom("foo").all().perPartitionLimit(1).limit(1))
56+
.hasCql("SELECT * FROM foo PER PARTITION LIMIT 1 LIMIT 1");
57+
}
5258
}

0 commit comments

Comments
 (0)