///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2024 Equinor ASA // // ResInsight is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. // // See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #include "RifOsduWellLogReader.h" #include "RifByteArrayArrowRandomAccessFile.h" #include "cafAssert.h" #include #include #include #include #include #include #include //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::pair, QString> RifOsduWellLogReader::readWellLogData( const QByteArray& contents ) { // Function to convert an entire column to std::vector auto convertColumnToVector = []( const std::shared_ptr& column ) -> std::vector { auto convertChunkToVector = []( const std::shared_ptr& array ) -> std::vector { std::vector result; auto double_array = std::static_pointer_cast( array ); result.resize( double_array->length() ); for ( int64_t i = 0; i < double_array->length(); ++i ) { result[i] = double_array->Value( i ); } return result; }; CAF_ASSERT( column->type()->id() == arrow::Type::DOUBLE ); std::vector result; // Iterate over each chunk in the column for ( int i = 0; i < column->num_chunks(); ++i ) { std::shared_ptr chunk = column->chunk( i ); std::vector chunk_vector = convertChunkToVector( chunk ); result.insert( result.end(), chunk_vector.begin(), chunk_vector.end() ); } return result; }; arrow::MemoryPool* pool = arrow::default_memory_pool(); std::shared_ptr input = std::make_shared( contents ); // Open Parquet file reader std::unique_ptr arrow_reader; if ( !parquet::arrow::OpenFile( input, pool, &arrow_reader ).ok() ) { return { nullptr, "Unable to read parquet data." }; } // Read entire file as a single Arrow table std::shared_ptr table; if ( !arrow_reader->ReadTable( &table ).ok() ) { return { nullptr, "Unable to read parquet table." }; } auto logData = cvf::make_ref(); for ( std::string columnName : table->ColumnNames() ) { std::shared_ptr column = table->GetColumnByName( columnName ); if ( column->type()->id() == arrow::Type::DOUBLE ) { std::vector columnVector = convertColumnToVector( column ); logData->setValues( QString::fromStdString( columnName ), columnVector ); } } logData->finalizeData(); return { logData, "" }; }