@Override public Dataset create(String name, DatasetDescriptor descriptor) { Preconditions.checkArgument(name != null, "Name can not be null"); Preconditions.checkArgument(descriptor != null, "Descriptor can not be null"); Schema schema = descriptor.getSchema(); Path datasetPath = pathForDataset(name); try { if (fileSystem.exists(datasetPath)) { throw new DatasetRepositoryException("Attempt to create an existing dataset:" + name); } } catch (IOException e) { throw new DatasetRepositoryException( "Internal error while determining if dataset path already exists:" + datasetPath, e); } logger.debug( "Creating dataset:{} schema:{} datasetPath:{}", new Object[] {name, schema, datasetPath}); try { if (!fileSystem.mkdirs(datasetPath)) { throw new DatasetRepositoryException("Failed to make dataset path:" + datasetPath); } } catch (IOException e) { throw new DatasetRepositoryException( "Internal failure while creating dataset path:" + datasetPath, e); } metadataProvider.save(name, descriptor); return new FileSystemDataset.Builder() .name(name) .fileSystem(fileSystem) .descriptor(descriptor) .directory(pathForDataset(name)) .partitionKey(descriptor.isPartitioned() ? Accessor.getDefault().newPartitionKey() : null) .get(); }
@Override public Dataset get(String name) { Preconditions.checkArgument(name != null, "Name can not be null"); logger.debug("Loading dataset:{}", name); Path datasetDirectory = pathForDataset(name); DatasetDescriptor descriptor = metadataProvider.load(name); FileSystemDataset ds = new FileSystemDataset.Builder() .fileSystem(fileSystem) .descriptor(descriptor) .directory(datasetDirectory) .name(name) .get(); logger.debug("Loaded dataset:{}", ds); return ds; }
@Override public boolean drop(String name) { Preconditions.checkArgument(name != null, "Name can not be null"); logger.debug("Dropping dataset:{}", name); Path datasetPath = pathForDataset(name); try { if (metadataProvider.delete(name) && fileSystem.exists(datasetPath)) { if (fileSystem.delete(datasetPath, true)) { return true; } else { throw new DatasetRepositoryException( "Failed to delete dataset name:" + name + " data path:" + datasetPath); } } else { return false; } } catch (IOException e) { throw new DatasetRepositoryException( "Internal failure to test if dataset path exists:" + datasetPath); } }