-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#31728 --------- Signed-off-by: lixinguo <[email protected]> Co-authored-by: lixinguo <[email protected]>
- Loading branch information
1 parent
19a5c31
commit 907fc24
Showing
27 changed files
with
1,756 additions
and
660 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
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,150 @@ | ||
// Licensed to the LF AI & Data foundation 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 "NullExpr.h" | ||
#include <memory> | ||
#include <utility> | ||
#include "common/Array.h" | ||
#include "common/Types.h" | ||
#include "log/Log.h" | ||
#include "query/Utils.h" | ||
namespace milvus { | ||
namespace exec { | ||
|
||
void | ||
PhyNullExpr::Eval(EvalCtx& context, VectorPtr& result) { | ||
auto input = context.get_offset_input(); | ||
switch (expr_->column_.data_type_) { | ||
case DataType::BOOL: { | ||
result = ExecVisitorImpl<bool>(input); | ||
break; | ||
} | ||
case DataType::INT8: { | ||
result = ExecVisitorImpl<int8_t>(input); | ||
break; | ||
} | ||
case DataType::INT16: { | ||
result = ExecVisitorImpl<int16_t>(input); | ||
break; | ||
} | ||
case DataType::INT32: { | ||
result = ExecVisitorImpl<int32_t>(input); | ||
break; | ||
} | ||
case DataType::INT64: { | ||
result = ExecVisitorImpl<int64_t>(input); | ||
break; | ||
} | ||
case DataType::FLOAT: { | ||
result = ExecVisitorImpl<float>(input); | ||
break; | ||
} | ||
case DataType::DOUBLE: { | ||
result = ExecVisitorImpl<double>(input); | ||
break; | ||
} | ||
case DataType::VARCHAR: { | ||
if (segment_->type() == SegmentType::Growing && | ||
!storage::MmapManager::GetInstance() | ||
.GetMmapConfig() | ||
.growing_enable_mmap) { | ||
result = ExecVisitorImpl<std::string>(input); | ||
} else { | ||
result = ExecVisitorImpl<std::string_view>(input); | ||
} | ||
break; | ||
} | ||
case DataType::JSON: { | ||
result = ExecVisitorImpl<Json>(input); | ||
break; | ||
} | ||
case DataType::ARRAY: { | ||
result = ExecVisitorImpl<ArrayView>(input); | ||
break; | ||
} | ||
default: | ||
PanicInfo(DataTypeInvalid, | ||
"unsupported data type: {}", | ||
expr_->column_.data_type_); | ||
} | ||
} | ||
|
||
template <typename T> | ||
VectorPtr | ||
PhyNullExpr::ExecVisitorImpl(OffsetVector* input) { | ||
if (auto res = PreCheckNullable(input)) { | ||
return res; | ||
} | ||
auto valid_res = | ||
(input != nullptr) | ||
? ProcessChunksForValidByOffsets<T>(is_index_mode_, *input) | ||
: ProcessChunksForValid<T>(is_index_mode_); | ||
TargetBitmap res = valid_res.clone(); | ||
if (expr_->op_ == proto::plan::NullExpr_NullOp_IsNull) { | ||
res.flip(); | ||
} | ||
auto res_vec = | ||
std::make_shared<ColumnVector>(std::move(res), std::move(valid_res)); | ||
return res_vec; | ||
} | ||
|
||
// if nullable is false, no need to process chunks | ||
// res is all false when is null, and is all true when is not null | ||
ColumnVectorPtr | ||
PhyNullExpr::PreCheckNullable(OffsetVector* input) { | ||
if (expr_->column_.nullable_) { | ||
return nullptr; | ||
} | ||
|
||
int64_t batch_size; | ||
if (input != nullptr) { | ||
batch_size = input->size(); | ||
} else { | ||
batch_size = precheck_pos_ + batch_size_ >= active_count_ | ||
? active_count_ - precheck_pos_ | ||
: batch_size_; | ||
precheck_pos_ += batch_size; | ||
} | ||
if (cached_precheck_res_ != nullptr && | ||
cached_precheck_res_->size() == batch_size) { | ||
return cached_precheck_res_; | ||
} | ||
|
||
auto res_vec = std::make_shared<ColumnVector>(TargetBitmap(batch_size), | ||
TargetBitmap(batch_size)); | ||
TargetBitmapView res(res_vec->GetRawData(), batch_size); | ||
TargetBitmapView valid_res(res_vec->GetValidRawData(), batch_size); | ||
valid_res.set(); | ||
switch (expr_->op_) { | ||
case proto::plan::NullExpr_NullOp_IsNull: { | ||
res.reset(); | ||
break; | ||
} | ||
case proto::plan::NullExpr_NullOp_IsNotNull: { | ||
res.set(); | ||
break; | ||
} | ||
default: | ||
PanicInfo(ExprInvalid, | ||
"unsupported null expr type {}", | ||
proto::plan::NullExpr_NullOp_Name(expr_->op_)); | ||
} | ||
cached_precheck_res_ = res_vec; | ||
return cached_precheck_res_; | ||
} | ||
|
||
} //namespace exec | ||
} // namespace milvus |
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,65 @@ | ||
// Licensed to the LF AI & Data foundation 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 <fmt/core.h> | ||
|
||
#include "common/EasyAssert.h" | ||
#include "common/Types.h" | ||
#include "common/Vector.h" | ||
#include "exec/expression/Expr.h" | ||
#include "expr/ITypeExpr.h" | ||
#include "segcore/SegmentInterface.h" | ||
|
||
namespace milvus { | ||
namespace exec { | ||
|
||
class PhyNullExpr : public SegmentExpr { | ||
public: | ||
PhyNullExpr(const std::vector<std::shared_ptr<Expr>>& input, | ||
const std::shared_ptr<const milvus::expr::NullExpr>& expr, | ||
const std::string& name, | ||
const segcore::SegmentInternalInterface* segment, | ||
int64_t active_count, | ||
int64_t batch_size) | ||
: SegmentExpr(std::move(input), | ||
name, | ||
segment, | ||
expr->column_.field_id_, | ||
active_count, | ||
batch_size), | ||
expr_(expr) { | ||
} | ||
|
||
void | ||
Eval(EvalCtx& context, VectorPtr& result) override; | ||
|
||
private: | ||
ColumnVectorPtr | ||
PreCheckNullable(OffsetVector* input); | ||
|
||
template <typename T> | ||
VectorPtr | ||
ExecVisitorImpl(OffsetVector* input); | ||
|
||
private: | ||
std::shared_ptr<const milvus::expr::NullExpr> expr_; | ||
ColumnVectorPtr cached_precheck_res_{nullptr}; | ||
int64_t precheck_pos_{0}; | ||
}; | ||
} //namespace exec | ||
} // namespace milvus |
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
Oops, something went wrong.