private static RecordWritable instantiateWritable( @Nullable Configuration conf, Id.DatasetInstance datasetInstanceId) throws IOException { Dataset dataset = instantiate(conf, datasetInstanceId); if (!(dataset instanceof RecordWritable)) { dataset.close(); throw new IOException( String.format( "Dataset %s does not implement RecordWritable, and hence cannot be written to in Hive.", datasetInstanceId != null ? datasetInstanceId : getDatasetInstanceId(conf))); } return (RecordWritable) dataset; }
/** * Returns record type of the RecordScannable. * * @param conf Configuration that contains RecordScannable name to load, CDAP and HBase * configurations. * @return Record type of RecordScannable dataset. * @throws IOException in case the conf does not contain a valid RecordScannable. */ private static Type getRecordType(Configuration conf, Id.DatasetInstance id) throws IOException { Dataset dataset = instantiate(conf, id); try { if (dataset instanceof RecordWritable) { return ((RecordWritable) dataset).getRecordType(); } else if (dataset instanceof RecordScannable) { return ((RecordScannable) dataset).getRecordType(); } throw new IOException( String.format( "Dataset %s does not implement neither RecordScannable nor RecordWritable.", getDatasetInstanceId(conf))); } finally { dataset.close(); } }