@Override public List<UUID> getTokensForPrincipal(ByteBuffer principalKeyBuffer){ Preconditions.checkNotNull(principalKeyBuffer, "principal key bytebuffer cannot be null"); Clause inPrincipal = QueryBuilder.eq("key", principalKeyBuffer); Statement statement = QueryBuilder .select() .column("column1") .from(PRINCIPAL_TOKENS_TABLE) .where(inPrincipal); final List<Row> rows = session.execute(statement).all(); final List<UUID> tokenUUIDs = new ArrayList<>(rows.size()); rows.forEach(row -> tokenUUIDs.add(row.getUUID("column1"))); logger.trace("getTokensForPrincipal, token UUIDs: {}", tokenUUIDs); return tokenUUIDs; }
/** @jira_ticket JAVA-1312 */ @Test(groups = "unit") public void should_not_append_last_column_twice() throws Exception { Select.SelectionOrAlias select = select().column("a").column("b"); Select fromUsers1 = select.from("users"); Select fromUsers2 = select.from("users"); assertThat(fromUsers1.getQueryString()) .isEqualTo(fromUsers2.getQueryString()) .isEqualTo("SELECT a,b FROM users;"); }
/** * @test_category queries:builder * @jira_ticket JAVA-1286 * @jira_ticket CASSANDRA-7423 */ @Test(groups = "unit") public void should_handle_retrieving_udt_fields() throws Exception { assertThat(select().path("a", Metadata.quote("B")).raw("c.\"D\"").from("tbl").getQueryString()) .isEqualTo("SELECT a.\"B\",c.\"D\" FROM tbl;"); }
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)); }
boolean initializeCompactStorage() throws PermanentBackendException { try { final ResultSet versionResultSet = this.session.execute( select().column("release_version").from("system", "local") ); final String version = versionResultSet.one().getString(0); final int major = Integer.parseInt(version.substring(0, version.indexOf("."))); // starting with Cassandra 3 COMPACT STORAGE is deprecated and has no impact return (major < 3); } catch (NumberFormatException | NoHostAvailableException | QueryExecutionException | QueryValidationException e) { throw new PermanentBackendException("Error determining Cassandra version", e); } }
/** * Returns a select statement builder for a {@link TableDDL} with the columns ordered in the order set by * {@link #ROW_KEY_RESULT_SET_COLUMN}, {@link #CHANGE_ID_RESULT_SET_COLUMN}, and {@link #VALUE_RESULT_SET_COLUMN}. */ private Select selectFrom(TableDDL tableDDL) { return QueryBuilder.select() .column(tableDDL.getRowKeyColumnName()) // ROW_KEY_RESULT_SET_COLUMN .column(tableDDL.getChangeIdColumnName()) // CHANGE_ID_RESULT_SET_COLUMN .column(tableDDL.getValueColumnName()) // VALUE_RESULT_SET_COLUMN .from(tableDDL.getTableMetadata()); }
/** * Returns a select statement builder for a {@link TableDDL} with the columns ordered in the order set by * {@link #ROW_KEY_RESULT_SET_COLUMN}, {@link #CHANGE_ID_RESULT_SET_COLUMN}, and {@link #VALUE_RESULT_SET_COLUMN}. */ private Select selectFrom(TableDDL tableDDL) { return QueryBuilder.select() .column(tableDDL.getRowKeyColumnName()) // ROW_KEY_RESULT_SET_COLUMN .column(tableDDL.getChangeIdColumnName()) // CHANGE_ID_RESULT_SET_COLUMN .column(tableDDL.getValueColumnName()) // VALUE_RESULT_SET_COLUMN .from(tableDDL.getTableMetadata()); }
/** * Returns a select statement builder for a {@link TableDDL} with the columns ordered in the order set by * {@link #ROW_KEY_RESULT_SET_COLUMN}, {@link #CHANGE_ID_RESULT_SET_COLUMN}, and {@link #VALUE_RESULT_SET_COLUMN}. */ private Select selectFrom(TableDDL tableDDL) { return QueryBuilder.select() .column(tableDDL.getRowKeyColumnName()) // ROW_KEY_RESULT_SET_COLUMN .column(tableDDL.getChangeIdColumnName()) // CHANGE_ID_RESULT_SET_COLUMN .column(tableDDL.getValueColumnName()) // VALUE_RESULT_SET_COLUMN .from(tableDDL.getTableMetadata()); }
/** * @test_category queries:builder * @jira_ticket JAVA-1286 * @jira_ticket CASSANDRA-7423 */ @Test(groups = "unit") public void should_handle_retrieving_udt_fields() throws Exception { assertThat(select().path("a", Metadata.quote("B")).raw("c.\"D\"").from("tbl").getQueryString()) .isEqualTo("SELECT a.\"B\",c.\"D\" FROM tbl;"); }
private Select selectDeltaFrom(BlockedDeltaTableDDL tableDDL) { return QueryBuilder.select() .column(tableDDL.getRowKeyColumnName()) // ROW_KEY_RESULT_SET_COLUMN .column(tableDDL.getChangeIdColumnName()) // CHANGE_ID_RESULT_SET_COLUMN .column(tableDDL.getValueColumnName()) // VALUE_RESULT_SET_COLUMN .column(tableDDL.getBlockColumnName()) // BLOCK_ID_RESULT_SET COLUMN .from(tableDDL.getTableMetadata()); }
/** * Returns a select statement builder for a {@link TableDDL} with the columns ordered in the order set by * {@link #ROW_KEY_RESULT_SET_COLUMN}, {@link #CHANGE_ID_RESULT_SET_COLUMN}, and {@link #VALUE_RESULT_SET_COLUMN}. */ private Select selectFrom(TableDDL tableDDL) { return QueryBuilder.select() .column(tableDDL.getRowKeyColumnName()) // ROW_KEY_RESULT_SET_COLUMN .column(tableDDL.getChangeIdColumnName()) // CHANGE_ID_RESULT_SET_COLUMN .column(tableDDL.getValueColumnName()) // VALUE_RESULT_SET_COLUMN .from(tableDDL.getTableMetadata()); }
/** @jira_ticket JAVA-1312 */ @Test(groups = "unit") public void should_not_append_last_column_twice() throws Exception { Select.SelectionOrAlias select = select().column("a").column("b"); Select fromUsers1 = select.from("users"); Select fromUsers2 = select.from("users"); assertThat(fromUsers1.getQueryString()) .isEqualTo(fromUsers2.getQueryString()) .isEqualTo("SELECT a,b FROM users;"); }
private ImmutableList<BuiltStatement> idempotentBuiltStatements() { return ImmutableList.<BuiltStatement>of( update("foo").with(set("v", 1)).where(eq("k", 1)), // set simple value update("foo").with(add("s", 1)).where(eq("k", 1)), // add to set update("foo").with(put("m", "a", 1)).where(eq("k", 1)), // put in map // select statements should be idempotent even with function calls select().countAll().from("foo").where(eq("k", 1)), select().ttl("v").from("foo").where(eq("k", 1)), select().writeTime("v").from("foo").where(eq("k", 1)), select().fcall("token", "k").from("foo").where(eq("k", 1))); }
.as("clustering1") .max("c") .from(table) .where(eq("a", 1)) .groupBy("a", "clustering1")); .column("b") .max("c") .from(table) .where(eq("a", 1)) .groupBy("a", "b", "z")); session().execute(select().column("a").column("b").max("d").from(table).groupBy("a")); fail("Expecting IQE"); } catch (InvalidQueryException e) {
select = select().writeTime("a").ttl("a").from("foo").allowFiltering(); assertEquals(select.toString(), query); select = select().fcall("intToBlob", column("b")).from("foo"); assertEquals(select.toString(), query); select() .cast(fcall("writetime", column("country")), DataType.text()) .from("artists") .limit(2); assertEquals(select.toString(), query); select = select().fcall("avg", cast(column("v"), DataType.cfloat())).from("e"); assertEquals(select.toString(), query); select = select().raw("CAST(writetime(country) AS text)").from("artists").limit(2); assertEquals(select.toString(), query);
.as("fint") .column("i") .from(TABLE2) .where(eq("k", "cast_t")));
select = select().fcall("* FROM bar; --", column("b")).from("foo"); assertEquals(select.toString(), query); select = select().writeTime("a) FROM bar; --").ttl("a").from("foo").allowFiltering(); assertEquals(select.toString(), query); select = select().writeTime("a").ttl("a) FROM bar; --").from("foo").allowFiltering(); assertEquals(select.toString(), query);
.execute(select().path("u", "first").raw("u.last").from(table).where(eq("k", "key"))) .one();
@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 ImmutableList<BuiltStatement> idempotentBuiltStatements() { return ImmutableList.<BuiltStatement>of( update("foo").with(set("v", 1)).where(eq("k", 1)), // set simple value update("foo").with(add("s", 1)).where(eq("k", 1)), // add to set update("foo").with(put("m", "a", 1)).where(eq("k", 1)), // put in map // select statements should be idempotent even with function calls select().countAll().from("foo").where(eq("k", 1)), select().ttl("v").from("foo").where(eq("k", 1)), select().writeTime("v").from("foo").where(eq("k", 1)), select().fcall("token", "k").from("foo").where(eq("k", 1))); }