This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Ape base #222
Open
yspMing
wants to merge
2
commits into
oap-project:ape
Choose a base branch
from
yspMing:ape-base
base: ape
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ape base #222
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
#include <stdlib.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add license |
||
|
||
#include <iostream> | ||
#include <memory> | ||
|
||
#include <arrow/api.h> | ||
#include <arrow/filesystem/api.h> | ||
#include <parquet/api/reader.h> | ||
#include <gtest/gtest.h> | ||
#include <vector> | ||
|
||
#include "src/reader.h" | ||
#include "src/utils/PredicateExpression.h" | ||
|
||
TEST(predicateFilterTest, minMaxTest) | ||
{ | ||
arrow::fs::HdfsOptions options_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. format this file? |
||
|
||
std::string hdfs_host = "clx06-AEP"; | ||
int hdfs_port = 8020; | ||
|
||
options_.ConfigureEndPoint(hdfs_host, hdfs_port); | ||
|
||
auto result = arrow::fs::HadoopFileSystem::Make(options_); | ||
EXPECT_TRUE(result.ok()) << "HadoopFileSystem Make failed"; | ||
|
||
std::shared_ptr<arrow::fs::FileSystem> fs_ = | ||
std::make_shared<arrow::fs::SubTreeFileSystem>("", *result); | ||
|
||
std::string file_name = | ||
"/user/hive/warehouse/tpcds_hdfs_parquet_10.db/store_sales/ss_sold_date_sk=2450817/" | ||
"part-00013-0828d1ab-ef1f-4b55-bf94-c071fb76c353.c000.snappy.parquet"; | ||
|
||
auto file_result = fs_->OpenInputFile(file_name); | ||
EXPECT_TRUE(file_result.ok()) << "Open hdfs file failed"; | ||
|
||
std::shared_ptr<arrow::io::RandomAccessFile> file = file_result.ValueOrDie(); | ||
std::cout << "file size is " << file->GetSize().ValueOrDie() << std::endl; | ||
|
||
parquet::ReaderProperties properties; | ||
// std::shared_ptr<parquet::FileMetaData> metadata; | ||
std::unique_ptr<parquet::ParquetFileReader> parquetReader = | ||
parquet::ParquetFileReader::Open(file, properties, NULLPTR); | ||
|
||
std::shared_ptr<parquet::FileMetaData> fileMetaData = parquetReader->metadata(); | ||
|
||
int numRows = fileMetaData->num_rows(); | ||
int numCols = fileMetaData->num_columns(); | ||
int numRowGroups = fileMetaData->num_row_groups(); | ||
std::string schema = fileMetaData->schema()->ToString(); | ||
|
||
std::cout<<"parquet file has "<<numRows<<" rows"<<std::endl | ||
<<numCols<<" cols"<<std::endl | ||
<<numRowGroups<<" row groups"<<std::endl; | ||
|
||
std::cout<<"schema: "<<schema<<std::endl; | ||
|
||
if(numRowGroups < 1) | ||
{ | ||
std::cout<<"not enough row groups for test"<<std::endl; | ||
return; | ||
} | ||
|
||
int rowGroupIndex = 0; | ||
std::unique_ptr<parquet::RowGroupMetaData> urgMataData = fileMetaData->RowGroup(rowGroupIndex); | ||
std::shared_ptr<parquet::RowGroupMetaData> rgMataData = std::move(urgMataData); | ||
|
||
//std::vector<std::unique_ptr<parquet::ColumnChunkMetaData>> columnChunkMeta; | ||
//columnChunkMeta.resize(numCols); | ||
std::unique_ptr<parquet::ColumnChunkMetaData> columnChunkMeta; | ||
|
||
for(int i=0; i<numCols; i++) | ||
{ | ||
columnChunkMeta = rgMataData->ColumnChunk(i); | ||
std::string column_name = fileMetaData->schema()->Column(i)->name(); | ||
parquet::Type::type column_type = fileMetaData->schema()->Column(i)->physical_type(); | ||
std::cout<<"current column["<<i<<"]: "<<column_name | ||
<<" type "<<column_type | ||
<<std::endl; | ||
|
||
std::shared_ptr<parquet::Statistics> statistic = columnChunkMeta->statistics(); | ||
if(!statistic->HasMinMax()) | ||
{ | ||
std::cout<<"This column does not have valid min max value."<<std::endl; | ||
continue; | ||
} | ||
switch (column_type) | ||
{ | ||
case parquet::Type::BOOLEAN:{ | ||
auto boolStatistic = std::static_pointer_cast<parquet::BoolStatistics>(statistic); | ||
std::cout<<"min: "<<boolStatistic->min()<<" max: "<<boolStatistic->max()<<std::endl; | ||
break;} | ||
case parquet::Type::INT32:{ | ||
auto int32Statistic = std::static_pointer_cast<parquet::Int32Statistics>(statistic); | ||
std::cout<<"min: "<<int32Statistic->min()<<" max: "<<int32Statistic->max()<<std::endl; | ||
break;} | ||
case parquet::Type::INT64:{ | ||
auto int64Statistic = std::static_pointer_cast<parquet::Int64Statistics>(statistic); | ||
std::cout<<"min: "<<int64Statistic->min()<<" max: "<<int64Statistic->max()<<std::endl; | ||
break;} | ||
case parquet::Type::FLOAT:{ | ||
auto floatStatistic = std::static_pointer_cast<parquet::FloatStatistics>(statistic); | ||
std::cout<<"min: "<<floatStatistic->min()<<" max: "<<floatStatistic->max()<<std::endl; | ||
break;} | ||
|
||
default: | ||
break; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
TEST(predicateFilterTest, predicateTest) { | ||
|
||
std::string hdfs_host = "clx06-AEP"; | ||
int hdfs_port = 8020; | ||
|
||
std::string file_name = | ||
"/user/hive/warehouse/tpcds_hdfs_parquet_10.db/store_sales/ss_sold_date_sk=2450817/" | ||
"part-00013-0828d1ab-ef1f-4b55-bf94-c071fb76c353.c000.snappy.parquet"; | ||
|
||
std::string requiredColumnName = R"( | ||
{ | ||
"name":"my_schema", | ||
"fields":[ | ||
{ | ||
"name":"ss_sold_time_sk", | ||
"value":true | ||
}, | ||
{ | ||
"name":"ss_sold_time_sk", | ||
"value":true | ||
} | ||
] | ||
} | ||
)"; | ||
|
||
std::string filterJson = R"( | ||
{ | ||
"FilterTypeName":"and", | ||
"LeftNode":{ | ||
"FilterTypeName":"lt", | ||
"ColumnType":"Integer", | ||
"ColumnName":"ss_sold_time_sk", | ||
"Value":"28855" | ||
}, | ||
"RightNode":{ | ||
"FilterTypeName":"gt", | ||
"ColumnType":"Integer", | ||
"ColumnName":"ss_item_sk", | ||
"Value":"3" | ||
} | ||
} | ||
|
||
)"; | ||
|
||
int firstRowGroup = 0; | ||
int rowGroupToRead = 1; | ||
|
||
ape::Reader test_reader; | ||
test_reader.init(file_name, hdfs_host, hdfs_port,requiredColumnName, firstRowGroup, rowGroupToRead); | ||
test_reader.setFilter(filterJson); | ||
|
||
bool res = test_reader.doPredicateFilter(0); | ||
std::cout<<"predicateFiltere: "<<res<<std::endl; | ||
|
||
test_reader.close(); | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove these logs?