-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
179 additions
and
17 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// 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 "dict_sink_operator.h" | ||
|
||
#include "common/status.h" | ||
#include "vec/functions/dictionary_factory.h" | ||
#include "vec/functions/hash_map_dictionary.h" | ||
#include "vec/functions/ip_address_dictionary.h" | ||
|
||
namespace doris::pipeline { | ||
#include "common/compile_check_begin.h" | ||
Status DictSinkLocalState::load_dict(RuntimeState* state) { | ||
if (_dict_input_block.empty()) { | ||
return Status::OK(); | ||
} | ||
|
||
auto& p = _parent->cast<DictSinkOperatorX>(); | ||
|
||
auto input_block = _dict_input_block.to_block(); | ||
auto key_data = input_block.get_by_position(p.key_column_id); | ||
|
||
vectorized::ColumnsWithTypeAndName attribute_data; | ||
std::string dict_name = p.dictionary_name; | ||
for (int64_t i = 0; i < p.attribute_column_ids.size(); i++) { | ||
auto att_col_id = p.attribute_column_ids[i]; | ||
auto att_name = p.attribute_name[i]; | ||
auto att_data = input_block.get_by_position(att_col_id); | ||
att_data.name = att_name; | ||
attribute_data.push_back(att_data); | ||
} | ||
|
||
vectorized::DictionaryPtr dict = nullptr; | ||
|
||
switch (p.layout_type) { | ||
case TDictLayoutType::type::IP_TRIE: { | ||
dict = create_ip_trie_dict_from_column(dict_name, key_data, attribute_data); | ||
break; | ||
} | ||
case TDictLayoutType::type::HASH_MAP: { | ||
dict = create_hash_map_dict_from_column(dict_name, key_data, attribute_data); | ||
break; | ||
} | ||
default: | ||
return Status::InternalError("Unknown layout type"); | ||
} | ||
if (dict == nullptr) { | ||
return Status::InternalError("Failed to create dictionary"); | ||
} | ||
ExecEnv::GetInstance()->dict_factory()->register_dict(dict); | ||
return Status::OK(); | ||
} | ||
|
||
DictSinkOperatorX::DictSinkOperatorX(int operator_id, const TDictSink& dict_sink) | ||
: DataSinkOperatorX(operator_id, 0), | ||
dictionary_id(dict_sink.dictionary_id), | ||
version_id(dict_sink.version_id), | ||
dictionary_name(dict_sink.dictionary_name), | ||
key_column_id(dict_sink.key_column_id), | ||
attribute_column_ids(dict_sink.attribute_column_ids), | ||
attribute_name(dict_sink.attribute_name), | ||
layout_type(dict_sink.layout_type) {} | ||
|
||
Status DictSinkOperatorX::open(RuntimeState* state) { | ||
if (attribute_column_ids.size() != attribute_name.size()) { | ||
return Status::InternalError("attribute_column_ids.size() != attribute_name.size()"); | ||
} | ||
return Status::OK(); | ||
} | ||
|
||
Status DictSinkOperatorX::sink(RuntimeState* state, vectorized::Block* in_block, bool eos) { | ||
auto& local_state = get_local_state(state); | ||
SCOPED_TIMER(local_state.exec_time_counter()); | ||
COUNTER_UPDATE(local_state.rows_input_counter(), (int64_t)in_block->rows()); | ||
|
||
if (local_state._dict_input_block.empty()) { | ||
local_state._dict_input_block = in_block->clone_empty(); | ||
} | ||
|
||
RETURN_IF_ERROR(local_state._dict_input_block.merge(std::move(*in_block))); | ||
|
||
if (eos) { | ||
RETURN_IF_ERROR(local_state.load_dict(state)); | ||
} | ||
|
||
return Status::OK(); | ||
} | ||
|
||
} // namespace doris::pipeline | ||
#include "common/compile_check_end.h" |
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,62 @@ | ||
// 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 <gen_cpp/DataSinks_types.h> | ||
|
||
#include <cstdint> | ||
|
||
#include "operator.h" | ||
|
||
namespace doris::pipeline { | ||
#include "common/compile_check_begin.h" | ||
class DictSinkLocalState final : public PipelineXSinkLocalState<BasicSharedState> { | ||
ENABLE_FACTORY_CREATOR(DictSinkLocalState); | ||
using Base = PipelineXSinkLocalState<BasicSharedState>; | ||
|
||
public: | ||
DictSinkLocalState(DataSinkOperatorXBase* parent, RuntimeState* state) : Base(parent, state) {} | ||
|
||
private: | ||
Status load_dict(RuntimeState* state); | ||
friend class DictSinkOperatorX; | ||
|
||
vectorized::MutableBlock _dict_input_block; | ||
}; | ||
|
||
class DictSinkOperatorX final : public DataSinkOperatorX<DictSinkLocalState> { | ||
public: | ||
using Base = DataSinkOperatorX<DictSinkLocalState>; | ||
DictSinkOperatorX(int operator_id, const TDictSink& dict_sink); | ||
Status open(RuntimeState* state) override; | ||
|
||
Status sink(RuntimeState* state, vectorized::Block* in_block, bool eos) override; | ||
|
||
private: | ||
friend class DictSinkLocalState; | ||
[[maybe_unused]] const int64_t dictionary_id; | ||
[[maybe_unused]] const int64_t version_id; | ||
const std::string dictionary_name; | ||
const int64_t key_column_id; | ||
const std::vector<int64_t> attribute_column_ids; | ||
const std::vector<std::string> attribute_name; | ||
const TDictLayoutType::type layout_type; | ||
}; | ||
|
||
} // namespace doris::pipeline | ||
#include "common/compile_check_end.h" |
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