/**
   * If the key is to be associated with a valid value, a mutation is created for it with the given
   * table and columns. In the event the value in the column is missing (i.e., null), then it is
   * marked for {@link Deletion}. Similarly, if the entire value for a key is missing (i.e., null),
   * then the entire key is marked for {@link Deletion}.
   *
   * @param keyColumns the key to write.
   * @param values the values to write.
   * @throws IOException
   */
  @Override
  public void write(Map<String, ByteBuffer> keyColumns, List<ByteBuffer> values)
      throws IOException {
    TokenRange range = ringCache.getRange(getPartitionKey(keyColumns));

    // get the client for the given range, or create a new one
    final InetAddress address = ringCache.getEndpoints(range).get(0);
    RangeClient client = clients.get(address);
    if (client == null) {
      // haven't seen keys for this range: create new client
      client = new RangeClient(ringCache.getEndpoints(range));
      client.start();
      clients.put(address, client);
    }

    // add primary key columns to the bind variables
    List<ByteBuffer> allValues = new ArrayList<ByteBuffer>(values);
    for (ColumnMetadata column : partitionKeyColumns)
      allValues.add(keyColumns.get(column.getName()));
    for (ColumnMetadata column : clusterColumns) allValues.add(keyColumns.get(column.getName()));

    client.put(allValues);

    if (progressable != null) progressable.progress();
    if (context != null) HadoopCompat.progress(context);
  }
  /** add where clauses for partition keys and cluster columns */
  private String appendKeyWhereClauses(String cqlQuery) {
    String keyWhereClause = "";

    for (ColumnMetadata partitionKey : partitionKeyColumns)
      keyWhereClause +=
          String.format(
              "%s = ?",
              keyWhereClause.isEmpty()
                  ? quote(partitionKey.getName())
                  : (" AND " + quote(partitionKey.getName())));
    for (ColumnMetadata clusterColumn : clusterColumns)
      keyWhereClause += " AND " + quote(clusterColumn.getName()) + " = ?";

    return cqlQuery + " WHERE " + keyWhereClause;
  }