@Test(groups = "unit") public void should_handle_to_json() throws Exception { assertThat(select().toJson("id").as("id").toJson("age").as("age").from("users").toString()) .isEqualTo("SELECT toJson(id) AS id,toJson(age) AS age FROM users;"); assertThat(select().distinct().toJson("id").as("id").from("users").toString()) .isEqualTo("SELECT DISTINCT toJson(id) AS id FROM users;"); assertThat( select(alias(toJson("id"), "id"), alias(toJson("age"), "age")).from("users").toString()) .isEqualTo("SELECT toJson(id) AS id,toJson(age) AS age FROM users;"); assertThat(select(alias(toJson("id"), "id")).distinct().from("users").toString()) .isEqualTo("SELECT DISTINCT toJson(id) AS id FROM users;"); }
@Test(groups = "unit") public void should_handle_select_json() throws Exception { assertThat(select().json().from("users").toString()).isEqualTo("SELECT JSON * FROM users;"); assertThat(select("id", "age").json().from("users").toString()) .isEqualTo("SELECT JSON id,age FROM users;"); assertThat( select() .json() .column("id") .writeTime("age") .ttl("state") .as("ttl") .from("users") .toString()) .isEqualTo("SELECT JSON id,writetime(age),ttl(state) AS ttl FROM users;"); assertThat(select().distinct().json().column("id").from("users").toString()) .isEqualTo( "SELECT JSON DISTINCT id FROM users;"); // note that the correct syntax is JSON DISTINCT }
"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) {
selection.distinct();
.distinct(); partitionKeys.forEach(column -> selection.column(column));
selection.distinct(); };
/** * Get the driver builder object with the selection clause. * * @return A {@link com.datastax.driver.core.querybuilder.Select.Builder}. */ private Select.Builder getDriverBuilder() { Select.Builder builder; if (selectionClause.getType() == SelectionClause.TYPE_COUNT) { builder = QueryBuilder.select().countAll(); } else { // Selection type SelectionList selList = (SelectionList) selectionClause; if (selList.getSelection().getType() != Selection.TYPE_ASTERISK) { Select.Selection selection = QueryBuilder.select(); if (selList.isDistinct()) { selection = selection.distinct(); } // Select the required columns. SelectionSelectors selSelectors = (SelectionSelectors) selList.getSelection(); builder = getDriverBuilderSelection(selSelectors, selection); } else { builder = QueryBuilder.select().all(); } } return builder; }
selection.distinct(); };
@Test(groups = "unit") public void should_handle_select_json() throws Exception { assertThat(select().json().from("users").toString()).isEqualTo("SELECT JSON * FROM users;"); assertThat(select("id", "age").json().from("users").toString()) .isEqualTo("SELECT JSON id,age FROM users;"); assertThat( select() .json() .column("id") .writeTime("age") .ttl("state") .as("ttl") .from("users") .toString()) .isEqualTo("SELECT JSON id,writetime(age),ttl(state) AS ttl FROM users;"); assertThat(select().distinct().json().column("id").from("users").toString()) .isEqualTo( "SELECT JSON DISTINCT id FROM users;"); // note that the correct syntax is JSON DISTINCT }
public static Select selectDistinctFrom(CassandraTableHandle tableHandle, List<CassandraColumnHandle> columns) { return from(select(columns).distinct(), tableHandle); }
public static Select selectDistinctFrom(CassandraTableHandle tableHandle, List<CassandraColumnHandle> columns) { return from(select(columns).distinct(), tableHandle); }
@Test(groups = "unit") public void should_handle_to_json() throws Exception { assertThat(select().toJson("id").as("id").toJson("age").as("age").from("users").toString()) .isEqualTo("SELECT toJson(id) AS id,toJson(age) AS age FROM users;"); assertThat(select().distinct().toJson("id").as("id").from("users").toString()) .isEqualTo("SELECT DISTINCT toJson(id) AS id FROM users;"); assertThat( select(alias(toJson("id"), "id"), alias(toJson("age"), "age")).from("users").toString()) .isEqualTo("SELECT toJson(id) AS id,toJson(age) AS age FROM users;"); assertThat(select(alias(toJson("id"), "id")).distinct().from("users").toString()) .isEqualTo("SELECT DISTINCT toJson(id) AS id FROM users;"); }
"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) {
public static Select selectDistinctFrom(CassandraTableHandle tableHandle, List<CassandraColumnHandle> columns) { return from(select(columns).distinct(), tableHandle); }