<commit_before>package com.booking.replication.applier.hbase;

import com.booking.replication.augmenter.AugmentedRow;
import com.booking.replication.schema.TableNameMapper;

import com.google.common.base.Joiner;

import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

import org.apache.hadoop.hbase.util.Triple;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by bosko on 4/18/16.
 */
public class HBaseApplierMutationGenerator {

    public class PutMutation {

        private final Put put;
        private final String table;
        private final String sourceRowUri;
        private final boolean isTableMirrored;

        public PutMutation(Put put, String table, String sourceRowUri, boolean isTableMirrored) {
            this.put = put;
            this.sourceRowUri = sourceRowUri;
            this.table = table;
            this.isTableMirrored = isTableMirrored;
        }

        public Put getPut() {
            return put;
        }

        public String getSourceRowUri() {
            return sourceRowUri;
        }

        public String getTable(){
            return table;
        }

        public String getTargetRowUri() {

            // TODO: make URI generation in a right way

            try {

                String source = configuration.getValidationConfiguration().getSourceDomain();

                String row = URLEncoder.encode(Bytes.toStringBinary(put.getRow()),"UTF-8");

                String cf = URLEncoder.encode(Bytes.toString(CF),"UTF-8");

                return String.format("hbase://%s/%s?row=%s&cf=%s", source, table, row , cf);

            } catch (UnsupportedEncodingException e) {

                LOGGER.error("UTF-8 not supported?",e);

                return null;

            }

        }

        public boolean isTableMirrored() {
            return isTableMirrored;
        }
    }

    private static final byte[] CF                           = Bytes.toBytes("d");
    private static final String DIGEST_ALGORITHM             = "MD5";

    private final com.booking.replication.Configuration configuration;

    private static final Logger LOGGER = LoggerFactory.getLogger(HBaseApplierMutationGenerator.class);

    // Constructor
    public HBaseApplierMutationGenerator(com.booking.replication.Configuration configuration) {<commit_msg>Fixes the datasource in the target uri of emitted validation tasks<commit_after>package com.booking.replication.applier.hbase;

import com.booking.replication.augmenter.AugmentedRow;
import com.booking.replication.schema.TableNameMapper;

import com.google.common.base.Joiner;

import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

import org.apache.hadoop.hbase.util.Triple;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by bosko on 4/18/16.
 */
public class HBaseApplierMutationGenerator {

    public class PutMutation {

        private final Put put;
        private final String table;
        private final String sourceRowUri;
        private final boolean isTableMirrored;

        public PutMutation(Put put, String table, String sourceRowUri, boolean isTableMirrored) {
            this.put = put;
            this.sourceRowUri = sourceRowUri;
            this.table = table;
            this.isTableMirrored = isTableMirrored;
        }

        public Put getPut() {
            return put;
        }

        public String getSourceRowUri() {
            return sourceRowUri;
        }

        public String getTable(){
            return table;
        }

        public String getTargetRowUri() {

            // TODO: make URI generation in a right way

            try {

                String dataSource = configuration.getValidationConfiguration().getTargetDomain();

                String row = URLEncoder.encode(Bytes.toStringBinary(put.getRow()),"UTF-8");

                String cf = URLEncoder.encode(Bytes.toString(CF),"UTF-8");

                return String.format("hbase://%s/%s?row=%s&cf=%s", dataSource, table, row , cf);

            } catch (UnsupportedEncodingException e) {

                LOGGER.error("UTF-8 not supported?",e);

                return null;

            }

        }

        public boolean isTableMirrored() {
            return isTableMirrored;
        }
    }

    private static final byte[] CF                           = Bytes.toBytes("d");
    private static final String DIGEST_ALGORITHM             = "MD5";

    private final com.booking.replication.Configuration configuration;

    private static final Logger LOGGER = LoggerFactory.getLogger(HBaseApplierMutationGenerator.class);

    // Constructor
    public HBaseApplierMutationGenerator(com.booking.replication.Configuration configuration) {
{'fraction_non_alphanumeric': 0.08984156570363466, 'fraction_numerical': 0.004100652376514445, 'mean_word_length': 2.5372445616348056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3145029', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1440, 'n_words': 328}