public void checkAccess(ClientState state) throws InvalidRequestException, UnauthorizedException { state.hasColumnFamilyAccess(keyspace(), columnFamily(), Permission.SELECT); }
static SelectStatement forSelection(CFMetaData cfm, Selection selection) { return new SelectStatement(cfm, 0, defaultParameters, selection, null); }
public ResultMessage.Rows executeInternal(QueryState state, QueryOptions options) throws RequestExecutionException, RequestValidationException { return executeInternal(state, options, System.currentTimeMillis()); }
private RangeSliceCommand getRangeCommand(QueryOptions options, int limit, long now) throws RequestValidationException { IDiskAtomFilter filter = makeFilter(options, limit); if (filter == null) return null; List<IndexExpression> expressions = getValidatedIndexExpressions(options); // The LIMIT provided by the user is the number of CQL row he wants returned. // We want to have getRangeSlice to count the number of columns, not the number of keys. AbstractBounds<RowPosition> keyBounds = getKeyBounds(options); return keyBounds == null ? null : new RangeSliceCommand(keyspace(), columnFamily(), now, filter, keyBounds, expressions, limit, !parameters.isDistinct, false); }
private Pageable getPageableCommand(QueryOptions options, int limit, long now) throws RequestValidationException { if (isNotReturningAnyRows(options)) return null; int limitForQuery = updateLimitForQuery(limit); if (isKeyRange || usesSecondaryIndexing) return getRangeCommand(options, limitForQuery, now); List<ReadCommand> commands = getSliceCommands(options, limitForQuery, now); return commands == null ? null : new Pageable.ReadCommands(commands, limitForQuery); }
public ResultMessage.Rows execute(QueryState state, QueryOptions options, long queryStartNanoTime) throws RequestExecutionException, RequestValidationException { ConsistencyLevel cl = options.getConsistency(); checkNotNull(cl, "Invalid empty consistency level"); cl.validateForRead(keyspace()); int nowInSec = FBUtilities.nowInSeconds(); int userLimit = getLimit(options); int userPerPartitionLimit = getPerPartitionLimit(options); int pageSize = options.getPageSize(); ReadQuery query = getQuery(options, nowInSec, userLimit, userPerPartitionLimit, pageSize); if (aggregationSpec == null && (pageSize <= 0 || (query.limits().count() <= pageSize))) return execute(query, options, state, nowInSec, userLimit, queryStartNanoTime); QueryPager pager = getPager(query, options); return execute(Pager.forDistributedQuery(pager, cl, state.getClientState()), options, pageSize, nowInSec, userLimit, queryStartNanoTime); }
public ResultMessage.Rows executeInternal(QueryState state, QueryOptions options, int nowInSec, long queryStartNanoTime) throws RequestExecutionException, RequestValidationException { int userLimit = getLimit(options); int userPerPartitionLimit = getPerPartitionLimit(options); int pageSize = options.getPageSize(); ReadQuery query = getQuery(options, nowInSec, userLimit, userPerPartitionLimit, pageSize); try (ReadExecutionController executionController = query.executionController()) { if (aggregationSpec == null && (pageSize <= 0 || (query.limits().count() <= pageSize))) { try (PartitionIterator data = query.executeInternal(executionController)) { return processResults(data, options, nowInSec, userLimit); } } else { QueryPager pager = getPager(query, options); return execute(Pager.forInternalQuery(pager, executionController), options, pageSize, nowInSec, userLimit, queryStartNanoTime); } } }
throw new InvalidRequestException("Invalid empty consistency level"); cl.validateForRead(keyspace()); int limit = getLimit(options); long now = System.currentTimeMillis(); Pageable command = getPageableCommand(options, limit, now); return execute(command, options, limit, now, state); return pageCountQuery(pager, options, pageSize, now, limit); if (needsPostQueryOrdering()) throw new InvalidRequestException("Cannot page queries with both ORDER BY and a IN restriction on the partition key; you must either remove the " + "ORDER BY or the IN and sort client side, or disable paging for this query"); ResultMessage.Rows msg = processResults(page, options, limit, now);
public void checkAccess(ClientState state) throws InvalidRequestException, UnauthorizedException { if (cfm.isView()) { CFMetaData baseTable = View.findBaseTable(keyspace(), columnFamily()); if (baseTable != null) state.hasColumnFamilyAccess(baseTable, Permission.SELECT); } else { state.hasColumnFamilyAccess(cfm, Permission.SELECT); } for (Function function : getFunctions()) state.ensureHasPermission(Permission.EXECUTE, function); }
public ResultMessage.Rows executeInternal(QueryState state, QueryOptions options, long now) throws RequestExecutionException, RequestValidationException int limit = getLimit(options); Pageable command = getPageableCommand(options, limit, now); ? Collections.<Row>emptyList() : (command instanceof Pageable.ReadCommands ? readLocally(keyspace(), ((Pageable.ReadCommands)command).commands) : ((RangeSliceCommand)command).executeLocally()); return processResults(rows, options, limit, now); return pageCountQuery(pager, options, pageSize, now, limit); if (needsPostQueryOrdering()) throw new InvalidRequestException("Cannot page queries with both ORDER BY and a IN restriction on the partition key; you must either remove the " + "ORDER BY or the IN and sort client side, or disable paging for this query"); ResultMessage.Rows msg = processResults(page, options, limit, now);
private ResultMessage.Rows pageCountQuery(QueryPager pager, QueryOptions options, int pageSize, long now, int limit) throws RequestValidationException, RequestExecutionException { int count = 0; while (!pager.isExhausted()) { int maxLimit = pager.maxRemaining(); logger.debug("New maxLimit for paged count query is {}", maxLimit); ResultSet rset = process(pager.fetchPage(pageSize), options, maxLimit, now); count += rset.rows.size(); } // We sometimes query one more result than the user limit asks to handle exclusive bounds with compact tables (see updateLimitForQuery). // So do make sure the count is not greater than what the user asked for. ResultSet result = ResultSet.makeCountResult(keyspace(), columnFamily(), Math.min(count, limit), parameters.countAlias); return new ResultMessage.Rows(result); }
public ReadQuery getQuery(QueryOptions options, int nowInSec, int userLimit, int perPartitionLimit, int pageSize) { boolean isPartitionRangeQuery = restrictions.isKeyRange() || restrictions.usesSecondaryIndexing(); DataLimits limit = getDataLimits(userLimit, perPartitionLimit, pageSize); if (isPartitionRangeQuery) return getRangeCommand(options, limit, nowInSec); return getSliceCommands(options, limit, nowInSec); }
public ReadQuery getQuery(QueryOptions options, int nowInSec) throws RequestValidationException { return getQuery(options, nowInSec, getLimit(options), getPerPartitionLimit(options), options.getPageSize()); }
ByteBuffer[] keyComponents = getComponents(cfm, partition.partitionKey()); if (!staticRow.isEmpty() && (queriesFullPartitions() || cfm.isStaticCompactTable())) break; case STATIC: addValue(result, def, staticRow, nowInSec, protocolVersion); break; default: break; case REGULAR: addValue(result, def, row, nowInSec, protocolVersion); break; case STATIC: addValue(result, def, staticRow, nowInSec, protocolVersion); break;
private List<ReadCommand> getSliceCommands(QueryOptions options, int limit, long now) throws RequestValidationException { Collection<ByteBuffer> keys = getKeys(options); if (keys.isEmpty()) // in case of IN () for (the last column of) the partition key. return null; List<ReadCommand> commands = new ArrayList<>(keys.size()); IDiskAtomFilter filter = makeFilter(options, limit); if (filter == null) return null; // Note that we use the total limit for every key, which is potentially inefficient. // However, IN + LIMIT is not a very sensible choice. for (ByteBuffer key : keys) { QueryProcessor.validateKey(key); // We should not share the slice filter amongst the commands (hence the cloneShallow), due to // SliceQueryFilter not being immutable due to its columnCounter used by the lastCounted() method // (this is fairly ugly and we should change that but that's probably not a tiny refactor to do that cleanly) commands.add(ReadCommand.create(keyspace(), ByteBufferUtil.clone(key), columnFamily(), now, filter.cloneShallow())); } return commands; }
private Role getRoleFromTable(String name, SelectStatement statement, Function<UntypedResultSet.Row, Role> function) throws RequestExecutionException, RequestValidationException { ResultMessage.Rows rows = statement.execute(QueryState.forInternalCalls(), QueryOptions.forInternalCalls(consistencyForRole(name), Collections.singletonList(ByteBufferUtil.bytes(name))), System.nanoTime()); if (rows.result.isEmpty()) return NULL_ROLE; return function.apply(UntypedResultSet.create(rows.result).one()); }
ByteBuffer value = validateIndexedValue(def, slice.bound(b, options)); Operator op = slice.getIndexOperator(b); op = reverse(op); expressions.add(new IndexExpression(def.name.bytes, op, value)); for (ByteBuffer value : contains.values(options)) validateIndexedValue(def, value); expressions.add(new IndexExpression(def.name.bytes, Operator.CONTAINS, value)); validateIndexedValue(def, key); expressions.add(new IndexExpression(def.name.bytes, Operator.CONTAINS_KEY, key)); validateIndexedValue(def, value); expressions.add(new IndexExpression(def.name.bytes, Operator.EQ, value)); ColumnFamilyStore cfs = Keyspace.open(keyspace()).getColumnFamilyStore(columnFamily()); SecondaryIndexManager secondaryIndexManager = cfs.indexManager; secondaryIndexManager.validateIndexSearchersForQuery(expressions);
SelectStatement.forSelection(cfm, selection).processPartition(partition, options, builder,
private static ResultSet.ResultMetadata extractResultMetadata(CQLStatement statement) { if (!(statement instanceof SelectStatement)) return ResultSet.ResultMetadata.EMPTY; return ((SelectStatement)statement).getResultMetadata(); }