Пример #1
0
  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;
  }
Пример #2
0
 /**
  * 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();
   }
 }
Пример #3
0
  private static synchronized Dataset firstLoad(
      DatasetFramework framework,
      QueryHandle queryHandle,
      Id.DatasetInstance datasetInstanceId,
      ClassLoader classLoader)
      throws DatasetManagementException, IOException {
    ClassLoader datasetClassLoader =
        DATASET_CLASSLOADER_MAP.getUnchecked(queryHandle).get(datasetInstanceId);
    if (datasetClassLoader != null) {
      // Some other call in parallel may have already loaded it, so use the same classlaoder
      return framework.getDataset(
          datasetInstanceId, DatasetDefinition.NO_ARGUMENTS, datasetClassLoader);
    }

    // No classloader for dataset exists, load the dataset and save the classloader.
    Dataset dataset =
        framework.getDataset(datasetInstanceId, DatasetDefinition.NO_ARGUMENTS, classLoader);
    if (dataset != null) {
      DATASET_CLASSLOADER_MAP
          .getUnchecked(queryHandle)
          .put(datasetInstanceId, dataset.getClass().getClassLoader());
    }
    return dataset;
  }