Private helper for constructing the bind values for the given row range. Note that the assumption here is that
we have a previously constructed prepared statement that we can bind these values with.

@param keyAlias
@param select
@param rowRange
@return
557144
private void bindWhereClauseForRowRange(List<Object> values, RowRange<?> rowRange) {

		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) {
				values.add(rowRange.getStartKey());
			}
			if (rowRange.getEndKey() != null) {
				values.add(rowRange.getEndKey());
			}

		} else if (tokenIsPresent) {

			BigInteger startTokenB = rowRange.getStartToken() != null ? new BigInteger(rowRange.getStartToken()) : null; 
			BigInteger endTokenB = rowRange.getEndToken() != null ? new BigInteger(rowRange.getEndToken()) : null; 

			Long startToken = startTokenB.longValue();
			Long endToken = endTokenB.longValue();
			
			if (startToken != null && endToken != null) {
				if (startToken != null) {
					values.add(startToken);
				}
				if (endToken != null) {
					values.add(endToken);
				}
			}

			if (rowRange.getCount() > 0) {
				// TODO: fix this
				//where.limit(rowRange.getCount());
			}
			return; 
		}
	}
824980
private int bindStatement(PreparedStatement stmt, int index, SelectionCriteria crit, ClassDescriptor cld) throws SQLException
    {
        return bindStatementValue(stmt, index, crit.getAttribute(), crit.getValue(), cld);
    }
508146
private void selectExpressions(ParserString raw, Select select) throws SQLParserException {
	Expression exp = null;
	do {
	    raw.removeSpace();

	    exp = expression(raw);
	    if (exp == null) throw new SQLParserException("missing expression in select part of query");
	    raw.removeSpace();
	    if (raw.forwardIfCurrent("as ")) {
		String alias = identifier(raw, new RefBooleanImpl(false));
		if (alias == null) throw new SQLParserException("missing alias in select part");
		exp.setAlias(alias);
	    }
	    else {
		int start = raw.getPos();
		RefBoolean hb = new RefBooleanImpl(false);
		String alias = identifier(raw, hb);
		if (!hb.toBooleanValue() && "from".equalsIgnoreCase(alias)) raw.setPos(start);
		else if (alias != null) exp.setAlias(alias);
	    }
	    select.addSelectExpression(exp);
	    raw.removeSpace();
	}
	while (raw.forwardIfCurrent(','));

    }
11028
public void bindArgument(@NotNull PreparedStatement ps, int index, @Nullable Object value) throws SQLException {
        ArgumentBinder.bindArgument(ps, index, value);
    }
116034
@Override
  public Collection<Range<T>> rangesOverlapping(final Range<T> queryRange) {
    final ImmutableSet.Builder<Range<T>> ret = ImmutableSet.builder();
    for (final Range<T> range : ranges) {
      if (range.isConnected(queryRange) && !range.intersection(queryRange).isEmpty()) {
        ret.add(range);
      }
    }
    return ret.build();
  }
1256866
@Override
  public UnsafeRow getKeyRow(int rowId) {
    assert(rowId >= 0);
    assert(rowId < numRows);
    if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached
      long offset = keyOffsets[rowId];
      int klen = Platform.getInt(base, offset - 4);
      keyRow.pointTo(base, offset, klen);
      // set keyRowId so we can check if desired row is cached
      keyRowId = rowId;
    }
    return keyRow;
  }
728119
public int execSelectCount(String preparedSql, Object[] searchKeys) {
    log("#execSelectCount preparedSql=" + preparedSql + " searchKeys=" + searchKeys);
    int retVal = 0;

    PreparedStatement preparedStmt = null;
    ResultSet rs = null;

    final Connection conn = createConnection();

    try {

      preparedStmt = conn.prepareStatement(preparedSql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

      final StringBuilder logSb = new StringBuilder();

      if (searchKeys != null) {
        logSb.append("/ ");
        for (int i = 0; i < searchKeys.length; i++) {

          setObject((i + 1), preparedStmt, searchKeys[i]);

          logSb.append("key(" + (i + 1) + ")=" + searchKeys[i]);
          logSb.append(" ");
        }
      }

      log("#execSelectCount SQL=" + preparedSql + " " + logSb.toString());

      // execute SQL
      rs = preparedStmt.executeQuery();

      while (rs.next()) {
        retVal = rs.getInt(1);
      }

    } catch (Exception e) {
      loge("#execSelectCount", e);

    } finally {
      try {
        if (rs != null) {
          rs.close();
        }
        if (preparedStmt != null) {
          preparedStmt.close();
        }
        if (conn != null) {
          conn.close();
        }
      } catch (SQLException e) {

        loge("#execSelectCount", e);
      }
    }
    return retVal;

  }
878501
@Override
    public String prepareQuery(Cells keys, Cells values) {

        StringBuilder sb = new StringBuilder("UPDATE ").append(quote(getCatalogName())).append(".")
                .append(quote(getTableName()))
                .append(" SET ");

        boolean isFirst = true;
        StringBuilder keyClause = new StringBuilder(" WHERE ");

        for (Cell cell : keys.getCells()) {
            if (!isFirst) {
                keyClause.append(" AND ");
            } else {
                isFirst = false;
            }
            keyClause.append(String.format("%s = ?", quote(cell.getCellName())));
        }

        isFirst = true;

        for (Cell cell : values.getCells()) {
            if (!isFirst) {
                sb.append(", ");
            } else {
                isFirst = false;
            }
            sb.append(String.format("%s = ?", quote(cell.getCellName())));

        }

        sb.append(keyClause).append(";");

        return sb.toString();
    }
512873
public TableKeysAndAttributes withHashAndRangeKeys(
            String hashKeyName, String rangeKeyName, 
            Object... alternatingHashAndRangeKeyValues) {
        if (hashKeyName == null)
            throw new IllegalArgumentException("hash key name must be specified");
        if (rangeKeyName == null)
            throw new IllegalArgumentException("range key name must be specified");
        if (alternatingHashAndRangeKeyValues.length % 2 != 0)
            throw new IllegalArgumentException("number of hash and range key values must be the same");
        final int len = alternatingHashAndRangeKeyValues.length / 2;
        PrimaryKey[] primaryKeys = new PrimaryKey[len];
        for (int i=0; i < alternatingHashAndRangeKeyValues.length; i += 2) {
            primaryKeys[i >> 1] = new PrimaryKey(
                hashKeyName, alternatingHashAndRangeKeyValues[i],
                rangeKeyName, alternatingHashAndRangeKeyValues[i+1]);
        }
        return withPrimaryKeys(primaryKeys);
    }
579968
@SuppressWarnings("WeakerAccess")
  public void dropRowRange(String tableId, String rowKeyPrefix) {
    ApiExceptions.callAndTranslateApiException(dropRowRangeAsync(tableId, rowKeyPrefix));
  }
794832
@VisibleForTesting
  RangeSet<RowKeyWrapper> rowSetToRangeSet(RowSet btRowSet) {
    RangeSet<RowKeyWrapper> rangeSet = TreeRangeSet.create();
    for (RowRange btRowRange : btRowSet.getRowRangesList()) {
      rangeSet.add(rowRangeToRange(btRowRange));
    }
    for (ByteString key : btRowSet.getRowKeysList()) {
      rangeSet.add(Range.singleton(new RowKeyWrapper(key)));
    }
    return rangeSet;
  }
152789
public void setRangesOnIndexedValues(java.util.Collection<ObjectAttributeRange> rangesOnIndexedValues) {
        if (rangesOnIndexedValues == null) {
            this.rangesOnIndexedValues = null;
            return;
        }

        this.rangesOnIndexedValues = new java.util.ArrayList<ObjectAttributeRange>(rangesOnIndexedValues);
    }
131536
@NonNull
  public static DeleteSelection deleteFrom(@Nullable String keyspace, @NonNull String table) {
    return deleteFrom(
        keyspace == null ? null : CqlIdentifier.fromCql(keyspace), CqlIdentifier.fromCql(table));
  }
110441
private T extractKeyAndRow(String timestamp, JSONObject jsonRow) {
        T rowValues = null;
        try {
            rowValues = rowMapper.newInstance();
            rowValues.getClass().getMethod("setTimestamp", String.class).invoke(rowValues, timestamp);
            for (Object key : jsonRow.keySet()) {
                Util.applyKVToBean(rowValues, key.toString(), jsonRow.get(key.toString()));
            }

        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException ex) {
            Logger.getLogger(Mapper4Bean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return rowValues;
    }
268431
static KeyRange keyRangeStartRow(byte[] startRowKey) {
        KeyRange keyRange = new KeyRange();
        keyRange.setStart_key(startRowKey);
        keyRange.setEnd_key(EMPTY_BYTE_BUFFER);
        keyRange.setCount(MAX_ROWS_BATCH_SIZE);
        return keyRange;
    }
497038
@Override
    public BoundStatement bindInsert(PreparedStatement statement, P pojo, int ttl) {
        List<Object> parameters = new LinkedList<>();
        keyBinding.collectParameters(pojo, parameters);
        facetBindings.forEach(facetBinding -> facetBinding.collectParameters(pojo, parameters));
        parameters.add(ttl);
        return bind(statement, parameters);
    }
894347
public Query query(DataRange dataRange) {
        RowPosition startPosition = dataRange.startKey();
        RowPosition stopPosition = dataRange.stopKey();
        Token startToken = startPosition.getToken();
        Token stopToken = stopPosition.getToken();
        boolean isSameToken = startToken.compareTo(stopToken) == 0 && !tokenMapper.isMinimum(startToken);
        BooleanClause.Occur occur = isSameToken ? MUST : SHOULD;
        boolean includeStart = tokenMapper.includeStart(startPosition);
        boolean includeStop = tokenMapper.includeStop(stopPosition);

        SliceQueryFilter sqf;
        if (startPosition instanceof DecoratedKey) {
            sqf = (SliceQueryFilter) dataRange.columnFilter(((DecoratedKey) startPosition).getKey());
        } else {
            sqf = (SliceQueryFilter) dataRange.columnFilter(ByteBufferUtil.EMPTY_BYTE_BUFFER);
        }
        Composite startName = sqf.start();
        Composite stopName = sqf.finish();

        BooleanQuery query = new BooleanQuery();

        if (!startName.isEmpty()) {
            BooleanQuery q = new BooleanQuery();
            q.add(tokenMapper.query(startToken), MUST);
            q.add(clusteringKeyMapper.query(startName, null), MUST);
            query.add(q, occur);
            includeStart = false;
        }

        if (!stopName.isEmpty()) {
            BooleanQuery q = new BooleanQuery();
            q.add(tokenMapper.query(stopToken), MUST);
            q.add(clusteringKeyMapper.query(null, stopName), MUST);
            query.add(q, occur);
            includeStop = false;
        }

        if (!isSameToken) {
            Query rangeQuery = tokenMapper.query(startToken, stopToken, includeStart, includeStop);
            if (rangeQuery != null) query.add(rangeQuery, SHOULD);
        } else if (query.getClauses().length == 0) {
            return tokenMapper.query(startToken);
        }

        return query.getClauses().length == 0 ? null : query;
    }