Exemple #1
0
 /**
  * Precondition-style validation that a dataset name is compatible.
  *
  * @param namespace a String namespace
  * @param name a String name
  */
 public static void checkDatasetName(String namespace, String name) {
   Preconditions.checkNotNull(namespace, "Namespace cannot be null");
   Preconditions.checkNotNull(name, "Dataset name cannot be null");
   Preconditions.checkArgument(
       Compatibility.isCompatibleName(namespace),
       "Hive incompatible: Namespace %s is not alphanumeric (plus '_')",
       namespace);
   Preconditions.checkArgument(
       Compatibility.isCompatibleName(name),
       "Hive incompatible: Dataset name %s is not alphanumeric (plus '_')",
       name);
 }
  @Override
  public DatasetDescriptor update(String name, DatasetDescriptor descriptor) {
    Compatibility.checkDatasetName(name);
    Compatibility.checkDescriptor(descriptor);

    if (!exists(name)) {
      throw new DatasetNotFoundException("Table not found: " + name);
    }

    Table table = getHcat().getTable(HiveUtils.DEFAULT_DB, name);
    HiveUtils.updateTableSchema(table, descriptor);
    getHcat().alterTable(table);
    return descriptor;
  }
  @Override
  public boolean delete(String name) {
    Compatibility.checkDatasetName(name);

    // TODO: when switching off of HCatalog, this may need to be moved
    if (!exists(name)) {
      return false;
    }
    getHcat().dropTable(HiveUtils.DEFAULT_DB, name);
    return true;
  }
  @Override
  public boolean exists(String name) {
    Compatibility.checkDatasetName(name);

    return getHcat().exists(HiveUtils.DEFAULT_DB, name);
  }