@Override protected Number executeCountQuery(Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) { if (!whereItems.isEmpty()) { // not supported - will have to be done by counting client-side logger.debug( "Not able to execute count query natively - resorting to query post-processing, which may be expensive"); return null; } final Statement statement = QueryBuilder.select().countAll().from(keySpaceName, table.getName()); final Row response = cassandraCluster.connect().execute(statement).one(); return response.getLong(0); }
private Statement createQueryToCheckIfMessageExists(String applicationId, String messageId) { UUID msgId = UUID.fromString(messageId); UUID appId = UUID.fromString(applicationId); return queryBuilder .select() .countAll() .from(Messages.TABLE_NAME) .where(eq(APP_ID, appId)) .and(eq(MESSAGE_ID, msgId)); }
@Override public long count(Class<?> entityClass) { Assert.notNull(entityClass, "Entity type must not be null"); Select select = QueryBuilder.select().countAll().from(getTableName(entityClass).toCql()); Long count = getCqlOperations().queryForObject(select, Long.class); return count != null ? count : 0L; }
public static Select selectCountAllFrom(CassandraTableHandle tableHandle) { String schema = validSchemaName(tableHandle.getSchemaName()); String table = validTableName(tableHandle.getTableName()); return QueryBuilder.select().countAll().from(schema, table); }
public static Select selectCountAllFrom(CassandraTableHandle tableHandle) { String schema = validSchemaName(tableHandle.getSchemaName()); String table = validTableName(tableHandle.getTableName()); return QueryBuilder.select().countAll().from(schema, table); }
private Statement createStatementToCheckIfFollowingExists(String userId, String applicationId) { UUID appUuid = UUID.fromString(applicationId); UUID userUuid = UUID.fromString(userId); return queryBuilder.select() .countAll() .from(Follow.TABLE_NAME_APP_FOLLOWERS) .where(eq(USER_ID, userUuid)) .and(eq(APP_ID, appUuid)); }
private Statement createQueryToCountMessagesFor(String userId) { UUID userUuid = UUID.fromString(userId); return QueryBuilder .select() .countAll() .from(Inbox.TABLE_NAME) .where(eq(Inbox.USER_ID, userUuid)); }
private Statement createQueryToCheckIfExists(String userId) { UUID userUuid = UUID.fromString(userId); return queryBuilder .select() .countAll() .from(Credentials.TABLE_NAME) .where(eq(Credentials.USER_ID, userUuid)); }
private Statement createQueryToCountMessagesByApplication(String applicationId) { UUID appId = UUID.fromString(applicationId); return QueryBuilder .select() .countAll() .from(Messages.TABLE_NAME) .where(eq(APP_ID, appId)); }
private Statement createQueryToCheckIfMessageExists(String applicationId, String messageId) { UUID msgId = UUID.fromString(messageId); UUID appId = UUID.fromString(applicationId); return QueryBuilder .select() .countAll() .from(Messages.TABLE_NAME) .where(eq(APP_ID, appId)) .and(eq(MESSAGE_ID, msgId)); }
private Statement createQueryToSeeIfMemberOfOrg(String organizationId, String userId) { UUID orgUuid = UUID.fromString(organizationId); UUID userUuid = UUID.fromString(userId); return queryBuilder .select() .countAll() .from(Organizations.TABLE_NAME_MEMBERS) .where(eq(ORG_ID, orgUuid)) .and(eq(USER_ID, userUuid)); }
private Statement createStatementToCheckIfFollowingExists(String userId, String applicationId) { UUID appUuid = UUID.fromString(applicationId); UUID userUuid = UUID.fromString(userId); return QueryBuilder .select() .countAll() .from(Follow.TABLE_NAME_APP_FOLLOWERS) .where(eq(USER_ID, userUuid)) .and(eq(APP_ID, appUuid)); }
@Override public ListenableFuture<Long> count(Class<?> entityClass) { Assert.notNull(entityClass, "Entity type must not be null"); Select select = QueryBuilder.select().countAll().from(getTableName(entityClass).toCql()); return getAsyncCqlOperations().queryForObject(select, Long.class); }
private Statement createQueryToCheckIfAppIdExists(String applicationId) { UUID appId = UUID.fromString(applicationId); return QueryBuilder .select() .countAll() .from(TABLE_NAME) .where(eq(APP_ID, appId)); }
private Statement createQueryToCheckIfOrgExists(String organizationId) { UUID orgUuid = UUID.fromString(organizationId); return queryBuilder .select() .countAll() .from(Organizations.TABLE_NAME) .where(eq(ORG_ID, orgUuid)); }
private Statement createStatementToCheckIfExists(String tokenId) { UUID tokenUuid = UUID.fromString(tokenId); return queryBuilder .select() .countAll() .from(Tokens.TABLE_NAME) .where(eq(TOKEN_ID, tokenUuid)); }
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))); }
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))); }
public static Select selectCountAllFrom(CassandraTableHandle tableHandle) { String schema = validSchemaName(tableHandle.getSchemaName()); String table = validTableName(tableHandle.getTableName()); return QueryBuilder.select().countAll().from(schema, table); }