@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;"); }
assertThat(session().execute(select("a", count("a")).distinct().from(table).groupBy("a"))) .containsExactly(row(1, 1L), row(2, 1L), row(4, 1L)); session().execute(select("a", count("a")).distinct().from(table).groupBy("a").limit(2))) .containsExactly(row(1, 1L), row(2, 1L)); session() .execute( select("a", count("a")).distinct().from(table).where(eq("a", 1)).groupBy("a"))) .containsExactly(row(1, 1L)); .execute( select("a", count("a")) .distinct() .from(table) .where(in("a", 1, 2, 4)) .execute( select("a", count("a")) .distinct() .from(table) .where(in("a", 1, 2, 4))
assertThat(session().execute(select("a", count("a")).distinct().from(table).groupBy("a"))) .containsExactly(row(1, 1L), row(2, 1L), row(4, 1L)); session().execute(select("a", count("a")).distinct().from(table).groupBy("a").limit(2))) .containsExactly(row(1, 1L), row(2, 1L)); session() .execute( select("a", count("a")).distinct().from(table).where(eq("a", 1)).groupBy("a"))) .containsExactly(row(1, 1L)); .execute( select("a", count("a")) .distinct() .from(table) .where(in("a", 1, 2, 4)) .execute( select("a", count("a")) .distinct() .from(table) .where(in("a", 1, 2, 4))
Factory(Session session) { this.session = session; this.preparedStatement = session.prepare( QueryBuilder.select("service_name").distinct().from(Tables.SERVICE_NAMES)); }
Factory(Session session) { this.session = session; this.preparedStatement = session.prepare(QueryBuilder.select("service").distinct().from(TABLE_SERVICE_SPANS)); }
@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;"); }