Package org.apache.sqoop.etl.io

Examples of org.apache.sqoop.etl.io.DataReader


    @Override
    public void run() {
      LOG.info("SqoopOutputFormatLoadExecutor consumer thread is starting");
      try {
        DataReader reader = new OutputFormatDataReader();

        Configuration conf = null;
        if (!isTest) {
          conf = context.getConfiguration();
          loaderName = conf.get(JobConstants.JOB_ETL_LOADER);
View Full Code Here


    fieldDelimiter = Data.DEFAULT_FIELD_DELIMITER;
  }

  @Override
  public void load(LoaderContext context, Object oc, Object oj) throws Exception {
    DataReader reader = context.getDataReader();
    reader.setFieldDelimiter(fieldDelimiter);

    Configuration conf = new Configuration();
//    Configuration conf = ((EtlContext)context).getConfiguration();
    String filename = context.getString(JobConstants.JOB_MR_OUTPUT_FILE);
    String codecname = context.getString(JobConstants.JOB_MR_OUTPUT_CODEC);

    CompressionCodec codec = null;
    if (codecname != null) {
      Class<?> clz = ClassUtils.loadClass(codecname);
      if (clz == null) {
        throw new SqoopException(MapreduceExecutionError.MAPRED_EXEC_0009, codecname);
      }

      try {
        codec = (CompressionCodec) clz.newInstance();
        if (codec instanceof Configurable) {
          ((Configurable) codec).setConf(conf);
        }
      } catch (Exception e) {
        throw new SqoopException(MapreduceExecutionError.MAPRED_EXEC_0010, codecname, e);
      }
    }

    filename += EXTENSION;

    try {
      Path filepath = new Path(filename);
      SequenceFile.Writer filewriter;
      if (codec != null) {
        filewriter = SequenceFile.createWriter(filepath.getFileSystem(conf),
          conf, filepath, Text.class, NullWritable.class,
          CompressionType.BLOCK, codec);
      } else {
        filewriter = SequenceFile.createWriter(filepath.getFileSystem(conf),
          conf, filepath, Text.class, NullWritable.class, CompressionType.NONE);
      }

      String csv;
      Text text = new Text();
      while ((csv = reader.readCsvRecord()) != null) {
        text.set(csv);
        filewriter.append(text, NullWritable.get());
      }
      filewriter.close();
View Full Code Here

    recordDelimiter = Data.DEFAULT_RECORD_DELIMITER;
  }

  @Override
  public void load(LoaderContext context, Object oc, Object oj) throws Exception{
    DataReader reader = context.getDataReader();
    reader.setFieldDelimiter(fieldDelimiter);

    Configuration conf = new Configuration();
//    Configuration conf = ((EtlContext)context).getConfiguration();
    String filename = context.getString(JobConstants.JOB_MR_OUTPUT_FILE);
    String codecname = context.getString(JobConstants.JOB_MR_OUTPUT_CODEC);

    CompressionCodec codec = null;
    if (codecname != null) {
      Class<?> clz = ClassUtils.loadClass(codecname);
      if (clz == null) {
        throw new SqoopException(MapreduceExecutionError.MAPRED_EXEC_0009, codecname);
      }

      try {
        codec = (CompressionCodec) clz.newInstance();
        if (codec instanceof Configurable) {
          ((Configurable) codec).setConf(conf);
        }
      } catch (Exception e) {
        throw new SqoopException(MapreduceExecutionError.MAPRED_EXEC_0010, codecname, e);
      }

      filename += codec.getDefaultExtension();
    }

    try {
      Path filepath = new Path(filename);
      FileSystem fs = filepath.getFileSystem(conf);

      BufferedWriter filewriter;
      DataOutputStream filestream = fs.create(filepath, false);
      if (codec != null) {
        filewriter = new BufferedWriter(new OutputStreamWriter(
            codec.createOutputStream(filestream, codec.createCompressor()),
            Data.CHARSET_NAME));
      } else {
        filewriter = new BufferedWriter(new OutputStreamWriter(
            filestream, Data.CHARSET_NAME));
      }

      String csv;
      while ((csv = reader.readCsvRecord()) != null) {
        filewriter.write(csv + recordDelimiter);
      }
      filewriter.close();

    } catch (IOException e) {
View Full Code Here

    @Override
    public void run() {
      LOG.info("SqoopOutputFormatLoadExecutor consumer thread is starting");
      try {
        DataReader reader = new OutputFormatDataReader();

        Configuration conf = null;
        if (!isTest) {
          conf = context.getConfiguration();
          loaderName = conf.get(JobConstants.JOB_ETL_LOADER);
View Full Code Here

TOP

Related Classes of org.apache.sqoop.etl.io.DataReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.