<commit_before>package com.google.cloud.anviltop.hbase.adapters;

import com.google.bigtable.anviltop.AnviltopData;
import com.google.bigtable.anviltop.AnviltopServices.AppendRowRequest;
import com.google.cloud.anviltop.hbase.AnviltopConstants;
import com.google.cloud.hadoop.hbase.repackaged.protobuf.ByteString;
import com.google.common.collect.ImmutableList;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Append;

import java.util.List;
import java.util.Map;

/**
 * Adapter for HBase Appends operations to Anviltop AppendRowRequest.Builder.
 */
public class AppendAdapter implements OperationAdapter<Append, AppendRowRequest.Builder> {

  @Override
  public AppendRowRequest.Builder adapt(Append operation) {
    AppendRowRequest.Builder result = AppendRowRequest.newBuilder();
    AnviltopData.RowAppend.Builder append = result.getAppendBuilder();
    append.setRowKey(ByteString.copyFrom(operation.getRow()));
    append.setReturnResults(operation.isReturnResults());


    for (Map.Entry<byte[], List<Cell>> entry : operation.getFamilyCellMap().entrySet()){
      for (Cell cell : entry.getValue()) {
        ByteString columnName = ByteString.copyFrom(
            ImmutableList.of(
                ByteString.copyFrom(CellUtil.cloneFamily(cell)),
                AnviltopConstants.ANVILTOP_COLUMN_SEPARATOR_BYTE_STRING,
                ByteString.copyFrom(CellUtil.cloneQualifier(cell))));

        append.addAppendsBuilder()
            .setColumnName(columnName)
            .setValue(ByteString.copyFrom(CellUtil.cloneValue(cell)));

      }
    }
    return result;
  }
}<commit_msg>Avoid doing multiple copies of the array.<commit_after>package com.google.cloud.anviltop.hbase.adapters;

import com.google.bigtable.anviltop.AnviltopData;
import com.google.bigtable.anviltop.AnviltopServices.AppendRowRequest;
import com.google.cloud.anviltop.hbase.AnviltopConstants;
import com.google.cloud.hadoop.hbase.repackaged.protobuf.ByteString;
import com.google.common.collect.ImmutableList;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Append;

import java.util.List;
import java.util.Map;

/**
 * Adapter for HBase Appends operations to Anviltop AppendRowRequest.Builder.
 */
public class AppendAdapter implements OperationAdapter<Append, AppendRowRequest.Builder> {

  @Override
  public AppendRowRequest.Builder adapt(Append operation) {
    AppendRowRequest.Builder result = AppendRowRequest.newBuilder();
    AnviltopData.RowAppend.Builder append = result.getAppendBuilder();
    append.setRowKey(ByteString.copyFrom(operation.getRow()));
    append.setReturnResults(operation.isReturnResults());


    for (Map.Entry<byte[], List<Cell>> entry : operation.getFamilyCellMap().entrySet()){
      for (Cell cell : entry.getValue()) {
        ByteString columnName = ByteString.copyFrom(
            ImmutableList.of(
                ByteString.copyFrom(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()),
                AnviltopConstants.ANVILTOP_COLUMN_SEPARATOR_BYTE_STRING,
                ByteString.copyFrom(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())));

        append.addAppendsBuilder()
            .setColumnName(columnName)
            .setValue(ByteString.copyFrom(CellUtil.cloneValue(cell)));

      }
    }
    return result;
  }
}
{'fraction_non_alphanumeric': 0.10805330243337195, 'fraction_numerical': 0.0, 'mean_word_length': 4.279816513761468, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '141208', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1026, 'n_words': 150}