Package co.cask.cdap.api.dataset

Examples of co.cask.cdap.api.dataset.Dataset


   * @param conf Configuration that contains RecordScannable name to load, CDAP and HBase configuration.
   * @return RecordScannable which name is contained in the {@code conf}.
   * @throws IOException in case the conf does not contain a valid RecordScannable.
   */
  public static RecordScannable getRecordScannable(Configuration conf) throws IOException {
    Dataset dataset = instantiate(conf);

    if (!(dataset instanceof RecordScannable)) {
      throw new IOException(
        String.format("Dataset %s does not implement RecordScannable, and hence cannot be queried in Hive.",
                      conf.get(Constants.Explore.DATASET_NAME)));
View Full Code Here


   * @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.
   */
  public static Type getRecordType(Configuration conf) throws IOException {
    Dataset dataset = instantiate(conf);
    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.",
                      conf.get(Constants.Explore.DATASET_NAME)));
    } finally {
      dataset.close();
    }
  }
View Full Code Here

    txAware.startTx(tx);
  }

  private static RecordWritable instantiateWritable(@Nullable Configuration conf, String datasetName)
    throws IOException {
    Dataset dataset = instantiate(conf, datasetName);

    if (!(dataset instanceof RecordWritable)) {
      throw new IOException(
        String.format("Dataset %s does not implement RecordWritable, and hence cannot be written to in Hive.",
                      datasetName != null ? datasetName : conf.get(Constants.Explore.DATASET_NAME)));
View Full Code Here

    }
    return (RecordWritable) dataset;
  }

  private static Dataset instantiate(Configuration conf) throws IOException {
    Dataset dataset = instantiate(conf, null);

    if (!(dataset instanceof RecordScannable || dataset instanceof RecordWritable)) {
      throw new IOException(
        String.format("Dataset %s does not implement neither RecordScannable nor RecordWritable.",
                      conf.get(Constants.Explore.DATASET_NAME)));
View Full Code Here

    try {
      DatasetFramework framework = context.getDatasetFramework();

      ClassLoader classLoader = DATASET_CLASSLOADERS.get(datasetName);
      Dataset dataset;
      if (classLoader == null) {
        if (conf == null) {
          throw new NullJobConfException();
        }
        classLoader = conf.getClassLoader();
View Full Code Here

      // Some other call in parallel may have already loaded it, so use the same classlaoder
      return framework.getDataset(datasetName, DatasetDefinition.NO_ARGUMENTS, datasetClassLoader);
    }

    // No classloader for dataset exists, load the dataset and save the classloader.
    Dataset dataset = framework.getDataset(datasetName, DatasetDefinition.NO_ARGUMENTS, classLoader);
    if (dataset != null) {
      DATASET_CLASSLOADERS.put(datasetName, dataset.getClass().getClassLoader());
    }
    return dataset;
  }
View Full Code Here

  @POST
  @Path("data/explore/datasets/{dataset}/enable")
  public void enableExplore(@SuppressWarnings("UnusedParameters") HttpRequest request, HttpResponder responder,
                            @PathParam("dataset") final String datasetName) {
    try {
      Dataset dataset;
      try {
        dataset = datasetFramework.getDataset(datasetName, DatasetDefinition.NO_ARGUMENTS, null);
      } catch (Exception e) {
        String className = isClassNotFoundException(e);
        if (className == null) {
          throw e;
        }
        LOG.info("Cannot load dataset {} because class {} cannot be found. This is probably because class {} is a " +
                   "type parameter of dataset {} that is not present in the dataset's jar file. See the developer " +
                   "guide for more information.", datasetName, className, className, datasetName);
        JsonObject json = new JsonObject();
        json.addProperty("handle", QueryHandle.NO_OP.getHandle());
        responder.sendJson(HttpResponseStatus.OK, json);
        return;
      }
      if (dataset == null) {
        responder.sendError(HttpResponseStatus.NOT_FOUND, "Cannot load dataset " + datasetName);
        return;
      }

      if (!(dataset instanceof RecordScannable || dataset instanceof RecordWritable)) {
        // It is not an error to get non-RecordEnabled datasets, since the type of dataset may not be known where this
        // call originates from.
        LOG.debug("Dataset {} neither implements {} nor {}", datasetName, RecordScannable.class.getName(),
                  RecordWritable.class.getName());
        JsonObject json = new JsonObject();
        json.addProperty("handle", QueryHandle.NO_OP.getHandle());
        responder.sendJson(HttpResponseStatus.OK, json);
        return;
      }

      LOG.debug("Enabling explore for dataset instance {}", datasetName);
      String createStatement;
      try {
        createStatement = generateCreateStatement(datasetName, dataset);
      } catch (UnsupportedTypeException e) {
        LOG.error("Exception while generating create statement for dataset {}", datasetName, e);
        responder.sendError(HttpResponseStatus.BAD_REQUEST, e.getMessage());
        return;
      }

      LOG.debug("Running create statement for dataset {} with row scannable {} - {}",
                datasetName,
                dataset.getClass().getName(),
                createStatement);

      QueryHandle handle = exploreService.execute(createStatement);
      JsonObject json = new JsonObject();
      json.addProperty("handle", handle.getHandle());
View Full Code Here

  public void disableExplore(@SuppressWarnings("UnusedParameters") HttpRequest request, HttpResponder responder,
                             @PathParam("dataset") final String datasetName) {
    try {
      LOG.debug("Disabling explore for dataset instance {}", datasetName);

      Dataset dataset = datasetFramework.getDataset(datasetName, DatasetDefinition.NO_ARGUMENTS, null);
      if (dataset == null) {
        responder.sendError(HttpResponseStatus.NOT_FOUND, "Cannot load dataset " + datasetName);
        return;
      }
View Full Code Here

                                                   "by the Worker. Specificy datasets used using useDataset() " +
                                                   "method in the Workers's configure.", name);
      Preconditions.checkArgument(datasets.contains(name), datasetNotUsedError);

      try {
        Dataset dataset = datasetFramework.getDataset(name, arguments,
                                                      programClassLoader);
        if (dataset == null) {
          throw new DataSetInstantiationException(String.format("Dataset %s does not exist.", name));
        }
        context.addTransactionAware((TransactionAware) dataset);
View Full Code Here

   * @return updated {@link Configuration}
   * @throws {@link IllegalArgumentException} if the {@link Dataset} to read is not {@link BatchReadable}
   */
  Configuration setInputDataset(String datasetName) {
    Configuration hConf = new Configuration(getHConf());
    Dataset dataset = basicSparkContext.getDataSet(datasetName);
    List<Split> inputSplits;
    if (dataset instanceof BatchReadable) {
      BatchReadable curDataset = (BatchReadable) dataset;
      inputSplits = curDataset.getSplits();
    } else {
View Full Code Here

TOP

Related Classes of co.cask.cdap.api.dataset.Dataset

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.