Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GLUTEN-3582][CH] Using ParquetBlockInputFormat instead of VectorizedParquetBlockInputFormat for complex type #5995

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class GlutenClickHouseHiveTableSuite
getClass.getResource("/").getPath + "tests-working-home/spark-warehouse")
.set("spark.hive.exec.dynamic.partition.mode", "nonstrict")
.set("spark.gluten.supported.hive.udfs", "my_add")
.set("spark.gluten.sql.columnar.backend.ch.runtime_config.use_local_format", "true")
.setMaster("local[*]")
}

Expand Down
20 changes: 17 additions & 3 deletions cpp-ch/local-engine/Storages/SubstraitSource/ParquetFormatFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <numeric>
#include <utility>

#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeNullable.h>
#include <Formats/FormatFactory.h>
#include <Formats/FormatSettings.h>
#include <IO/SeekableReadBuffer.h>
Expand All @@ -46,12 +46,13 @@ extern const int UNKNOWN_TYPE;

namespace local_engine
{

ParquetFormatFile::ParquetFormatFile(
const DB::ContextPtr & context_,
const substrait::ReadRel::LocalFiles::FileOrFiles & file_info_,
const ReadBufferBuilderPtr & read_buffer_builder_,
bool use_local_format_)
: FormatFile(context_, file_info_, read_buffer_builder_), use_local_format(use_local_format_)
: FormatFile(context_, file_info_, read_buffer_builder_), use_pageindex_reader(use_local_format_)
{
}

Expand Down Expand Up @@ -85,7 +86,7 @@ FormatFile::InputFormatPtr ParquetFormatFile::createInputFormat(const DB::Block
std::ranges::set_difference(total_row_group_indices, required_row_group_indices, std::back_inserter(skip_row_group_indices));

format_settings.parquet.skip_row_groups = std::unordered_set<int>(skip_row_group_indices.begin(), skip_row_group_indices.end());
if (use_local_format)
if (use_pageindex_reader && pageindex_reader_support(header))
res->input = std::make_shared<VectorizedParquetBlockInputFormat>(*(res->read_buffer), header, format_settings);
else
res->input = std::make_shared<DB::ParquetBlockInputFormat>(*(res->read_buffer), header, format_settings, 1, 8192);
Expand All @@ -112,6 +113,19 @@ std::optional<size_t> ParquetFormatFile::getTotalRows()
return total_rows;
}
}
bool ParquetFormatFile::pageindex_reader_support(const DB::Block & header)
{
const auto result = std::ranges::find_if(
header,
[](DB::ColumnWithTypeAndName const & col)
{
const DB::DataTypePtr type_not_nullable = DB::removeNullable(col.type);
const DB::WhichDataType which(type_not_nullable);
return DB::isArray(which) || DB::isMap(which) || DB::isTuple(which);
});

return result == header.end();
}

std::vector<RowGroupInformation> ParquetFormatFile::collectRequiredRowGroups(int & total_row_groups) const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ class ParquetFormatFile : public FormatFile

String getFileFormat() const override { return "Parquet"; }

static bool pageindex_reader_support(const DB::Block & header);

private:
bool use_local_format;
bool use_pageindex_reader;
std::mutex mutex;
std::optional<size_t> total_rows;

Expand Down
29 changes: 29 additions & 0 deletions cpp-ch/local-engine/tests/gtest_parquet_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* limitations under the License.
*/

#include <Storages/SubstraitSource/ParquetFormatFile.h>


#include "config.h"

#if USE_PARQUET
Expand Down Expand Up @@ -139,6 +142,32 @@ TEST(ParquetRead, ReadSchema)
readSchema("alltypes/alltypes_null.parquet");
}

TEST(ParquetRead, VerifyPageindexReaderSupport)
{
EXPECT_FALSE(local_engine::ParquetFormatFile::pageindex_reader_support(
toBlockRowType(local_engine::test::readParquetSchema(local_engine::test::data_file("alltypes/alltypes_notnull.parquet")))));
EXPECT_FALSE(local_engine::ParquetFormatFile::pageindex_reader_support(
toBlockRowType(local_engine::test::readParquetSchema(local_engine::test::data_file("alltypes/alltypes_null.parquet")))));


EXPECT_FALSE(local_engine::ParquetFormatFile::pageindex_reader_support(
toBlockRowType(local_engine::test::readParquetSchema(local_engine::test::data_file("array.parquet")))));
EXPECT_TRUE(local_engine::ParquetFormatFile::pageindex_reader_support(
toBlockRowType(local_engine::test::readParquetSchema(local_engine::test::data_file("date.parquet")))));
EXPECT_TRUE(local_engine::ParquetFormatFile::pageindex_reader_support(
toBlockRowType(local_engine::test::readParquetSchema(local_engine::test::data_file("datetime64.parquet")))));
EXPECT_TRUE(local_engine::ParquetFormatFile::pageindex_reader_support(
toBlockRowType(local_engine::test::readParquetSchema(local_engine::test::data_file("decimal.parquet")))));
EXPECT_TRUE(local_engine::ParquetFormatFile::pageindex_reader_support(
toBlockRowType(local_engine::test::readParquetSchema(local_engine::test::data_file("iris.parquet")))));
EXPECT_FALSE(local_engine::ParquetFormatFile::pageindex_reader_support(
toBlockRowType(local_engine::test::readParquetSchema(local_engine::test::data_file("map.parquet")))));
EXPECT_TRUE(local_engine::ParquetFormatFile::pageindex_reader_support(
toBlockRowType(local_engine::test::readParquetSchema(local_engine::test::data_file("sample.parquet")))));
EXPECT_FALSE(local_engine::ParquetFormatFile::pageindex_reader_support(
toBlockRowType(local_engine::test::readParquetSchema(local_engine::test::data_file("struct.parquet")))));
}

TEST(ParquetRead, ReadDataNotNull)
{
const std::map<String, Field> fields{
Expand Down
Loading