outputStream.write(descriptor.getSchema().toString(true)
.getBytes(Charsets.UTF_8));
outputStream.flush();
threw = false;
} catch (IOException e) {
throw new DatasetIOException(
"Unable to save schema file: " + schemaPath +
" for dataset: " + name, e);
} finally {
try {
Closeables.close(outputStream, threw);
} catch (IOException e) {
throw new DatasetIOException("Cannot close", e);
}
}
Properties properties = new Properties();
properties.setProperty(VERSION_FIELD_NAME, METADATA_VERSION);
properties.setProperty(FORMAT_FIELD_NAME, descriptor.getFormat().getName());
properties.setProperty(COMPRESSION_TYPE_FIELD_NAME, descriptor.getCompressionType().getName());
final URI dataLocation = descriptor.getLocation();
if (dataLocation != null) {
properties.setProperty(LOCATION_FIELD_NAME, dataLocation.toString());
}
if (descriptor.isPartitioned()) {
properties.setProperty(PARTITION_EXPRESSION_FIELD_NAME,
Accessor.getDefault().toExpression(descriptor.getPartitionStrategy()));
}
// copy custom properties to the table
for (String property : descriptor.listProperties()) {
// no need to check the reserved list, those are not set on descriptors
properties.setProperty(property, descriptor.getProperty(property));
}
final Path descriptorPath = new Path(metadataLocation, DESCRIPTOR_FILE_NAME);
threw = true;
try {
outputStream = fs.create(descriptorPath, true /* overwrite */ );
properties.store(outputStream, "Dataset descriptor for " + name);
outputStream.flush();
threw = false;
} catch (IOException e) {
throw new DatasetIOException(
"Unable to save descriptor file: " + descriptorPath +
" for dataset: " + name, e);
} finally {
try {
Closeables.close(outputStream, threw);
} catch (IOException e) {
throw new DatasetIOException("Cannot close", e);
}
}
}