Search in sources :

Example 1 with AtomicFileOperations

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();
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) AtomicFileOperations(org.apache.carbondata.core.fileoperations.AtomicFileOperations) AtomicFileOperationsImpl(org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl) BufferedWriter(java.io.BufferedWriter)

Example 2 with AtomicFileOperations

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();
    }
}
Also used : CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) DataOutputStream(java.io.DataOutputStream) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) AtomicFileOperations(org.apache.carbondata.core.fileoperations.AtomicFileOperations) AtomicFileOperationsImpl(org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl) BufferedWriter(java.io.BufferedWriter)

Example 3 with AtomicFileOperations

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;
}
Also used : SegmentUpdateDetails(org.apache.carbondata.core.mutate.SegmentUpdateDetails) InputStreamReader(java.io.InputStreamReader) CarbonTablePath(org.apache.carbondata.core.util.path.CarbonTablePath) BufferedReader(java.io.BufferedReader) Gson(com.google.gson.Gson) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) AtomicFileOperations(org.apache.carbondata.core.fileoperations.AtomicFileOperations) AtomicFileOperationsImpl(org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl)

Example 4 with AtomicFileOperations

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) DeleteDeltaBlockDetails(org.apache.carbondata.core.mutate.DeleteDeltaBlockDetails) Gson(com.google.gson.Gson) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) AtomicFileOperations(org.apache.carbondata.core.fileoperations.AtomicFileOperations) AtomicFileOperationsImpl(org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl)

Example 5 with AtomicFileOperations

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();
}
Also used : LoadMetadataDetails(org.apache.carbondata.core.statusmanager.LoadMetadataDetails) DataOutputStream(java.io.DataOutputStream) Gson(com.google.gson.Gson) OutputStreamWriter(java.io.OutputStreamWriter) AtomicFileOperations(org.apache.carbondata.core.fileoperations.AtomicFileOperations) AtomicFileOperationsImpl(org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Aggregations

Gson (com.google.gson.Gson)9 IOException (java.io.IOException)9 AtomicFileOperations (org.apache.carbondata.core.fileoperations.AtomicFileOperations)9 AtomicFileOperationsImpl (org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl)9 BufferedWriter (java.io.BufferedWriter)5 DataOutputStream (java.io.DataOutputStream)5 OutputStreamWriter (java.io.OutputStreamWriter)5 BufferedReader (java.io.BufferedReader)4 DataInputStream (java.io.DataInputStream)4 InputStreamReader (java.io.InputStreamReader)4 CarbonTablePath (org.apache.carbondata.core.util.path.CarbonTablePath)4 LoadMetadataDetails (org.apache.carbondata.core.statusmanager.LoadMetadataDetails)2 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 DeleteDeltaBlockDetails (org.apache.carbondata.core.mutate.DeleteDeltaBlockDetails)1 SegmentUpdateDetails (org.apache.carbondata.core.mutate.SegmentUpdateDetails)1