Search in sources :

Example 1 with AtomicFileOperationsImpl

use of org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl 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 AtomicFileOperationsImpl

use of org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl 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 AtomicFileOperationsImpl

use of org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl 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 AtomicFileOperationsImpl

use of org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl 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 AtomicFileOperationsImpl

use of org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl in project carbondata by apache.

the class ThriftWriter method open.

/**
   * Method for opening file writing for atomic operations
   *
   * @param fileWriteOperation
   * @throws IOException
   */
public void open(FileWriteOperation fileWriteOperation) throws IOException {
    FileFactory.FileType fileType = FileFactory.getFileType(fileName);
    atomicFileOperationsWriter = new AtomicFileOperationsImpl(fileName, fileType);
    dataOutputStream = atomicFileOperationsWriter.openForWrite(fileWriteOperation);
    binaryOut = new TCompactProtocol(new TIOStreamTransport(dataOutputStream));
}
Also used : TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) AtomicFileOperationsImpl(org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl) FileFactory(org.apache.carbondata.core.datastore.impl.FileFactory)

Aggregations

AtomicFileOperationsImpl (org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl)10 Gson (com.google.gson.Gson)9 IOException (java.io.IOException)9 AtomicFileOperations (org.apache.carbondata.core.fileoperations.AtomicFileOperations)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 FileFactory (org.apache.carbondata.core.datastore.impl.FileFactory)1 DeleteDeltaBlockDetails (org.apache.carbondata.core.mutate.DeleteDeltaBlockDetails)1 SegmentUpdateDetails (org.apache.carbondata.core.mutate.SegmentUpdateDetails)1 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)1 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)1