Package co.cask.cdap.api.data.batch

Examples of co.cask.cdap.api.data.batch.RecordWritable


   * @param conf Configuration that contains RecordWritable name to load, CDAP and HBase configurations.
   * @return RecordWritable which name is contained in the {@code conf}.
   * @throws IOException in case the conf does not contain a valid RecordWritable.
   */
  public static RecordWritable getRecordWritable(Configuration conf) throws IOException {
    RecordWritable recordWritable = instantiateWritable(conf, null);

    if (recordWritable instanceof TransactionAware) {
      startTransaction(conf, (TransactionAware) recordWritable);
    }
    return recordWritable;
View Full Code Here


   * Check that the conf contains information about a valid RecordWritable object.
   * @param conf configuration containing RecordWritable name, CDAP and HBase configurations.
   * @throws IOException in case the conf does not contain a valid RecordWritable.
   */
  public static void checkRecordWritable(Configuration conf) throws IOException {
    RecordWritable recordWritable = instantiateWritable(conf, null);
    recordWritable.close();
  }
View Full Code Here

  private static final Logger LOG = LoggerFactory.getLogger(DatasetOutputFormat.class);

  @Override
  public RecordWriter<Void, Text> getRecordWriter(FileSystem ignored, final JobConf jobConf, String name,
                                                  Progressable progress) throws IOException {
    final RecordWritable recordWritable = DatasetAccessor.getRecordWritable(jobConf);
    final Type recordType = recordWritable.getRecordType();

    return new RecordWriter<Void, Text>() {
      @Override
      public void write(Void key, Text value) throws IOException {
        if (value == null) {
          throw new IOException("Writable value is null.");
        }
        recordWritable.write(new Gson().fromJson(value.toString(), recordType));
      }

      @Override
      public void close(Reporter reporter) throws IOException {
        try {
          if (recordWritable instanceof TransactionAware) {
            try {
              // Commit changes made to the dataset being written
              // NOTE: because the transaction wrapping a Hive query is a long running one,
              // we don't track changes and don't check conflicts - we can just commit the changes.
              ((TransactionAware) recordWritable).commitTx();
            } catch (Exception e) {
              LOG.error("Could not commit changes for table {}", recordWritable);
              throw new IOException(e);
            }
          }
        } finally {
          recordWritable.close();
        }
      }
    };
  }
View Full Code Here

TOP

Related Classes of co.cask.cdap.api.data.batch.RecordWritable

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.