mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Add test for reading Parquet files using Apache Arrow.
This commit is contained in:
@@ -102,6 +102,7 @@ set(SOURCE_UNITTEST_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifSummaryCalculationIO-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimEmReader-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifPolygonReader-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifParquetReader-Test.cpp
|
||||
)
|
||||
|
||||
if(RESINSIGHT_ENABLE_GRPC)
|
||||
|
||||
52
ApplicationLibCode/UnitTests/RifParquetReader-Test.cpp
Normal file
52
ApplicationLibCode/UnitTests/RifParquetReader-Test.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RiaTestDataDirectory.h"
|
||||
|
||||
#include <arrow/csv/api.h>
|
||||
#include <arrow/io/api.h>
|
||||
#include <arrow/scalar.h>
|
||||
#include <arrow/util/cancel.h>
|
||||
#include <parquet/arrow/reader.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QString>
|
||||
|
||||
TEST( RifParquetReaderTest, ReadValidFile )
|
||||
{
|
||||
QDir baseFolder( TEST_DATA_DIR );
|
||||
|
||||
QString filename( "RifParquetReader/example.parquet" );
|
||||
QString filePath = baseFolder.absoluteFilePath( filename );
|
||||
EXPECT_TRUE( QFile::exists( filePath ) );
|
||||
|
||||
arrow::MemoryPool* pool = arrow::default_memory_pool();
|
||||
|
||||
auto openResult = arrow::io::ReadableFile::Open( filePath.toStdString().c_str() );
|
||||
EXPECT_TRUE( openResult.ok() );
|
||||
|
||||
std::shared_ptr<arrow::io::RandomAccessFile> input = std::move( openResult ).ValueOrDie();
|
||||
|
||||
// Open Parquet file reader
|
||||
std::unique_ptr<parquet::arrow::FileReader> arrow_reader;
|
||||
EXPECT_TRUE( parquet::arrow::OpenFile( input, pool, &arrow_reader ).ok() );
|
||||
|
||||
// Read entire file as a single Arrow table
|
||||
std::shared_ptr<arrow::Table> table;
|
||||
EXPECT_TRUE( arrow_reader->ReadTable( &table ).ok() );
|
||||
|
||||
// Expect one column named "col1"
|
||||
EXPECT_EQ( table->columns().size(), 1 );
|
||||
std::vector<std::string> expectedNames = { "col1" };
|
||||
EXPECT_EQ( table->ColumnNames(), expectedNames );
|
||||
|
||||
// Expected the column to contain 100 int64 [0, 99]
|
||||
auto columnData = table->column( 0 );
|
||||
int expectedSize = 100;
|
||||
EXPECT_EQ( columnData->length(), expectedSize );
|
||||
for ( int i = 0; i < expectedSize; i++ )
|
||||
{
|
||||
std::shared_ptr<arrow::Scalar> scalar = columnData->GetScalar( i ).ValueOrDie();
|
||||
std::shared_ptr<arrow::Int64Scalar> intScalar = std::dynamic_pointer_cast<arrow::Int64Scalar>( scalar );
|
||||
EXPECT_TRUE( scalar->Equals( arrow::Int64Scalar( i ) ) );
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -636,6 +636,26 @@ add_subdirectory(ThirdParty/tomlplusplus)
|
||||
add_subdirectory(ThirdParty/spdlog)
|
||||
list(APPEND THIRD_PARTY_LIBRARIES spdlog)
|
||||
|
||||
# ##############################################################################
|
||||
# Arrow
|
||||
# ##############################################################################
|
||||
find_package(Arrow CONFIG REQUIRED)
|
||||
if(MSVC)
|
||||
list(APPEND THIRD_PARTY_LIBRARIES Arrow::arrow_shared)
|
||||
else()
|
||||
list(APPEND THIRD_PARTY_LIBRARIES Arrow::arrow_static)
|
||||
endif()
|
||||
|
||||
# ##############################################################################
|
||||
# Parquet
|
||||
# ##############################################################################
|
||||
find_package(Parquet CONFIG REQUIRED)
|
||||
if(MSVC)
|
||||
list(APPEND THIRD_PARTY_LIBRARIES Parquet::parquet_shared)
|
||||
else()
|
||||
list(APPEND THIRD_PARTY_LIBRARIES Parquet::parquet_static)
|
||||
endif()
|
||||
|
||||
# ##############################################################################
|
||||
# Thirdparty libraries are put in ThirdParty solution folder
|
||||
# ##############################################################################
|
||||
|
||||
@@ -2,5 +2,6 @@ grpc
|
||||
boost-filesystem
|
||||
boost-spirit
|
||||
eigen3
|
||||
arrow
|
||||
--triplet
|
||||
x64-linux
|
||||
|
||||
@@ -2,5 +2,6 @@ grpc
|
||||
boost-filesystem
|
||||
boost-spirit
|
||||
eigen3
|
||||
arrow
|
||||
--triplet
|
||||
x64-osx
|
||||
|
||||
@@ -2,5 +2,6 @@ grpc
|
||||
boost-filesystem
|
||||
boost-spirit
|
||||
eigen3
|
||||
arrow
|
||||
--triplet
|
||||
x64-windows
|
||||
|
||||
Reference in New Issue
Block a user