Search in sources :

Example 1 with PhoenixInputFormat

use of org.apache.phoenix.mapreduce.PhoenixInputFormat in project DataX by alibaba.

the class HbaseSQLHelper method split.

public static List<Configuration> split(HbaseSQLReaderConfig readerConfig) {
    PhoenixInputFormat inputFormat = new PhoenixInputFormat<PhoenixRecordWritable>();
    org.apache.hadoop.conf.Configuration conf = generatePhoenixConf(readerConfig);
    JobID jobId = new JobID(Key.MOCK_JOBID_IDENTIFIER, Key.MOCK_JOBID);
    JobContextImpl jobContext = new JobContextImpl(conf, jobId);
    List<Configuration> resultConfigurations = new ArrayList<Configuration>();
    List<InputSplit> rawSplits = null;
    try {
        rawSplits = inputFormat.getSplits(jobContext);
        LOG.info("split size is " + rawSplits.size());
        for (InputSplit split : rawSplits) {
            Configuration cfg = readerConfig.getOriginalConfig().clone();
            byte[] splitSer = HadoopSerializationUtil.serialize((PhoenixInputSplit) split);
            String splitBase64Str = org.apache.commons.codec.binary.Base64.encodeBase64String(splitSer);
            cfg.set(Key.SPLIT_KEY, splitBase64Str);
            resultConfigurations.add(cfg);
        }
    } catch (IOException e) {
        throw DataXException.asDataXException(HbaseSQLReaderErrorCode.GET_PHOENIX_SPLITS_ERROR, "获取表的split信息时出现了异常,请检查hbase集群服务是否正常," + e.getMessage(), e);
    } catch (InterruptedException e) {
        throw DataXException.asDataXException(HbaseSQLReaderErrorCode.GET_PHOENIX_SPLITS_ERROR, "获取表的split信息时被中断,请重试,若还有问题请联系datax管理员," + e.getMessage(), e);
    }
    return resultConfigurations;
}
Also used : PhoenixInputFormat(org.apache.phoenix.mapreduce.PhoenixInputFormat) JobContextImpl(org.apache.hadoop.mapreduce.task.JobContextImpl) Configuration(com.alibaba.datax.common.util.Configuration) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PhoenixInputSplit(org.apache.phoenix.mapreduce.PhoenixInputSplit) InputSplit(org.apache.hadoop.mapreduce.InputSplit) JobID(org.apache.hadoop.mapreduce.JobID)

Example 2 with PhoenixInputFormat

use of org.apache.phoenix.mapreduce.PhoenixInputFormat in project Datax by n-kong.

the class HbaseSQLHelper method split.

public static List<Configuration> split(HbaseSQLReaderConfig readerConfig) {
    PhoenixInputFormat inputFormat = new PhoenixInputFormat<PhoenixRecordWritable>();
    org.apache.hadoop.conf.Configuration conf = generatePhoenixConf(readerConfig);
    JobID jobId = new JobID(Key.MOCK_JOBID_IDENTIFIER, Key.MOCK_JOBID);
    JobContextImpl jobContext = new JobContextImpl(conf, jobId);
    List<Configuration> resultConfigurations = new ArrayList<Configuration>();
    List<InputSplit> rawSplits = null;
    try {
        rawSplits = inputFormat.getSplits(jobContext);
        LOG.info("split size is " + rawSplits.size());
        for (InputSplit split : rawSplits) {
            Configuration cfg = readerConfig.getOriginalConfig().clone();
            byte[] splitSer = HadoopSerializationUtil.serialize((PhoenixInputSplit) split);
            String splitBase64Str = org.apache.commons.codec.binary.Base64.encodeBase64String(splitSer);
            cfg.set(Key.SPLIT_KEY, splitBase64Str);
            resultConfigurations.add(cfg);
        }
    } catch (IOException e) {
        throw DataXException.asDataXException(HbaseSQLReaderErrorCode.GET_PHOENIX_SPLITS_ERROR, "获取表的split信息时出现了异常,请检查hbase集群服务是否正常," + e.getMessage(), e);
    } catch (InterruptedException e) {
        throw DataXException.asDataXException(HbaseSQLReaderErrorCode.GET_PHOENIX_SPLITS_ERROR, "获取表的split信息时被中断,请重试,若还有问题请联系datax管理员," + e.getMessage(), e);
    }
    return resultConfigurations;
}
Also used : PhoenixInputFormat(org.apache.phoenix.mapreduce.PhoenixInputFormat) JobContextImpl(org.apache.hadoop.mapreduce.task.JobContextImpl) Configuration(com.alibaba.datax.common.util.Configuration) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PhoenixInputSplit(org.apache.phoenix.mapreduce.PhoenixInputSplit) InputSplit(org.apache.hadoop.mapreduce.InputSplit) JobID(org.apache.hadoop.mapreduce.JobID)

Aggregations

Configuration (com.alibaba.datax.common.util.Configuration)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 InputSplit (org.apache.hadoop.mapreduce.InputSplit)2 JobID (org.apache.hadoop.mapreduce.JobID)2 JobContextImpl (org.apache.hadoop.mapreduce.task.JobContextImpl)2 PhoenixInputFormat (org.apache.phoenix.mapreduce.PhoenixInputFormat)2 PhoenixInputSplit (org.apache.phoenix.mapreduce.PhoenixInputSplit)2