Skip to content

Commit

Permalink
[GLUTEN-7145][CH][PART]refactor for rel parsers (apache#7193)
Browse files Browse the repository at this point in the history
What changes were proposed in this pull request?
(Please fill in changes proposed in this fix)

Fixes: apache#7145

Refactor SerializedPlanParser::parseOp. RelParser don't need to call SerializedPlanParser from down to top at the parsing process

How was this patch tested?
(Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests)

unit tests

(If this patch involves UI changes, please attach a screenshot; otherwise, remove this)
lgbo-ustc authored and shamirchen committed Oct 14, 2024
1 parent 86fc749 commit 331eafc
Showing 35 changed files with 475 additions and 514 deletions.
1 change: 1 addition & 0 deletions cpp-ch/local-engine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ add_subdirectory(proto)
add_headers_and_sources(builder Builder)
add_headers_and_sources(join Join)
add_headers_and_sources(parser Parser)
add_headers_and_sources(parser Parser/RelParsers)
add_headers_and_sources(rewriter Rewriter)
add_headers_and_sources(storages Storages)
add_headers_and_sources(storages Storages/Output)
2 changes: 1 addition & 1 deletion cpp-ch/local-engine/Common/CHUtil.cpp
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@
#include <Functions/registerFunctions.h>
#include <IO/SharedThreadPools.h>
#include <Interpreters/JIT/CompiledExpressionCache.h>
#include <Parser/RelParser.h>
#include <Parser/RelParsers/RelParser.h>
#include <Parser/SerializedPlanParser.h>
#include <Parser/SubstraitParserUtils.h>
#include <Planner/PlannerActionsVisitor.h>
2 changes: 1 addition & 1 deletion cpp-ch/local-engine/Join/BroadCastJoinBuilder.cpp
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
#include <Compression/CompressedReadBuffer.h>
#include <Interpreters/TableJoin.h>
#include <Join/StorageJoinFromReadBuffer.h>
#include <Parser/JoinRelParser.h>
#include <Parser/RelParsers/JoinRelParser.h>
#include <Parser/TypeParser.h>
#include <QueryPipeline/ProfileInfo.h>
#include <Shuffle/ShuffleReader.h>
2 changes: 1 addition & 1 deletion cpp-ch/local-engine/Parser/AggregateFunctionParser.cpp
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
#include <DataTypes/DataTypeAggregateFunction.h>
#include <DataTypes/DataTypeTuple.h>
#include <Functions/FunctionHelpers.h>
#include <Parser/RelParser.h>
#include <Parser/RelParsers/RelParser.h>
#include <Parser/TypeParser.h>
#include <Common/CHUtil.h>
#include <Common/Exception.h>
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
*/
#pragma once
#include <Parser/AggregateFunctionParser.h>
#include <Parser/RelParser.h>
#include <Parser/RelParsers/RelParser.h>
#include <Poco/Logger.h>
#include <Common/logger_useful.h>

@@ -30,7 +30,7 @@ class AggregateRelParser : public RelParser
~AggregateRelParser() override = default;
DB::QueryPlanPtr
parse(DB::QueryPlanPtr query_plan, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_) override;
const substrait::Rel & getSingleInput(const substrait::Rel & rel) override { return rel.aggregate().input(); }
std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel & rel) override { return &rel.aggregate().input(); }

private:
struct AggregateInfo
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
* limitations under the License.
*/
#include "CrossRelParser.h"
#include <optional>

#include <Interpreters/CollectJoinOnKeysVisitor.h>
#include <Interpreters/GraceHashJoin.h>
@@ -73,25 +74,27 @@ CrossRelParser::parse(DB::QueryPlanPtr /*query_plan*/, const substrait::Rel & /*
throw Exception(ErrorCodes::LOGICAL_ERROR, "join node has 2 inputs, can't call parse().");
}

const substrait::Rel & CrossRelParser::getSingleInput(const substrait::Rel & /*rel*/)
{
throw Exception(ErrorCodes::LOGICAL_ERROR, "join node has 2 inputs, can't call getSingleInput().");
}

DB::QueryPlanPtr CrossRelParser::parseOp(const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack)
std::vector<const substrait::Rel *> CrossRelParser::getInputs(const substrait::Rel & rel)
{
const auto & join = rel.cross();
if (!join.has_left() || !join.has_right())
{
throw Exception(ErrorCodes::BAD_ARGUMENTS, "left table or right table is missing.");
}

rel_stack.push_back(&rel);
auto left_plan = getPlanParser()->parseOp(join.left(), rel_stack);
auto right_plan = getPlanParser()->parseOp(join.right(), rel_stack);
rel_stack.pop_back();
return {&join.left(), &join.right()};
}
std::optional<const substrait::Rel *> CrossRelParser::getSingleInput(const substrait::Rel & /*rel*/)
{
throw Exception(ErrorCodes::LOGICAL_ERROR, "join node has 2 inputs, can't call getSingleInput().");
}

return parseJoin(join, std::move(left_plan), std::move(right_plan));
DB::QueryPlanPtr
CrossRelParser::parse(std::vector<DB::QueryPlanPtr> & input_plans_, const substrait::Rel & rel, std::list<const substrait::Rel *> &)
{
assert(input_plans_.size() == 2);
const auto & join = rel.cross();
return parseJoin(join, std::move(input_plans_[0]), std::move(input_plans_[1]));
}

void CrossRelParser::renamePlanColumns(DB::QueryPlan & left, DB::QueryPlan & right, const StorageJoinFromReadBuffer & storage_join)
@@ -194,7 +197,8 @@ DB::QueryPlanPtr CrossRelParser::parseJoin(const substrait::CrossRel & join, DB:
else
{
JoinPtr hash_join = std::make_shared<HashJoin>(table_join, right->getCurrentDataStream().header.cloneEmpty());
QueryPlanStepPtr join_step = std::make_unique<DB::JoinStep>(left->getCurrentDataStream(), right->getCurrentDataStream(), hash_join, 8192, 1, false);
QueryPlanStepPtr join_step
= std::make_unique<DB::JoinStep>(left->getCurrentDataStream(), right->getCurrentDataStream(), hash_join, 8192, 1, false);
join_step->setStepDescription("CROSS_JOIN");
steps.emplace_back(join_step.get());
std::vector<QueryPlanPtr> plans;
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@
#pragma once

#include <memory>
#include <Parser/RelParser.h>
#include <optional>
#include <Parser/RelParsers/RelParser.h>
#include <substrait/algebra.pb.h>

namespace DB
@@ -37,12 +38,13 @@ class CrossRelParser : public RelParser
explicit CrossRelParser(SerializedPlanParser * plan_paser_);
~CrossRelParser() override = default;

DB::QueryPlanPtr parse(
std::vector<DB::QueryPlanPtr> & input_plans_, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_) override;
DB::QueryPlanPtr
parse(DB::QueryPlanPtr query_plan, const substrait::Rel & sort_rel, std::list<const substrait::Rel *> & rel_stack_) override;
parse(DB::QueryPlanPtr query_plan, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_) override;

DB::QueryPlanPtr parseOp(const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack) override;

const substrait::Rel & getSingleInput(const substrait::Rel & rel) override;
std::vector<const substrait::Rel *> getInputs(const substrait::Rel & rel) override;
std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel & rel) override;

private:
std::unordered_map<std::string, std::string> & function_mapping;
@@ -55,7 +57,11 @@ class CrossRelParser : public RelParser
void addConvertStep(TableJoin & table_join, DB::QueryPlan & left, DB::QueryPlan & right);
void addPostFilter(DB::QueryPlan & query_plan, const substrait::CrossRel & join);
bool applyJoinFilter(
DB::TableJoin & table_join, const substrait::CrossRel & join_rel, DB::QueryPlan & left, DB::QueryPlan & right, bool allow_mixed_condition);
DB::TableJoin & table_join,
const substrait::CrossRel & join_rel,
DB::QueryPlan & left,
DB::QueryPlan & right,
bool allow_mixed_condition);
};

}
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
#include <Core/ColumnWithTypeAndName.h>
#include <Operator/ExpandStep.h>
#include <Parser/ExpandField.h>
#include <Parser/RelParser.h>
#include <Parser/RelParsers/RelParser.h>
#include <Parser/SerializedPlanParser.h>
#include <Processors/QueryPlan/QueryPlan.h>
#include <Common/logger_useful.h>
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@
* limitations under the License.
*/
#pragma once
#include <Parser/RelParser.h>
#include <optional>
#include <Parser/RelParsers/RelParser.h>


namespace local_engine
@@ -29,6 +30,6 @@ class ExpandRelParser : public RelParser
DB::QueryPlanPtr
parse(DB::QueryPlanPtr query_plan, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_) override;

const substrait::Rel & getSingleInput(const substrait::Rel & rel) override { return rel.expand().input(); }
std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel & rel) override { return &rel.expand().input(); }
};
}
49 changes: 49 additions & 0 deletions cpp-ch/local-engine/Parser/RelParsers/FetchRelParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <memory>
#include <optional>
#include <Parser/SerializedPlanParser.h>
#include <Processors/QueryPlan/LimitStep.h>
#include "RelParser.h"
namespace local_engine
{
class FetchRelParser : public RelParser
{
public:
explicit FetchRelParser(SerializedPlanParser * plan_parser_) : RelParser(plan_parser_) { }
~FetchRelParser() override = default;

DB::QueryPlanPtr parse(DB::QueryPlanPtr query_plan, const substrait::Rel & rel, std::list<const substrait::Rel *> &)
{
const auto & limit = rel.fetch();
auto limit_step = std::make_unique<DB::LimitStep>(query_plan->getCurrentDataStream(), limit.count(), limit.offset());
limit_step->setStepDescription("LIMIT");
steps.push_back(limit_step.get());
query_plan->addStep(std::move(limit_step));
return query_plan;
}
std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel & rel) override { return &rel.fetch().input(); }
};

void registerFetchRelParser(RelParserFactory & factory)
{
auto builder = [](SerializedPlanParser * plan_parser_) { return std::make_unique<FetchRelParser>(plan_parser_); };
factory.registerBuilder(substrait::Rel::RelTypeCase::kFetch, builder);
}

}
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@

#pragma once

#include <Parser/RelParser.h>
#include <optional>
#include <Parser/RelParsers/RelParser.h>
#include <Poco/Logger.h>
#include <Common/logger_useful.h>

@@ -29,11 +30,12 @@ class FilterRelParser : public RelParser
explicit FilterRelParser(SerializedPlanParser * plan_paser_);
~FilterRelParser() override = default;

const substrait::Rel & getSingleInput(const substrait::Rel & rel) override { return rel.filter().input(); }
std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel & rel) override { return &rel.filter().input(); }

DB::QueryPlanPtr
parse(DB::QueryPlanPtr query_plan, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_) override;

private:
// Poco::Logger * logger = &Poco::Logger::get("ProjectRelParser");
};
};
}
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
* limitations under the License.
*/
#include "JoinRelParser.h"
#include <optional>

#include <Core/Block.h>
#include <Functions/FunctionFactory.h>
@@ -27,10 +28,10 @@
#include <Interpreters/TableJoin.h>
#include <Join/BroadCastJoinBuilder.h>
#include <Join/StorageJoinFromReadBuffer.h>
#include <Operator/EarlyStopStep.h>
#include <Parser/AdvancedParametersParseUtil.h>
#include <Parser/SerializedPlanParser.h>
#include <Parsers/ASTIdentifier.h>
#include <Operator/EarlyStopStep.h>
#include <Processors/QueryPlan/ExpressionStep.h>
#include <Processors/QueryPlan/FilterStep.h>
#include <Processors/QueryPlan/JoinStep.h>
@@ -56,8 +57,8 @@ namespace local_engine
{
std::shared_ptr<DB::TableJoin> createDefaultTableJoin(substrait::JoinRel_JoinType join_type, bool is_existence_join, ContextPtr & context)
{
auto table_join = std::make_shared<TableJoin>(
context->getSettingsRef(), context->getGlobalTemporaryVolume(), context->getTempDataOnDisk());
auto table_join
= std::make_shared<TableJoin>(context->getSettingsRef(), context->getGlobalTemporaryVolume(), context->getTempDataOnDisk());

std::pair<DB::JoinKind, DB::JoinStrictness> kind_and_strictness = JoinUtil::getJoinKindAndStrictness(join_type, is_existence_join);
table_join->setKind(kind_and_strictness.first);
@@ -79,25 +80,27 @@ JoinRelParser::parse(DB::QueryPlanPtr /*query_plan*/, const substrait::Rel & /*r
throw Exception(ErrorCodes::LOGICAL_ERROR, "join node has 2 inputs, can't call parse().");
}

const substrait::Rel & JoinRelParser::getSingleInput(const substrait::Rel & /*rel*/)
{
throw Exception(ErrorCodes::LOGICAL_ERROR, "join node has 2 inputs, can't call getSingleInput().");
}

DB::QueryPlanPtr JoinRelParser::parseOp(const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack)
std::vector<const substrait::Rel *> JoinRelParser::getInputs(const substrait::Rel & rel)
{
const auto & join = rel.join();
if (!join.has_left() || !join.has_right())
{
throw Exception(ErrorCodes::BAD_ARGUMENTS, "left table or right table is missing.");
}

rel_stack.push_back(&rel);
auto left_plan = getPlanParser()->parseOp(join.left(), rel_stack);
auto right_plan = getPlanParser()->parseOp(join.right(), rel_stack);
rel_stack.pop_back();
return {&join.left(), &join.right()};
}
std::optional<const substrait::Rel *> JoinRelParser::getSingleInput(const substrait::Rel & /*rel*/)
{
throw Exception(ErrorCodes::LOGICAL_ERROR, "join node has 2 inputs, can't call getSingleInput().");
}

return parseJoin(join, std::move(left_plan), std::move(right_plan));
DB::QueryPlanPtr JoinRelParser::parse(
std::vector<DB::QueryPlanPtr> & input_plans_, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_)
{
assert(input_plans_.size() == 2);
const auto & join = rel.join();
return parseJoin(join, std::move(input_plans_[0]), std::move(input_plans_[1]));
}

std::unordered_set<DB::JoinTableSide> JoinRelParser::extractTableSidesFromExpression(
@@ -282,13 +285,22 @@ DB::QueryPlanPtr JoinRelParser::parseJoin(const substrait::JoinRel & join, DB::Q
auto input_header = left->getCurrentDataStream().header;
DB::ActionsDAG filter_is_not_null_dag{input_header.getColumnsWithTypeAndName()};
// when is_null_aware_anti_join is true, there is only one join key
const auto * key_field = filter_is_not_null_dag.getInputs()[join.expression().scalar_function().arguments().at(0).value().selection().direct_reference().struct_field().field()];
const auto * key_field = filter_is_not_null_dag.getInputs()[join.expression()
.scalar_function()
.arguments()
.at(0)
.value()
.selection()
.direct_reference()
.struct_field()
.field()];

auto result_node = filter_is_not_null_dag.tryFindInOutputs(key_field->result_name);
// add a function isNotNull to filter the null key on the left side
const auto * cond_node = plan_parser->toFunctionNode(filter_is_not_null_dag, "isNotNull", {result_node});
filter_is_not_null_dag.addOrReplaceInOutputs(*cond_node);
auto filter_step = std::make_unique<FilterStep>(left->getCurrentDataStream(), std::move(filter_is_not_null_dag), cond_node->result_name, true);
auto filter_step = std::make_unique<FilterStep>(
left->getCurrentDataStream(), std::move(filter_is_not_null_dag), cond_node->result_name, true);
left->addStep(std::move(filter_step));
}
// other case: is_empty_hash_table, don't need to handle
@@ -342,8 +354,7 @@ DB::QueryPlanPtr JoinRelParser::parseJoin(const substrait::JoinRel & join, DB::Q
= couldRewriteToMultiJoinOnClauses(table_join->getOnlyClause(), join_on_clauses, join, left_header, right_header);
if (is_multi_join_on_clauses && join_config.prefer_multi_join_on_clauses && join_opt_info.right_table_rows > 0
&& join_opt_info.partitions_num > 0
&& join_opt_info.right_table_rows / join_opt_info.partitions_num
< join_config.multi_join_on_clauses_build_side_rows_limit)
&& join_opt_info.right_table_rows / join_opt_info.partitions_num < join_config.multi_join_on_clauses_build_side_rows_limit)
{
query_plan = buildMultiOnClauseHashJoin(table_join, std::move(left), std::move(right), join_on_clauses);
}
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
#include <unordered_set>
#include <Core/Joins.h>
#include <Interpreters/TableJoin.h>
#include <Parser/RelParser.h>
#include <Parser/RelParsers/RelParser.h>
#include <substrait/algebra.pb.h>

namespace DB
@@ -42,9 +42,11 @@ class JoinRelParser : public RelParser
DB::QueryPlanPtr
parse(DB::QueryPlanPtr query_plan, const substrait::Rel & sort_rel, std::list<const substrait::Rel *> & rel_stack_) override;

DB::QueryPlanPtr parseOp(const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack) override;
DB::QueryPlanPtr parse(
std::vector<DB::QueryPlanPtr> & input_plans_, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_) override;

const substrait::Rel & getSingleInput(const substrait::Rel & rel) override;
std::vector<const substrait::Rel *> getInputs(const substrait::Rel & rel) override;
std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel & rel) override;

private:
std::unordered_map<std::string, std::string> & function_mapping;
@@ -69,8 +71,8 @@ class JoinRelParser : public RelParser

void existenceJoinPostProject(DB::QueryPlan & plan, const DB::Names & left_input_cols);

static std::unordered_set<DB::JoinTableSide> extractTableSidesFromExpression(
const substrait::Expression & expr, const DB::Block & left_header, const DB::Block & right_header);
static std::unordered_set<DB::JoinTableSide>
extractTableSidesFromExpression(const substrait::Expression & expr, const DB::Block & left_header, const DB::Block & right_header);

bool couldRewriteToMultiJoinOnClauses(
const DB::TableJoin::JoinOnClause & prefix_clause,
Original file line number Diff line number Diff line change
@@ -17,9 +17,10 @@
#pragma once

#include <memory>
#include <optional>
#include <substrait/algebra.pb.h>

#include <Parser/RelParser.h>
#include <Parser/RelParsers/RelParser.h>

namespace DB
{
@@ -50,7 +51,7 @@ class MergeTreeRelParser : public RelParser
DB::QueryPlanPtr parseReadRel(
DB::QueryPlanPtr query_plan, const substrait::ReadRel & read_rel, const substrait::ReadRel::ExtensionTable & extension_table);

const substrait::Rel & getSingleInput(const substrait::Rel &) override
std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel &) override
{
throw Exception(ErrorCodes::LOGICAL_ERROR, "MergeTreeRelParser can't call getSingleInput().");
}
Original file line number Diff line number Diff line change
@@ -15,9 +15,10 @@
* limitations under the License.
*/
#pragma once
#include <optional>
#include <Core/Block.h>
#include <Core/SortDescription.h>
#include <Parser/RelParser.h>
#include <Parser/RelParsers/RelParser.h>
#include <Poco/Logger.h>

namespace local_engine
@@ -29,7 +30,7 @@ class ProjectRelParser : public RelParser
{
ActionsDAG before_array_join; /// Optional
ActionsDAG array_join;
ActionsDAG after_array_join; /// Optional
ActionsDAG after_array_join; /// Optional
};

explicit ProjectRelParser(SerializedPlanParser * plan_paser_);
@@ -44,21 +45,21 @@ class ProjectRelParser : public RelParser
DB::QueryPlanPtr parseProject(DB::QueryPlanPtr query_plan, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_);
DB::QueryPlanPtr parseGenerate(DB::QueryPlanPtr query_plan, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_);

static const DB::ActionsDAG::Node * findArrayJoinNode(const ActionsDAG& actions_dag);
static const DB::ActionsDAG::Node * findArrayJoinNode(const ActionsDAG & actions_dag);

/// Split actions_dag of generate rel into 3 parts: before array join + during array join + after array join
static SplittedActionsDAGs splitActionsDAGInGenerate(const ActionsDAG& actions_dag);
static SplittedActionsDAGs splitActionsDAGInGenerate(const ActionsDAG & actions_dag);

bool isReplicateRows(substrait::GenerateRel rel);

DB::QueryPlanPtr parseReplicateRows(QueryPlanPtr query_plan, substrait::GenerateRel generate_rel);

const substrait::Rel & getSingleInput(const substrait::Rel & rel) override
std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel & rel) override
{
if (rel.has_generate())
return rel.generate().input();
return &rel.generate().input();

return rel.project().input();
return &rel.project().input();
}
};
}
136 changes: 136 additions & 0 deletions cpp-ch/local-engine/Parser/RelParsers/ReadRelParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "ReadRelParser.h"
#include <memory>

namespace DB::ErrorCodes
{
extern const int LOGICAL_ERROR;
}

namespace local_engine
{
DB::QueryPlanPtr ReadRelParser::parse(DB::QueryPlanPtr query_plan, const substrait::Rel & rel, std::list<const substrait::Rel *> &)
{
if (query_plan)
throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, "Source node's input plan should be null");
const auto & read = rel.read();
if (read.has_local_files() || (!read.has_extension_table() && !isReadFromMergeTree(read)))
{
assert(read.has_base_schema());
DB::QueryPlanStepPtr read_step;
if (isReadRelFromJava(read))
read_step = parseReadRelWithJavaIter(read);
else
read_step = parseReadRelWithLocalFile(read);
query_plan = std::make_unique<DB::QueryPlan>();
steps.emplace_back(read_step.get());
query_plan->addStep(std::move(read_step));

if (getContext()->getSettingsRef().max_threads > 1)
{
auto buffer_step = std::make_unique<BlocksBufferPoolStep>(query_plan->getCurrentDataStream());
steps.emplace_back(buffer_step.get());
query_plan->addStep(std::move(buffer_step));
}
}
else
{
substrait::ReadRel::ExtensionTable extension_table;
if (read.has_extension_table())
extension_table = read.extension_table();
else
{
extension_table = BinaryToMessage<substrait::ReadRel::ExtensionTable>(split_info);
logDebugMessage(extension_table, "extension_table");
}
MergeTreeRelParser mergeTreeParser(getPlanParser(), getContext());
query_plan = mergeTreeParser.parseReadRel(std::make_unique<DB::QueryPlan>(), read, extension_table);
steps = mergeTreeParser.getSteps();
}
return query_plan;
}

bool ReadRelParser::isReadRelFromJava(const substrait::ReadRel & rel)
{
return rel.has_local_files() && rel.local_files().items().size() == 1
&& rel.local_files().items().at(0).uri_file().starts_with("iterator");
}

bool ReadRelParser::isReadFromMergeTree(const substrait::ReadRel & rel)
{
assert(rel.has_advanced_extension());
bool is_read_from_merge_tree;
google::protobuf::StringValue optimization;
optimization.ParseFromString(rel.advanced_extension().optimization().value());
ReadBufferFromString in(optimization.value());
if (!checkString("isMergeTree=", in))
return false;
readBoolText(is_read_from_merge_tree, in);
assertChar('\n', in);
return is_read_from_merge_tree;
}

DB::QueryPlanStepPtr ReadRelParser::parseReadRelWithJavaIter(const substrait::ReadRel & rel)
{
GET_JNIENV(env)
SCOPE_EXIT({CLEAN_JNIENV});
auto first_block = SourceFromJavaIter::peekBlock(env, input_iter);

/// Try to decide header from the first block read from Java iterator. Thus AggregateFunction with parameters has more precise types.
auto header = first_block.has_value() ? first_block->cloneEmpty() : TypeParser::buildBlockFromNamedStruct(rel.base_schema());
auto source = std::make_shared<SourceFromJavaIter>(
getContext(), std::move(header), input_iter, is_input_iter_materialize, std::move(first_block));

QueryPlanStepPtr source_step = std::make_unique<ReadFromPreparedSource>(Pipe(source));
source_step->setStepDescription("Read From Java Iter");
return source_step;
}

QueryPlanStepPtr ReadRelParser::parseReadRelWithLocalFile(const substrait::ReadRel & rel)
{
auto header = TypeParser::buildBlockFromNamedStruct(rel.base_schema());
substrait::ReadRel::LocalFiles local_files;
if (rel.has_local_files())
local_files = rel.local_files();
else
{
local_files = BinaryToMessage<substrait::ReadRel::LocalFiles>(getPlanParser()->nextSplitInfo());
logDebugMessage(local_files, "local_files");
}
auto source = std::make_shared<SubstraitFileSource>(getContext(), header, local_files);
auto source_pipe = Pipe(source);
auto source_step = std::make_unique<SubstraitFileSourceStep>(getContext(), std::move(source_pipe), "substrait local files");
source_step->setStepDescription("read local files");
if (rel.has_filter())
{
DB::ActionsDAG actions_dag{blockToNameAndTypeList(header)};
const DB::ActionsDAG::Node * filter_node = parseExpression(actions_dag, rel.filter());
actions_dag.addOrReplaceInOutputs(*filter_node);
assert(filter_node == &(actions_dag.findInOutputs(filter_node->result_name)));
source_step->addFilter(std::move(actions_dag), filter_node->result_name);
}
return source_step;
}

void registerReadRelParser(RelParserFactory & factory)
{
auto builder = [](SerializedPlanParser * plan_parser_) { return std::make_unique<ReadRelParser>(plan_parser_); };
factory.registerBuilder(substrait::Rel::RelTypeCase::kRead, builder);
}
}
71 changes: 71 additions & 0 deletions cpp-ch/local-engine/Parser/RelParsers/ReadRelParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <Core/Block.h>
#include <Core/Settings.h>
#include <Interpreters/Context.h>
#include <Operator/BlocksBufferPoolTransform.h>
#include <Parser/RelParsers/MergeTreeRelParser.h>
#include <Parser/SerializedPlanParser.h>
#include <Parser/SubstraitParserUtils.h>
#include <Parser/TypeParser.h>
#include <Processors/QueryPlan/ReadFromPreparedSource.h>
#include <Storages/SourceFromJavaIter.h>
#include <Storages/SubstraitSource/SubstraitFileSource.h>
#include <Storages/SubstraitSource/SubstraitFileSourceStep.h>
#include <google/protobuf/wrappers.pb.h>
#include <Common/BlockTypeUtils.h>
#include <Common/JNIUtils.h>

namespace local_engine
{
class ReadRelParser : public RelParser
{
public:
explicit ReadRelParser(SerializedPlanParser * plan_parser_) : RelParser(plan_parser_) { }
~ReadRelParser() override = default;

DB::QueryPlanPtr
parse(std::vector<DB::QueryPlanPtr> &, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_) override
{
DB::QueryPlanPtr query_plan;
return parse(std::move(query_plan), rel, rel_stack_);
}

DB::QueryPlanPtr parse(DB::QueryPlanPtr query_plan, const substrait::Rel & rel, std::list<const substrait::Rel *> &) override;
// This is source node, there is no input
std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel & rel) override { return {}; }

bool isReadRelFromJava(const substrait::ReadRel & rel);
bool isReadFromMergeTree(const substrait::ReadRel & rel);

void setInputIter(jobject input_iter_, bool is_materialze)
{
input_iter = input_iter_;
is_input_iter_materialize = is_materialze;
}

void setSplitInfo(String split_info_) { split_info = split_info_; }

private:
jobject input_iter;
bool is_input_iter_materialize;
String split_info;
DB::QueryPlanStepPtr parseReadRelWithJavaIter(const substrait::ReadRel & rel);
QueryPlanStepPtr parseReadRelWithLocalFile(const substrait::ReadRel & rel);
};
}
Original file line number Diff line number Diff line change
@@ -22,9 +22,10 @@
#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <DataTypes/DataTypeAggregateFunction.h>
#include <DataTypes/IDataType.h>
#include <Poco/Logger.h>
#include <Poco/StringTokenizer.h>
#include <Common/Exception.h>

#include <Common/logger_useful.h>

namespace DB
{
@@ -37,6 +38,14 @@ extern const int LOGICAL_ERROR;

namespace local_engine
{

std::vector<const substrait::Rel *> RelParser::getInputs(const substrait::Rel & rel)
{
auto input = getSingleInput(rel);
if (!input)
return {};
return {*input};
}
AggregateFunctionPtr RelParser::getAggregateFunction(
const String & name, DB::DataTypes arg_types, DB::AggregateFunctionProperties & properties, const DB::Array & parameters)
{
@@ -80,13 +89,12 @@ std::optional<String> RelParser::parseFunctionName(UInt32 function_ref, const su
}
return plan_parser->getFunctionName(*sigature_name, function);
}
DB::QueryPlanPtr RelParser::parseOp(const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack)

DB::QueryPlanPtr
RelParser::parse(std::vector<DB::QueryPlanPtr> & input_plans_, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_)
{
SerializedPlanParser & planParser = *getPlanParser();
rel_stack.push_back(&rel);
auto query_plan = planParser.parseOp(getSingleInput(rel), rel_stack);
rel_stack.pop_back();
return parse(std::move(query_plan), rel, rel_stack);
assert(input_plans_.size() == 1);
return parse(std::move(input_plans_[0]), rel, rel_stack_);
}

std::map<std::string, std::string>
@@ -160,6 +168,8 @@ void registerProjectRelParser(RelParserFactory & factory);
void registerJoinRelParser(RelParserFactory & factory);
void registerFilterRelParser(RelParserFactory & factory);
void registerCrossRelParser(RelParserFactory & factory);
void registerFetchRelParser(RelParserFactory & factory);
void registerReadRelParser(RelParserFactory & factory);

void registerRelParsers()
{
@@ -173,5 +183,7 @@ void registerRelParsers()
registerJoinRelParser(factory);
registerCrossRelParser(factory);
registerFilterRelParser(factory);
registerFetchRelParser(factory);
registerReadRelParser(factory);
}
}
Original file line number Diff line number Diff line change
@@ -39,8 +39,10 @@ class RelParser
virtual DB::QueryPlanPtr
parse(DB::QueryPlanPtr current_plan_, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_)
= 0;
virtual DB::QueryPlanPtr parseOp(const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack);
virtual const substrait::Rel & getSingleInput(const substrait::Rel & rel) = 0;
virtual DB::QueryPlanPtr
parse(std::vector<DB::QueryPlanPtr> & input_plans_, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_);
virtual std::vector<const substrait::Rel *> getInputs(const substrait::Rel & rel);
virtual std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel & rel) = 0;
const std::vector<IQueryPlanStep *> & getSteps() const { return steps; }

static AggregateFunctionPtr getAggregateFunction(
@@ -59,12 +61,12 @@ class RelParser
// Get coresponding function name in ClickHouse.
std::optional<String> parseFunctionName(UInt32 function_ref, const substrait::Expression_ScalarFunction & function);

const DB::ActionsDAG::Node * parseArgument(ActionsDAG& action_dag, const substrait::Expression & rel)
const DB::ActionsDAG::Node * parseArgument(ActionsDAG & action_dag, const substrait::Expression & rel)
{
return plan_parser->parseExpression(action_dag, rel);
}

const DB::ActionsDAG::Node * parseExpression(ActionsDAG& action_dag, const substrait::Expression & rel)
const DB::ActionsDAG::Node * parseExpression(ActionsDAG & action_dag, const substrait::Expression & rel)
{
return plan_parser->parseExpression(action_dag, rel);
}
@@ -77,13 +79,15 @@ class RelParser
std::vector<IQueryPlanStep *> steps;

const ActionsDAG::Node *
buildFunctionNode(ActionsDAG& action_dag, const String & function, const DB::ActionsDAG::NodeRawConstPtrs & args)
buildFunctionNode(ActionsDAG & action_dag, const String & function, const DB::ActionsDAG::NodeRawConstPtrs & args)
{
return plan_parser->toFunctionNode(action_dag, function, args);
}

static std::map<std::string, std::string> parseFormattedRelAdvancedOptimization(const substrait::extensions::AdvancedExtension &advanced_extension);
static std::string getStringConfig(const std::map<std::string, std::string> & configs, const std::string & key, const std::string & default_value = "");
static std::map<std::string, std::string>
parseFormattedRelAdvancedOptimization(const substrait::extensions::AdvancedExtension & advanced_extension);
static std::string
getStringConfig(const std::map<std::string, std::string> & configs, const std::string & key, const std::string & default_value = "");

SerializedPlanParser * plan_parser;
};
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
#include "SortRelParser.h"

#include <Common/GlutenConfig.h>
#include <Parser/RelParser.h>
#include <Parser/RelParsers/RelParser.h>
#include <Processors/QueryPlan/SortingStep.h>
#include <Common/logger_useful.h>
#include <Common/QueryContext.h>
Original file line number Diff line number Diff line change
@@ -15,9 +15,10 @@
* limitations under the License.
*/
#pragma once
#include <optional>
#include <Core/Block.h>
#include <Core/SortDescription.h>
#include <Parser/RelParser.h>
#include <Parser/RelParsers/RelParser.h>
#include <google/protobuf/repeated_field.h>
namespace local_engine
{
@@ -32,7 +33,7 @@ class SortRelParser : public RelParser
static DB::SortDescription
parseSortDescription(const google::protobuf::RepeatedPtrField<substrait::SortField> & sort_fields, const DB::Block & header);

const substrait::Rel & getSingleInput(const substrait::Rel & rel) override { return rel.sort().input(); }
std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel & rel) override { return &rel.sort().input(); }

private:
size_t parseLimit(std::list<const substrait::Rel *> & rel_stack_);
Original file line number Diff line number Diff line change
@@ -16,15 +16,11 @@
*/

#include "WindowGroupLimitRelParser.h"
#include <Interpreters/ActionsDAG.h>
#include <Operator/WindowGroupLimitStep.h>
#include <Parser/AdvancedParametersParseUtil.h>
#include <Parser/SortRelParser.h>
#include <Parser/WindowGroupLimitRelParser.h>
#include <Processors/QueryPlan/ExpressionStep.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/wrappers.pb.h>
#include "AdvancedParametersParseUtil.h"

namespace DB::ErrorCodes
{
Original file line number Diff line number Diff line change
@@ -15,13 +15,8 @@
* limitations under the License.
*/
#pragma once
#include <unordered_map>
#include <Core/Field.h>
#include <Core/SortDescription.h>
#include <DataTypes/IDataType.h>
#include <Interpreters/WindowDescription.h>
#include <Parser/AggregateFunctionParser.h>
#include <Parser/RelParser.h>
#include <optional>
#include <Parser/RelParsers/RelParser.h>
#include <Parser/SerializedPlanParser.h>
#include <Processors/QueryPlan/QueryPlan.h>
#include <Poco/Logger.h>
@@ -40,7 +35,7 @@ class WindowGroupLimitRelParser : public RelParser
~WindowGroupLimitRelParser() override = default;
DB::QueryPlanPtr
parse(DB::QueryPlanPtr current_plan_, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_) override;
const substrait::Rel & getSingleInput(const substrait::Rel & rel) override { return rel.windowgrouplimit().input(); }
std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel & rel) override { return &rel.windowgrouplimit().input(); }

private:
DB::QueryPlanPtr current_plan;
Original file line number Diff line number Diff line change
@@ -29,8 +29,8 @@
#include <IO/WriteBufferFromString.h>
#include <Interpreters/ActionsDAG.h>
#include <Interpreters/WindowDescription.h>
#include <Parser/RelParser.h>
#include <Parser/SortRelParser.h>
#include <Parser/RelParsers/RelParser.h>
#include <Parser/RelParsers/SortRelParser.h>
#include <Parser/TypeParser.h>
#include <Processors/QueryPlan/ExpressionStep.h>
#include <Processors/QueryPlan/WindowStep.h>
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
#include <DataTypes/IDataType.h>
#include <Interpreters/WindowDescription.h>
#include <Parser/AggregateFunctionParser.h>
#include <Parser/RelParser.h>
#include <Parser/RelParsers/RelParser.h>
#include <Processors/QueryPlan/QueryPlan.h>
#include <Poco/Logger.h>
#include <Common/logger_useful.h>
@@ -35,7 +35,7 @@ class WindowRelParser : public RelParser
~WindowRelParser() override = default;
DB::QueryPlanPtr
parse(DB::QueryPlanPtr current_plan_, const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack_) override;
const substrait::Rel & getSingleInput(const substrait::Rel & rel) override { return rel.window().input(); }
std::optional<const substrait::Rel *> getSingleInput(const substrait::Rel & rel) override { return &rel.window().input(); }

private:
struct WindowInfo
File renamed without changes.
408 changes: 51 additions & 357 deletions cpp-ch/local-engine/Parser/SerializedPlanParser.cpp

Large diffs are not rendered by default.

45 changes: 13 additions & 32 deletions cpp-ch/local-engine/Parser/SerializedPlanParser.h
Original file line number Diff line number Diff line change
@@ -90,18 +90,19 @@ class SerializedPlanParser
///
std::unique_ptr<LocalExecutor> createExecutor(const std::string_view plan);

DB::QueryPlanStepPtr parseReadRealWithLocalFile(const substrait::ReadRel & rel);
DB::QueryPlanStepPtr parseReadRealWithJavaIter(const substrait::ReadRel & rel);

static bool isReadRelFromJava(const substrait::ReadRel & rel);
static bool isReadFromMergeTree(const substrait::ReadRel & rel);

void addInputIter(jobject iter, bool materialize_input)
{
input_iters.emplace_back(iter);
materialize_inputs.emplace_back(materialize_input);
}

std::pair<jobject, bool> getInputIter(size_t index)
{
if (index > input_iters.size())
throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, "Index({}) is overflow input_iters's size({})", index, input_iters.size());
return {input_iters[index], materialize_inputs[index]};
}

void addSplitInfo(std::string && split_info) { split_infos.emplace_back(std::move(split_info)); }

int nextSplitInfoIndex()
@@ -115,6 +116,12 @@ class SerializedPlanParser
return split_info_index++;
}

const String & nextSplitInfo()
{
auto next_index = nextSplitInfoIndex();
return split_infos.at(next_index);
}

void parseExtensions(const ::google::protobuf::RepeatedPtrField<substrait::extensions::SimpleExtensionDeclaration> & extensions);
DB::ActionsDAG expressionsToActionsDAG(
const std::vector<substrait::Expression> & expressions, const DB::Block & header, const DB::Block & read_schema);
@@ -133,8 +140,6 @@ class SerializedPlanParser

private:
DB::QueryPlanPtr parseOp(const substrait::Rel & rel, std::list<const substrait::Rel *> & rel_stack);
void
collectJoinKeys(const substrait::Expression & condition, std::vector<std::pair<int32_t, int32_t>> & join_keys, int32_t right_key_start);

void parseFunctionOrExpression(
const substrait::Expression & rel, std::string & result_name, DB::ActionsDAG & actions_dag, bool keep_result = false);
@@ -185,34 +190,10 @@ class SerializedPlanParser
int split_info_index = 0;
std::vector<bool> materialize_inputs;
ContextPtr context;
// for parse rel node, collect steps from a rel node
std::vector<IQueryPlanStep *> temp_step_collection;
std::vector<RelMetricPtr> metrics;

public:
const ActionsDAG::Node * addColumn(DB::ActionsDAG & actions_dag, const DataTypePtr & type, const Field & field);
};

class ASTParser
{
public:
explicit ASTParser(
const ContextPtr & context_, std::unordered_map<std::string, std::string> & function_mapping_, SerializedPlanParser * plan_parser_)
: context(context_), function_mapping(function_mapping_), plan_parser(plan_parser_)
{
}

~ASTParser() = default;

ASTPtr parseToAST(const Names & names, const substrait::Expression & rel);
ActionsDAG convertToActions(const NamesAndTypesList & name_and_types, const ASTPtr & ast) const;

private:
ContextPtr context;
std::unordered_map<std::string, std::string> function_mapping;
SerializedPlanParser * plan_parser;

void parseFunctionArgumentsToAST(const Names & names, const substrait::Expression_ScalarFunction & scalar_function, ASTs & ast_args);
ASTPtr parseArgumentToAST(const Names & names, const substrait::Expression & rel);
};
}
4 changes: 2 additions & 2 deletions cpp-ch/local-engine/Parser/TypeParser.cpp
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
#include <DataTypes/DataTypesNumber.h>
#include <Parser/AggregateFunctionParser.h>
#include <Parser/FunctionParser.h>
#include <Parser/RelParser.h>
#include <Parser/RelParsers/RelParser.h>
#include <Parser/SerializedPlanParser.h>
#include <Parser/TypeParser.h>
#include <Poco/StringTokenizer.h>
@@ -334,4 +334,4 @@ DB::DataTypePtr TypeParser::tryWrapNullable(substrait::Type_Nullability nullable
return std::make_shared<DB::DataTypeNullable>(nested_type);
return nested_type;
}
}
}
51 changes: 22 additions & 29 deletions cpp-ch/local-engine/local_engine_jni.cpp
Original file line number Diff line number Diff line change
@@ -23,13 +23,14 @@
#include <DataTypes/DataTypeNullable.h>
#include <Join/BroadCastJoinBuilder.h>
#include <Parser/CHColumnToSparkRow.h>
#include <Parser/MergeTreeRelParser.h>
#include <Parser/RelParser.h>
#include <Parser/SerializedPlanParser.h>
#include <Parser/LocalExecutor.h>
#include <Parser/RelParsers/MergeTreeRelParser.h>
#include <Parser/RelParsers/RelParser.h>
#include <Parser/RelParsers/WriteRelParser.h>
#include <Parser/SerializedPlanParser.h>
#include <Parser/SparkRowToCHColumn.h>
#include <Parser/SubstraitParserUtils.h>
#include <Parser/WriteRelParser.h>
#include <Processors/Executors/PipelineExecutor.h>
#include <Shuffle/NativeSplitter.h>
#include <Shuffle/NativeWriterInMemory.h>
#include <Shuffle/PartitionWriter.h>
@@ -53,12 +54,10 @@
#include <Poco/Logger.h>
#include <Poco/StringTokenizer.h>
#include <Common/CHUtil.h>
#include <Common/ErrorCodes.h>
#include <Common/ExceptionUtils.h>
#include <Common/JNIUtils.h>
#include <Common/QueryContext.h>
#include <Common/ErrorCodes.h>
#include <Processors/Executors/PipelineExecutor.h>
#include <Storages/Cache/CacheManager.h>

#ifdef __cplusplus
namespace DB
@@ -515,18 +514,15 @@ JNIEXPORT jlong Java_org_apache_gluten_vectorized_CHNativeBlock_nativeTotalBytes
LOCAL_ENGINE_JNI_METHOD_END(env, -1)
}

JNIEXPORT jobject Java_org_apache_gluten_vectorized_CHNativeBlock_nativeBlockStats(JNIEnv * env, jobject obj, jlong block_address, jint column_position)
JNIEXPORT jobject
Java_org_apache_gluten_vectorized_CHNativeBlock_nativeBlockStats(JNIEnv * env, jobject obj, jlong block_address, jint column_position)
{
LOCAL_ENGINE_JNI_METHOD_START
DB::Block * block = reinterpret_cast<DB::Block *>(block_address);
auto col = getColumnFromColumnVector(env, obj, block_address, column_position);
if (!col.column->isNullable())
{
jobject block_stats = env->NewObject(
block_stats_class,
block_stats_constructor,
block->rows(),
false);
jobject block_stats = env->NewObject(block_stats_class, block_stats_constructor, block->rows(), false);
return block_stats;
}
else
@@ -535,10 +531,7 @@ JNIEXPORT jobject Java_org_apache_gluten_vectorized_CHNativeBlock_nativeBlockSta
const auto & null_map_data = nullable->getNullMapData();

jobject block_stats = env->NewObject(
block_stats_class,
block_stats_constructor,
block->rows(),
!DB::memoryIsZero(null_map_data.data(), 0, null_map_data.size()));
block_stats_class, block_stats_constructor, block->rows(), !DB::memoryIsZero(null_map_data.data(), 0, null_map_data.size()));
return block_stats;
}
LOCAL_ENGINE_JNI_METHOD_END(env, nullptr)
@@ -573,12 +566,8 @@ JNIEXPORT void Java_org_apache_gluten_vectorized_CHStreamReader_nativeClose(JNIE
LOCAL_ENGINE_JNI_METHOD_END(env, )
}

local_engine::SplitterHolder * buildAndExecuteShuffle(JNIEnv * env,
jobject iter,
const String & name,
const local_engine::SplitOptions& options,
jobject rss_pusher = nullptr
)
local_engine::SplitterHolder * buildAndExecuteShuffle(
JNIEnv * env, jobject iter, const String & name, const local_engine::SplitOptions & options, jobject rss_pusher = nullptr)
{
auto current_executor = local_engine::LocalExecutor::getCurrentExecutor();
local_engine::SplitterHolder * splitter = nullptr;
@@ -592,7 +581,8 @@ local_engine::SplitterHolder * buildAndExecuteShuffle(JNIEnv * env,
{
/// Try to decide header from the first block read from Java iterator.
auto header = first_block.value().cloneEmpty();
splitter = new local_engine::SplitterHolder{.exchange_manager = std::make_unique<local_engine::SparkExchangeManager>(header, name, options, rss_pusher)};
splitter = new local_engine::SplitterHolder{
.exchange_manager = std::make_unique<local_engine::SparkExchangeManager>(header, name, options, rss_pusher)};
splitter->exchange_manager->initSinks(1);
splitter->exchange_manager->pushBlock(first_block.value());
first_block = std::nullopt;
@@ -604,14 +594,18 @@ local_engine::SplitterHolder * buildAndExecuteShuffle(JNIEnv * env,
}
else
// empty iterator
splitter = new local_engine::SplitterHolder{.exchange_manager = std::make_unique<local_engine::SparkExchangeManager>(DB::Block(), name, options, rss_pusher)};
splitter = new local_engine::SplitterHolder{
.exchange_manager = std::make_unique<local_engine::SparkExchangeManager>(DB::Block(), name, options, rss_pusher)};
}
else
{
splitter = new local_engine::SplitterHolder{.exchange_manager = std::make_unique<local_engine::SparkExchangeManager>(current_executor.value()->getHeader().cloneEmpty(), name, options, rss_pusher)};
splitter = new local_engine::SplitterHolder{
.exchange_manager = std::make_unique<local_engine::SparkExchangeManager>(
current_executor.value()->getHeader().cloneEmpty(), name, options, rss_pusher)};
// TODO support multiple sinks
splitter->exchange_manager->initSinks(1);
current_executor.value()->setSinks([&](auto & pipeline_builder) { splitter->exchange_manager->setSinksToPipeline(pipeline_builder);});
current_executor.value()->setSinks([&](auto & pipeline_builder)
{ splitter->exchange_manager->setSinksToPipeline(pipeline_builder); });
// execute pipeline
current_executor.value()->execute();
}
@@ -775,8 +769,7 @@ JNIEXPORT jobject Java_org_apache_gluten_vectorized_CHShuffleSplitterJniWrapper_
result.total_serialize_time,
result.total_rows,
result.total_blocks,
result.wall_time
);
result.wall_time);

return split_result;
LOCAL_ENGINE_JNI_METHOD_END(env, nullptr)

0 comments on commit 331eafc

Please sign in to comment.