use of org.apache.carbondata.core.fileoperations.AtomicFileOperations in project carbondata by apache.
the class SegmentStatusManager method writeLoadDetailsIntoFile.
/**
* writes load details into a given file at @param dataLoadLocation
*
* @param dataLoadLocation
* @param listOfLoadFolderDetailsArray
* @throws IOException
*/
public static void writeLoadDetailsIntoFile(String dataLoadLocation, LoadMetadataDetails[] listOfLoadFolderDetailsArray) throws IOException {
AtomicFileOperations fileWrite = new AtomicFileOperationsImpl(dataLoadLocation, FileFactory.getFileType(dataLoadLocation));
BufferedWriter brWriter = null;
DataOutputStream dataOutputStream = null;
Gson gsonObjectToWrite = new Gson();
try {
dataOutputStream = fileWrite.openForWrite(FileWriteOperation.OVERWRITE);
brWriter = new BufferedWriter(new OutputStreamWriter(dataOutputStream, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)));
String metadataInstance = gsonObjectToWrite.toJson(listOfLoadFolderDetailsArray);
brWriter.write(metadataInstance);
} catch (IOException ioe) {
LOG.error("Error message: " + ioe.getLocalizedMessage());
throw ioe;
} finally {
if (null != brWriter) {
brWriter.flush();
}
CarbonUtil.closeStreams(brWriter);
fileWrite.close();
}
}
use of org.apache.carbondata.core.fileoperations.AtomicFileOperations in project carbondata by apache.
the class SegmentUpdateStatusManager method writeLoadDetailsIntoFile.
/**
* writes segment update details into a given file at @param dataLoadLocation
*
* @param listOfSegmentUpdateDetailsArray
* @throws IOException
*/
public void writeLoadDetailsIntoFile(List<SegmentUpdateDetails> listOfSegmentUpdateDetailsArray, String updateStatusFileIdentifier) throws IOException {
CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier());
String fileLocation = carbonTablePath.getMetadataDirectoryPath() + CarbonCommonConstants.FILE_SEPARATOR + CarbonUpdateUtil.getUpdateStatusFileName(updateStatusFileIdentifier);
AtomicFileOperations fileWrite = new AtomicFileOperationsImpl(fileLocation, FileFactory.getFileType(fileLocation));
BufferedWriter brWriter = null;
DataOutputStream dataOutputStream = null;
Gson gsonObjectToWrite = new Gson();
try {
dataOutputStream = fileWrite.openForWrite(FileWriteOperation.OVERWRITE);
brWriter = new BufferedWriter(new OutputStreamWriter(dataOutputStream, CarbonCommonConstants.CARBON_DEFAULT_STREAM_ENCODEFORMAT));
String metadataInstance = gsonObjectToWrite.toJson(listOfSegmentUpdateDetailsArray);
brWriter.write(metadataInstance);
} catch (IOException ioe) {
LOG.error("Error message: " + ioe.getLocalizedMessage());
} finally {
if (null != brWriter) {
brWriter.flush();
}
CarbonUtil.closeStreams(brWriter);
fileWrite.close();
}
}
use of org.apache.carbondata.core.fileoperations.AtomicFileOperations in project carbondata by apache.
the class SegmentUpdateStatusManager method readLoadMetadata.
/**
* This method loads segment update details
*
* @return
*/
public SegmentUpdateDetails[] readLoadMetadata() {
Gson gsonObjectToRead = new Gson();
DataInputStream dataInputStream = null;
BufferedReader buffReader = null;
InputStreamReader inStream = null;
SegmentUpdateDetails[] listOfSegmentUpdateDetailsArray;
// get the updated status file identifier from the table status.
String tableUpdateStatusIdentifier = getUpdatedStatusIdentifier();
if (null == tableUpdateStatusIdentifier) {
return new SegmentUpdateDetails[0];
}
CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier());
String tableUpdateStatusPath = carbonTablePath.getMetadataDirectoryPath() + CarbonCommonConstants.FILE_SEPARATOR + tableUpdateStatusIdentifier;
AtomicFileOperations fileOperation = new AtomicFileOperationsImpl(tableUpdateStatusPath, FileFactory.getFileType(tableUpdateStatusPath));
try {
if (!FileFactory.isFileExist(tableUpdateStatusPath, FileFactory.getFileType(tableUpdateStatusPath))) {
return new SegmentUpdateDetails[0];
}
dataInputStream = fileOperation.openForRead();
inStream = new InputStreamReader(dataInputStream, CarbonCommonConstants.CARBON_DEFAULT_STREAM_ENCODEFORMAT);
buffReader = new BufferedReader(inStream);
listOfSegmentUpdateDetailsArray = gsonObjectToRead.fromJson(buffReader, SegmentUpdateDetails[].class);
} catch (IOException e) {
return new SegmentUpdateDetails[0];
} finally {
closeStreams(buffReader, inStream, dataInputStream);
}
return listOfSegmentUpdateDetailsArray;
}
use of org.apache.carbondata.core.fileoperations.AtomicFileOperations in project carbondata by apache.
the class CarbonDeleteDeltaFileReaderImpl method readJson.
/**
* Reads delete delta file (json file) and returns DeleteDeltaBlockDetails
* @return DeleteDeltaBlockDetails
* @throws IOException
*/
@Override
public DeleteDeltaBlockDetails readJson() throws IOException {
Gson gsonObjectToRead = new Gson();
DataInputStream dataInputStream = null;
BufferedReader buffReader = null;
InputStreamReader inStream = null;
DeleteDeltaBlockDetails deleteDeltaBlockDetails;
AtomicFileOperations fileOperation = new AtomicFileOperationsImpl(filePath, FileFactory.getFileType(filePath));
try {
if (!FileFactory.isFileExist(filePath, FileFactory.getFileType(filePath))) {
return new DeleteDeltaBlockDetails("");
}
dataInputStream = fileOperation.openForRead();
inStream = new InputStreamReader(dataInputStream, CarbonCommonConstants.CARBON_DEFAULT_STREAM_ENCODEFORMAT);
buffReader = new BufferedReader(inStream);
deleteDeltaBlockDetails = gsonObjectToRead.fromJson(buffReader, DeleteDeltaBlockDetails.class);
} catch (IOException e) {
return new DeleteDeltaBlockDetails("");
} finally {
CarbonUtil.closeStreams(buffReader, inStream, dataInputStream);
}
return deleteDeltaBlockDetails;
}
use of org.apache.carbondata.core.fileoperations.AtomicFileOperations in project carbondata by apache.
the class StoreCreator method writeLoadMetadata.
public static void writeLoadMetadata(CarbonDataLoadSchema schema, String databaseName, String tableName, List<LoadMetadataDetails> listOfLoadFolderDetails) throws IOException {
LoadMetadataDetails loadMetadataDetails = new LoadMetadataDetails();
loadMetadataDetails.setLoadEndTime(System.currentTimeMillis());
loadMetadataDetails.setLoadStatus("SUCCESS");
loadMetadataDetails.setLoadName(String.valueOf(0));
loadMetadataDetails.setLoadStartTime(loadMetadataDetails.getTimeStamp(readCurrentTime()));
listOfLoadFolderDetails.add(loadMetadataDetails);
String dataLoadLocation = schema.getCarbonTable().getMetaDataFilepath() + File.separator + CarbonCommonConstants.LOADMETADATA_FILENAME;
DataOutputStream dataOutputStream;
Gson gsonObjectToWrite = new Gson();
BufferedWriter brWriter = null;
AtomicFileOperations writeOperation = new AtomicFileOperationsImpl(dataLoadLocation, FileFactory.getFileType(dataLoadLocation));
try {
dataOutputStream = writeOperation.openForWrite(FileWriteOperation.OVERWRITE);
brWriter = new BufferedWriter(new OutputStreamWriter(dataOutputStream, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)));
String metadataInstance = gsonObjectToWrite.toJson(listOfLoadFolderDetails.toArray());
brWriter.write(metadataInstance);
} catch (Exception ex) {
throw ex;
} finally {
try {
if (null != brWriter) {
brWriter.flush();
}
} catch (Exception e) {
throw e;
}
CarbonUtil.closeStreams(brWriter);
}
writeOperation.close();
}
Aggregations