コード例 #1
0
  /**
   * 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);
  }
コード例 #2
0
 @Override
 public void write(Object key, List<ByteBuffer> values) {
   prepareWriter();
   // To ensure Crunch doesn't reuse CQLSSTableWriter's objects
   List<ByteBuffer> bb = Lists.newArrayList();
   for (ByteBuffer v : values) {
     bb.add(ByteBufferUtil.clone(v));
   }
   values = bb;
   try {
     ((CQLSSTableWriter) writer).rawAddRow(values);
     if (null != progress) progress.progress();
     if (null != context) HadoopCompat.progress(context);
   } catch (InvalidRequestException | IOException e) {
     LOG.error(e.getMessage());
     throw new CrunchRuntimeException("Error adding row : " + e.getMessage());
   }
 }
コード例 #3
0
 /**
  * Upon construction, obtain the map that this writer will use to collect mutations, and the ring
  * cache for the given keyspace.
  *
  * @param context the task attempt context
  * @throws IOException
  */
 CqlRecordWriter(TaskAttemptContext context) throws IOException {
   this(HadoopCompat.getConfiguration(context));
   this.context = context;
 }