/** * Adds a bind marker for the {@code PER PARTITION LIMIT} clause to the {@code SELECT} statement * this {@code WHERE} clause is part of. * * <p>Note: support for {@code PER PARTITION LIMIT} clause is only available from Cassandra 3.6 * onwards. * * @param limit the bind marker to use as limit per partition. * @return the {@code SELECT} statement this {@code WHERE} clause is part of. * @throws IllegalStateException if a {@code PER PARTITION LIMIT} clause has already been * provided. * @throws IllegalStateException if this statement is a {@code SELECT DISTINCT} statement. */ public Select perPartitionLimit(BindMarker limit) { return statement.perPartitionLimit(limit); }
/** * Adds a {@code PER PARTITION LIMIT} clause to the {@code SELECT} statement this {@code WHERE} * clause is part of. * * <p>Note: support for {@code PER PARTITION LIMIT} clause is only available from Cassandra 3.6 * onwards. * * @param perPartitionLimit the limit to set per partition. * @return the {@code SELECT} statement this {@code WHERE} clause is part of. * @throws IllegalArgumentException if {@code perPartitionLimit <= 0}. * @throws IllegalStateException if a {@code PER PARTITION LIMIT} clause has already been * provided. * @throws IllegalStateException if this statement is a {@code SELECT DISTINCT} statement. */ public Select perPartitionLimit(int perPartitionLimit) { return statement.perPartitionLimit(perPartitionLimit); }
/** * Adds a bind marker for the {@code PER PARTITION LIMIT} clause to the {@code SELECT} statement this * {@code WHERE} clause if part of. * <p> * Note: support for {@code PER PARTITION LIMIT} clause is only available from * Cassandra 3.6 onwards. * * @param limit the bind marker to use as limit per partition. * @return the {@code SELECT} statement this {@code WHERE} clause if part of. * @throws IllegalStateException if a {@code PER PARTITION LIMIT} clause has already been * provided. * @throws IllegalStateException if this statement is a {@code SELECT DISTINCT} statement. */ public Select perPartitionLimit(BindMarker limit) { return statement.perPartitionLimit(limit); }
/** * Adds a bind marker for the {@code PER PARTITION LIMIT} clause to the {@code SELECT} statement this * {@code WHERE} clause if part of. * <p> * Note: support for {@code PER PARTITION LIMIT} clause is only available from * Cassandra 3.6 onwards. * * @param limit the bind marker to use as limit per partition. * @return the {@code SELECT} statement this {@code WHERE} clause if part of. * @throws IllegalStateException if a {@code PER PARTITION LIMIT} clause has already been * provided. * @throws IllegalStateException if this statement is a {@code SELECT DISTINCT} statement. */ public Select perPartitionLimit(BindMarker limit) { return statement.perPartitionLimit(limit); }
/** * Adds a bind marker for the {@code PER PARTITION LIMIT} clause to the {@code SELECT} statement this * {@code WHERE} clause if part of. * <p> * Note: support for {@code PER PARTITION LIMIT} clause is only available from * Cassandra 3.6 onwards. * * @param limit the bind marker to use as limit per partition. * @return the {@code SELECT} statement this {@code WHERE} clause if part of. * @throws IllegalStateException if a {@code PER PARTITION LIMIT} clause has already been * provided. * @throws IllegalStateException if this statement is a {@code SELECT DISTINCT} statement. */ public Select perPartitionLimit(BindMarker limit) { return statement.perPartitionLimit(limit); }
/** * Adds a {@code PER PARTITION LIMIT} clause to the {@code SELECT} statement this * {@code WHERE} clause if part of. * <p> * Note: support for {@code PER PARTITION LIMIT} clause is only available from * Cassandra 3.6 onwards. * * @param perPartitionLimit the limit to set per partition. * @return the {@code SELECT} statement this {@code WHERE} clause if part of. * @throws IllegalArgumentException if {@code perPartitionLimit <= 0}. * @throws IllegalStateException if a {@code PER PARTITION LIMIT} clause has already been * provided. * @throws IllegalStateException if this statement is a {@code SELECT DISTINCT} statement. */ public Select perPartitionLimit(int perPartitionLimit) { return statement.perPartitionLimit(perPartitionLimit); }
/** * Adds a {@code PER PARTITION LIMIT} clause to the {@code SELECT} statement this * {@code WHERE} clause if part of. * <p> * Note: support for {@code PER PARTITION LIMIT} clause is only available from * Cassandra 3.6 onwards. * * @param perPartitionLimit the limit to set per partition. * @return the {@code SELECT} statement this {@code WHERE} clause if part of. * @throws IllegalArgumentException if {@code perPartitionLimit <= 0}. * @throws IllegalStateException if a {@code PER PARTITION LIMIT} clause has already been * provided. * @throws IllegalStateException if this statement is a {@code SELECT DISTINCT} statement. */ public Select perPartitionLimit(int perPartitionLimit) { return statement.perPartitionLimit(perPartitionLimit); }
/** * Adds a {@code PER PARTITION LIMIT} clause to the {@code SELECT} statement this * {@code WHERE} clause if part of. * <p> * Note: support for {@code PER PARTITION LIMIT} clause is only available from * Cassandra 3.6 onwards. * * @param perPartitionLimit the limit to set per partition. * @return the {@code SELECT} statement this {@code WHERE} clause if part of. * @throws IllegalArgumentException if {@code perPartitionLimit <= 0}. * @throws IllegalStateException if a {@code PER PARTITION LIMIT} clause has already been * provided. * @throws IllegalStateException if this statement is a {@code SELECT DISTINCT} statement. */ public Select perPartitionLimit(int perPartitionLimit) { return statement.perPartitionLimit(perPartitionLimit); }
@Test(groups = "unit") public void should_handle_per_partition_limit_clause() { assertThat(select().all().from("foo").perPartitionLimit(2).toString()) .isEqualTo("SELECT * FROM foo PER PARTITION LIMIT 2;"); assertThat(select().all().from("foo").perPartitionLimit(bindMarker()).toString()) .isEqualTo("SELECT * FROM foo PER PARTITION LIMIT ?;"); assertThat(select().all().from("foo").perPartitionLimit(bindMarker("limit")).toString()) .isEqualTo("SELECT * FROM foo PER PARTITION LIMIT :limit;"); assertThat(select().all().from("foo").perPartitionLimit(2).limit(bindMarker()).toString()) .isEqualTo("SELECT * FROM foo PER PARTITION LIMIT 2 LIMIT ?;"); assertThat( .where(eq("a", bindMarker())) .orderBy(desc("b")) .perPartitionLimit(2) .limit(3) .toString()) .and(gt("b", bindMarker())) .orderBy(desc("b")) .perPartitionLimit(bindMarker()) .limit(3) .allowFiltering() "SELECT * FROM foo WHERE a=? AND b>? ORDER BY b DESC PER PARTITION LIMIT ? LIMIT 3 ALLOW FILTERING;"); try { select().distinct().all().from("foo").perPartitionLimit(3); fail("Should not allow DISTINCT + PER PARTITION LIMIT"); } catch (Exception e) {
.from(table) .groupBy("a", "b") .perPartitionLimit(1))) .containsExactly(row(1, 2, 6, 2L, 12), row(2, 2, 6, 1L, 6), row(4, 8, 24, 1L, 24)); .from(table) .groupBy("a", "b") .perPartitionLimit(1) .limit(2))) .containsExactly(row(1, 2, 6, 2L, 12), row(2, 2, 6, 1L, 6)); .where(eq("a", 1)) .groupBy("a", "b", "c") .perPartitionLimit(2))) .containsExactly(row(1, 2, 6, 1L, 6), row(1, 2, 12, 1L, 12)); .groupBy("a", "b", "c") .orderBy(desc("b"), desc("c")) .perPartitionLimit(1))) .containsExactly(row(1, 4, 24, 2L, 24)); .where(in("a", 1, 2, 4)) .groupBy("a", "b", "c") .perPartitionLimit(1))) .containsExactly(row(1, 2, 6, 1L, 6), row(2, 2, 6, 1L, 6), row(4, 8, 24, 1L, 24)); .where(in("a", 1, 2, 4)) .groupBy("a", "b", "c") .perPartitionLimit(2)))
@Test(groups = "short") public void should_support_per_partition_limit() throws Exception { assertThat(session().execute(select().all().from("test_ppl").perPartitionLimit(2))) .contains( row(0, 0, 0), row(4, 1, 1)); assertThat(session().execute(select().all().from("test_ppl").perPartitionLimit(2).limit(6))) .hasSize(6); assertThat(session().execute(select().all().from("test_ppl").perPartitionLimit(2).limit(5))) .contains(row(0, 0, 0), row(0, 1, 1), row(1, 0, 0), row(1, 1, 1), row(2, 0, 0)); .where(eq("a", bindMarker())) .orderBy(desc("b")) .perPartitionLimit(bindMarker()) .getQueryString(), 2, .and(gt("b", bindMarker())) .orderBy(desc("b")) .perPartitionLimit(bindMarker()) .allowFiltering() .getQueryString(),
@Test(groups = "unit") public void should_handle_per_partition_limit_clause() { assertThat(select().all().from("foo").perPartitionLimit(2).toString()) .isEqualTo("SELECT * FROM foo PER PARTITION LIMIT 2;"); assertThat(select().all().from("foo").perPartitionLimit(bindMarker()).toString()) .isEqualTo("SELECT * FROM foo PER PARTITION LIMIT ?;"); assertThat(select().all().from("foo").perPartitionLimit(bindMarker("limit")).toString()) .isEqualTo("SELECT * FROM foo PER PARTITION LIMIT :limit;"); assertThat(select().all().from("foo").perPartitionLimit(2).limit(bindMarker()).toString()) .isEqualTo("SELECT * FROM foo PER PARTITION LIMIT 2 LIMIT ?;"); assertThat( .where(eq("a", bindMarker())) .orderBy(desc("b")) .perPartitionLimit(2) .limit(3) .toString()) .and(gt("b", bindMarker())) .orderBy(desc("b")) .perPartitionLimit(bindMarker()) .limit(3) .allowFiltering() "SELECT * FROM foo WHERE a=? AND b>? ORDER BY b DESC PER PARTITION LIMIT ? LIMIT 3 ALLOW FILTERING;"); try { select().distinct().all().from("foo").perPartitionLimit(3); fail("Should not allow DISTINCT + PER PARTITION LIMIT"); } catch (Exception e) {
.from(table) .groupBy("a", "b") .perPartitionLimit(1))) .containsExactly(row(1, 2, 6, 2L, 12), row(2, 2, 6, 1L, 6), row(4, 8, 24, 1L, 24)); .from(table) .groupBy("a", "b") .perPartitionLimit(1) .limit(2))) .containsExactly(row(1, 2, 6, 2L, 12), row(2, 2, 6, 1L, 6)); .where(eq("a", 1)) .groupBy("a", "b", "c") .perPartitionLimit(2))) .containsExactly(row(1, 2, 6, 1L, 6), row(1, 2, 12, 1L, 12)); .groupBy("a", "b", "c") .orderBy(desc("b"), desc("c")) .perPartitionLimit(1))) .containsExactly(row(1, 4, 24, 2L, 24)); .where(in("a", 1, 2, 4)) .groupBy("a", "b", "c") .perPartitionLimit(1))) .containsExactly(row(1, 2, 6, 1L, 6), row(2, 2, 6, 1L, 6), row(4, 8, 24, 1L, 24)); .where(in("a", 1, 2, 4)) .groupBy("a", "b", "c") .perPartitionLimit(2)))
@Test(groups = "short") public void should_support_per_partition_limit() throws Exception { assertThat(session().execute(select().all().from("test_ppl").perPartitionLimit(2))) .contains( row(0, 0, 0), row(4, 1, 1)); assertThat(session().execute(select().all().from("test_ppl").perPartitionLimit(2).limit(6))) .hasSize(6); assertThat(session().execute(select().all().from("test_ppl").perPartitionLimit(2).limit(5))) .contains(row(0, 0, 0), row(0, 1, 1), row(1, 0, 0), row(1, 1, 1), row(2, 0, 0)); .where(eq("a", bindMarker())) .orderBy(desc("b")) .perPartitionLimit(bindMarker()) .getQueryString(), 2, .and(gt("b", bindMarker())) .orderBy(desc("b")) .perPartitionLimit(bindMarker()) .allowFiltering() .getQueryString(),