creates a scan for flow data
@param rowPrefix - start row prefix
@param limit - limit on scanned results
@param version - version to match
@return Scan
2640
private Scan createFlowScan(byte[] rowPrefix, int limit, String version) {
    Scan scan = new Scan();
    scan.setStartRow(rowPrefix);

    // using a large scanner caching value with a small limit can mean we scan a
    // lot more data than necessary, so lower the caching for low limits
    scan.setCaching(Math.min(limit, defaultScannerCaching));
    // require that all rows match the prefix we're looking for
    Filter prefixFilter = new WhileMatchFilter(new PrefixFilter(rowPrefix));
    // if version is passed, restrict the rows returned to that version
    if (version != null && version.length() > 0) {
      FilterList filters = new FilterList(FilterList.Operator.MUST_PASS_ALL);
      filters.addFilter(prefixFilter);
      filters.addFilter(new SingleColumnValueFilter(Constants.INFO_FAM_BYTES,
          Constants.VERSION_COLUMN_BYTES, CompareFilter.CompareOp.EQUAL,
          Bytes.toBytes(version)));
      scan.setFilter(filters);
    } else {
      scan.setFilter(prefixFilter);
    }
    return scan;
  }
448597
public static MapReduceSpecification<Long, Integer, Integer, ArrayList<Integer>,
      GoogleCloudStorageFileSet> createMapReduceSpec(String bucket, long start, long limit,
          int shards) {
    ConsecutiveLongInput input = new ConsecutiveLongInput(start, limit, shards);
    Mapper<Long, Integer, Integer> mapper = new SeedToRandomMapper();
    Marshaller<Integer> intermediateKeyMarshaller = Marshallers.getIntegerMarshaller();
    Marshaller<Integer> intermediateValueMarshaller = Marshallers.getIntegerMarshaller();
    Reducer<Integer, Integer, ArrayList<Integer>> reducer = new CollisionFindingReducer();
    Marshaller<ArrayList<Integer>> outputMarshaller = Marshallers.getSerializationMarshaller();

    Output<ArrayList<Integer>, GoogleCloudStorageFileSet> output = new MarshallingOutput<>(
        new GoogleCloudStorageFileOutput(bucket, "CollidingSeeds-%04d", "integers"),
        outputMarshaller);
    // [START mapReduceSpec]
    MapReduceSpecification<Long, Integer, Integer, ArrayList<Integer>, GoogleCloudStorageFileSet>
        spec = new MapReduceSpecification.Builder<>(input, mapper, reducer, output)
            .setKeyMarshaller(intermediateKeyMarshaller)
            .setValueMarshaller(intermediateValueMarshaller)
            .setJobName("DemoMapreduce")
            .setNumReducers(shards)
            .build();
    // [END mapReduceSpec]
    return spec;
  }
623414
private Iterable<MultiTableScanResult> scanMultiTableRows(
            final TableSet tables, final DeltaPlacement placement, final ByteBufferRange rowRange,
            final LimitCounter limit, final boolean includeDroppedTables, final boolean includeMirrorTables,
            final ReadConsistency consistency, final Instant cutoffTime) {

        // Avoiding pinning multiple decoded rows into memory at once.
        return () -> limit.limit(new AbstractIterator<MultiTableScanResult>() {
            private PeekingIterator<Iterable<Row>> _iter = Iterators.peekingIterator(
                    rowScan(placement, null, rowRange, consistency));

            private long _lastTableUuid = -1;
            private AstyanaxTable _table = null;
            private boolean _droppedTable;
            private boolean _primaryTable;

            @Override
            protected MultiTableScanResult computeNext() {
                while (_iter.hasNext()) {
                    // Get the next rows from the grouping iterator.  All rows in the returned Iterable
                    // are from the same Cassandra wide row (in other words, they share the same key).
                    final Iterable<Row> rows = _iter.next();

                    // filter the rows if a cutOff time is specified.
                    Iterable<Row> filteredRows = rows;
                    if (cutoffTime != null) {
                        filteredRows = getFilteredRows(rows, cutoffTime);
                    }

                    // Convert the filteredRows into a Record object
                    ByteBuffer rowKey = getRawKeyFromRowGroupOrNull(filteredRows);
                    // rowKey can be null if "all" the rows of the cassandra record are after the cutoff time. In such case ignore that record and continue.
                    if (rowKey == null) {
                        continue;
                    }

                    long tableUuid = AstyanaxStorage.getTableUuid(rowKey);
                    if (_lastTableUuid != tableUuid) {
                        _lastTableUuid = tableUuid;
                        try {
                            _table = (AstyanaxTable) tables.getByUuid(tableUuid);
                        } catch (UnknownTableException e) {
                            _table = AstyanaxTable.createUnknown(tableUuid, placement, e.getTable());
                        } catch (DroppedTableException e) {
                            _table = AstyanaxTable.createUnknown(tableUuid, placement, e.getPriorTable());
                        }
                        _droppedTable = _table.isUnknownTable();
                        _primaryTable = _table.getReadStorage().hasUUID(tableUuid);
                    }

                    // Skip dropped and mirror tables if configured
                    if ((!includeDroppedTables && _droppedTable) || (!includeMirrorTables && !_primaryTable)) {
                        _iter = skipToNextTable(tableUuid);
                        continue;
                    }

                    int shardId = AstyanaxStorage.getShardId(rowKey);
                    String key = AstyanaxStorage.getContentKey(rowKey);
                    Record record = newRecordFromCql(new Key(_table, key), filteredRows);
                    return new MultiTableScanResult(rowKey, shardId, tableUuid, _droppedTable, record);
                }

                return endOfData();
            }

            private PeekingIterator<Iterable<Row>> skipToNextTable(long tableUuid) {
                // Iterate over the next 10 row groups first to check for a table switch.  This avoids starting a new range
                // query if the number of rows in the undesired table is small.
                int skipLimit = 10;
                Iterable<Row> rowGroup = null;

                while (skipLimit != 0 && _iter.hasNext()) {
                    rowGroup = _iter.peek();
                    ByteBuffer rawKey = getRawKeyFromRowGroup(rowGroup);
                    long nextTableUuid = AstyanaxStorage.getTableUuid(rawKey);
                    if (nextTableUuid != tableUuid) {
                        // This is the first row of a new table
                        return _iter;
                    } else {
                        _iter.next();
                        skipLimit -= 1;
                    }
                }

                if (_iter.hasNext()) {
                    // Skip the table entirely by starting a new query on the next possible table
                    assert rowGroup != null;
                    int shardId = AstyanaxStorage.getShardId(getRawKeyFromRowGroup(rowGroup));
                    ByteBuffer nextPossibleTableStart = AstyanaxStorage.getRowKeyRaw(shardId, tableUuid + 1, "");
                    ByteBuffer end = rowRange.getEnd();

                    if (AstyanaxStorage.compareKeys(nextPossibleTableStart, end) < 0) {
                        // We haven't reached the last end boundary of the original range scan
                        ByteBufferRange updatedRange = new ByteBufferRangeImpl(nextPossibleTableStart, end, -1, false);
                        return Iterators.peekingIterator(rowScan(placement, null, updatedRange, consistency));
                    }
                }

                return Iterators.peekingIterator(Iterators.<Iterable<Row>>emptyIterator());
            }
        });
    }
642437
public List<HdfsStats> getAllDirs(String cluster, String pathPrefix,
      int limit, long runId) throws IOException {
    long encodedRunId = getEncodedRunId(runId);
    String rowPrefixStr =
        Long.toString(encodedRunId) + HdfsConstants.SEP + cluster;
    if (StringUtils.isNotEmpty(pathPrefix)) {
      // path expected to be cleansed at collection/storage time as well
      rowPrefixStr += HdfsConstants.SEP + StringUtil.cleanseToken(pathPrefix);
    }
    LOG.info(" Getting all dirs for cluster " + cluster + " with pathPrefix: "
        + pathPrefix + " for runId " + runId + " encodedRunId: " + encodedRunId
        + " limit: " + limit + " row prefix : " + rowPrefixStr);
    byte[] rowPrefix = Bytes.toBytes(rowPrefixStr);
    Scan scan = createScanWithAllColumns();
    scan.setStartRow(rowPrefix);

    // require that all rows match the prefix we're looking for
    Filter prefixFilter = new WhileMatchFilter(new PrefixFilter(rowPrefix));
    scan.setFilter(prefixFilter);
    // using a large scanner caching value with a small limit can mean we scan a
    // lot more data than
    // necessary, so lower the caching for low limits
    scan.setCaching(Math.min(limit, defaultScannerCaching));
    // we need only the latest cell version
    scan.setMaxVersions(1);

    return createFromScanResults(cluster, null, scan, limit, Boolean.FALSE, 0l,
        0l);

  }
1266516
public int getRowStart(int rowIndex) {
        if (isCompacted) {
            throw new IllegalStateException(
                    "Illegal Invocation of the method after compact()");
        }
        if (rowIndex < 0 || rowIndex > rows) {
            throw new IllegalArgumentException("rowIndex out of bound!");
        }
        return v[rowIndex * columns];
    }
1108201
@Override
    public Iterator<Map<String, Object>> scan(String tableName, @Nullable String fromKeyExclusive,
                                              LimitCounter limit, ReadConsistency consistency) {
        return scan(tableName, fromKeyExclusive, limit, false, consistency);
    }
662029
protected MappedPreparedStmt<T, ID> prepareStatement(Long limit, boolean cacheStore) throws SQLException {
		List<ArgumentHolder> argList = new ArrayList<ArgumentHolder>();
		String statement = buildStatementString(argList);
		ArgumentHolder[] selectArgs = argList.toArray(new ArgumentHolder[argList.size()]);
		FieldType[] resultFieldTypes = getResultFieldTypes();
		FieldType[] argFieldTypes = new FieldType[argList.size()];
		for (int selectC = 0; selectC < selectArgs.length; selectC++) {
			argFieldTypes[selectC] = selectArgs[selectC].getFieldType();
		}
		if (!type.isOkForStatementBuilder()) {
			throw new IllegalStateException("Building a statement from a " + type + " statement is not allowed");
		}
		return new MappedPreparedStmt<T, ID>(dao, tableInfo, statement, argFieldTypes, resultFieldTypes, selectArgs,
				(databaseType.isLimitSqlSupported() ? null : limit), type, cacheStore);
	}
1017116
private Where addWhereClauseForRowRange(String keyAlias, Select select, RowRange<?> rowRange) {

		Where where = null;

		boolean keyIsPresent = false;
		boolean tokenIsPresent = false; 

		if (rowRange.getStartKey() != null || rowRange.getEndKey() != null) {
			keyIsPresent = true;
		}
		if (rowRange.getStartToken() != null || rowRange.getEndToken() != null) {
			tokenIsPresent = true;
		}

		if (keyIsPresent && tokenIsPresent) {
			throw new RuntimeException("Cannot provide both token and keys for range query");
		}
		
		if (keyIsPresent) {
			if (rowRange.getStartKey() != null && rowRange.getEndKey() != null) {

				where = select.where(gte(keyAlias, BIND_MARKER))
						.and(lte(keyAlias, BIND_MARKER));

			} else if (rowRange.getStartKey() != null) {				
				where = select.where(gte(keyAlias, BIND_MARKER));

			} else if (rowRange.getEndKey() != null) {
				where = select.where(lte(keyAlias, BIND_MARKER));
			}

		} else if (tokenIsPresent) {
			String tokenOfKey ="token(" + keyAlias + ")";

			if (rowRange.getStartToken() != null && rowRange.getEndToken() != null) {

				where = select.where(gte(tokenOfKey, BIND_MARKER))
						.and(lte(tokenOfKey, BIND_MARKER));

			} else if (rowRange.getStartToken() != null) {
				where = select.where(gte(tokenOfKey, BIND_MARKER));

			} else if (rowRange.getEndToken() != null) {
				where = select.where(lte(tokenOfKey, BIND_MARKER));
			}
		} else { 
			where = select.where();
		}

		if (rowRange.getCount() > 0) {
			// TODO: fix this
			//where.limit(rowRange.getCount());
		}
		return where; 
	}
1096777
def prefix(rowPrefix):
        """"""
        fp = Range.followingPrefix(rowPrefix)
        return Range(srow=rowPrefix, sinclude=True, erow=fp, einclude=False)
212041
private String limitString(int rowIndex){

        if(params.length != 2){
            throw new IllegalArgumentException("Wrong number of Parameters for limit string expression");
        }

        final RecordList.Record currentRecord = recordList.getRecords().get(rowIndex);
        final String field = currentRecord.getValueByFieldName(params[0]);
        int limit = Integer.parseInt(params[1]);

        if (field.isEmpty() || field.length() < limit){
            return field;
        }

        String result = field.substring(0, limit) + "...";
        return result;
    }
1047402
public void throwIfUnsupportedScan(Scan scan) {
    if (scan.getFilter() != null) {
      filterAdapter.throwIfUnsupportedFilter(scan, scan.getFilter());
    }

    if (scan.getMaxResultsPerColumnFamily() != UNSET_MAX_RESULTS_PER_COLUMN_FAMILY) {
      throw new UnsupportedOperationException(
          "Limiting of max results per column family is not supported.");
    }
  }
517581
public AddressbookQuery limitNumberOfResults(int limit)
	{
		if (limit > 0)
		{
			addLimit(WebDavSearch.NRESULTS, limit);
		}
		else
		{
			removeLimit(WebDavSearch.NRESULTS);
		}
		return this;
	}
62725
public static TableKey versioned(@NonNull ArrayView key, long version) {
        Preconditions.checkArgument(version >= 0 || version == NOT_EXISTS || version == NO_VERSION, "Version must be a non-negative number.");
        return new TableKey(key, version);
    }
332797
public static ExtensionId toExtensionId(String groupId, String artifactId, String classifier, String version)
    {
        return toExtensionId(groupId, artifactId, classifier, version != null ? new DefaultVersion(version) : null);
    }
228911
@Nullable
  public ScanQuery toScanQuery()
  {
    if (grouping != null) {
      // Scan cannot GROUP BY.
      return null;
    }
    if (limitSpec != null &&
        (limitSpec.getColumns().size() > 1
         || (limitSpec.getColumns().size() == 1 && !Iterables.getOnlyElement(limitSpec.getColumns())
                                                             .getDimension()
                                                             .equals(ColumnHolder.TIME_COLUMN_NAME)))) {
      // Scan cannot ORDER BY non-time columns.
      return null;
    }

    if (outputRowSignature.getRowOrder().isEmpty()) {
      // Should never do a scan query without any columns that we're interested in. This is probably a planner bug.
      throw new ISE("WTF?! Attempting to convert to Scan query without any columns?");
    }

    final Filtration filtration = Filtration.create(filter).optimize(sourceQuerySignature);

    // DefaultLimitSpec (which we use to "remember" limits) is int typed, and Integer.MAX_VALUE means "no limit".
    final long scanLimit = limitSpec == null || limitSpec.getLimit() == Integer.MAX_VALUE
                           ? 0L
                           : (long) limitSpec.getLimit();

    ScanQuery.Order order;
    if (limitSpec == null || limitSpec.getColumns().size() == 0) {
      order = ScanQuery.Order.NONE;
    } else if (limitSpec.getColumns().get(0).getDirection() == OrderByColumnSpec.Direction.ASCENDING) {
      order = ScanQuery.Order.ASCENDING;
    } else {
      order = ScanQuery.Order.DESCENDING;
    }

    return new ScanQuery(
        dataSource,
        filtration.getQuerySegmentSpec(),
        getVirtualColumns(true),
        ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST,
        0,
        scanLimit,
        order, // Will default to "none"
        filtration.getDimFilter(),
        Ordering.natural().sortedCopy(ImmutableSet.copyOf(outputRowSignature.getRowOrder())),
        false,
        ImmutableSortedMap.copyOf(plannerContext.getQueryContext())
    );
  }
443068
public static boolean match(Version version, String begin, String end) {
        E.checkArgumentNotNull(version, "The version to match is null");
        return version.compareTo(new Version(begin)) >= 0 &&
               version.compareTo(new Version(end)) < 0;
    }
349508
function createQueryWithLimit() {
            // We query only limit number in case of big table
            // If we query with more than million data query will hang up
            const query = _this.initQuery(namespace);
            if (ancestors) {
                query.hasAncestor(_this.gstore.ds.key(ancestors.slice()));
            }
            query.select('__key__');
            query.limit(limitDataPerQuery);

            return query;
        }