@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() .cast("f", DataType.cint()) .as("fint") .column("i") .from(TABLE2)
select() .fcall("avg", cast(column("i"), DataType.cfloat())) .as("iavg") .from(TABLE2) .where(eq("k", "cast_t")));
@Override String makePreparedQueryString(TableMetadata table, EntityMapper<?> mapper, MappingManager manager, Set<AliasedMappedProperty> columns, Collection<Mapper.Option> options) { Select.Selection selection = select(); for (AliasedMappedProperty col : mapper.allColumns) { Select.SelectionOrAlias column = col.mappedProperty.isComputed() ? selection.raw(col.mappedProperty.getMappedName()) : selection.column(col.mappedProperty.getMappedName()); if (col.alias == null) { selection = column; } else { selection = column.as(col.alias); } } Select select; if (table == null) { select = selection.from(mapper.keyspace, mapper.table); } else { select = selection.from(table); } Select.Where where = select.where(); for (int i = 0; i < mapper.primaryKeySize(); i++) where.and(eq(mapper.getPrimaryKeyColumn(i).mappedProperty.getMappedName(), bindMarker())); for (Mapper.Option option : options) { option.validate(QueryType.GET, manager); option.modifyQueryString(select); } return select.toString(); } },
@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 }
private Statement createQueryToGetOrganizationMembers(String organizationId) { UUID orgUuid = UUID.fromString(organizationId); return queryBuilder .select() .column(USER_ID).as(Users.USER_ID) .column(USER_FIRST_NAME).as(Users.FIRST_NAME) .column(USER_MIDDLE_NAME).as(Users.MIDDLE_NAME) .column(USER_LAST_NAME).as(Users.LAST_NAME) .column(USER_ROLES).as(Users.ROLES) .column(USER_EMAIL).as(Users.EMAIL) .from(Organizations.TABLE_NAME_MEMBERS) .where(eq(ORG_ID, orgUuid)); }
private Statement createQueryForFollowersOfApp(String applicationId) { UUID appUuid = UUID.fromString(applicationId); return QueryBuilder .select() .column(Follow.APP_NAME).as(Applications.APP_NAME) .column(Follow.APP_ID).as(Applications.APP_ID) .column(Follow.USER_FIRST_NAME).as(Users.FIRST_NAME) .column(Follow.TIME_OF_FOLLOW) .column(Follow.USER_ID) .from(Follow.TABLE_NAME_APP_FOLLOWERS) .where(eq(APP_ID, appUuid)); }
private Statement createQueryToGetOrganizationMembers(String organizationId) { UUID orgUuid = UUID.fromString(organizationId); return QueryBuilder .select() .column(USER_ID).as(Users.USER_ID) .column(USER_FIRST_NAME).as(Users.FIRST_NAME) .column(USER_MIDDLE_NAME).as(Users.MIDDLE_NAME) .column(USER_LAST_NAME).as(Users.LAST_NAME) .column(USER_ROLES).as(Users.ROLES) .column(USER_EMAIL).as(Users.EMAIL) .from(Organizations.TABLE_NAME_MEMBERS) .where(eq(ORG_ID, orgUuid)); }
/** * Generate a SELECT ... <strong>writetime(QueryBuilder.column("value")) AS write_time</strong> ... */ public final EntityWithComplexTypes_Select.Cols writeTime() { selection.fcall("writetime",QueryBuilder.column("value")).as("write_time"); return this; }
/** * Generate a SELECT ... <strong>writetime(QueryBuilder.column("value")) AS write_time</strong> ... */ public final EntityWithComplexTypes_Select.Cols writeTime() { select.fcall("writetime",QueryBuilder.column("value")).as("write_time"); return new EntityWithComplexTypes_Select.Cols(select); }
/** * Generate a SELECT ... <strong>writetime(QueryBuilder.column("value")) AS write_time</strong> ... */ public final EntityWithComplexTypes_Select.ColsTM writeTime() { selection.fcall("writetime",QueryBuilder.column("value")).as("write_time"); return this; }
/** * Generate a SELECT ... <strong>writetime(QueryBuilder.column("value")) AS write_time_2</strong> ... */ public final EntityWithComplexTypes_Select.Cols writeTimeWithCodec() { selection.fcall("writetime",QueryBuilder.column("value")).as("write_time_2"); return this; }
/** * Generate a SELECT ... <strong>writetime(QueryBuilder.column("value")) AS write_time_2</strong> ... */ public final EntityWithComplexTypes_Select.Cols writeTimeWithCodec() { select.fcall("writetime",QueryBuilder.column("value")).as("write_time_2"); return new EntityWithComplexTypes_Select.Cols(select); }
@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;"); }
private Statement createQueryForAppsFollowedBy(String userId) { UUID userUuid = UUID.fromString(userId); return QueryBuilder .select() .column(Follow.APP_NAME).as(Applications.APP_NAME) .column(Follow.APP_ID).as(Applications.APP_ID) .column(Follow.USER_FIRST_NAME).as(Users.FIRST_NAME) .column(Follow.TIME_OF_FOLLOW) .column(Follow.USER_ID) .from(Follow.TABLE_NAME_USER_FOLLOWING) .where(eq(USER_ID, userUuid)); }
/** * Generate a SELECT ... <strong>writetime(QueryBuilder.column("value")) AS write_time_2</strong> ... */ public final EntityWithComplexTypes_Select.ColsTM writeTimeWithCodec() { selection.fcall("writetime",QueryBuilder.column("value")).as("write_time_2"); return this; }
.column("a") .column("b") .as("clustering1") .max("c") .from(table)
select() .fcall("avg", cast(column("i"), DataType.cfloat())) .as("iavg") .from(TABLE2) .where(eq("k", "cast_t")));