-
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.
feat: Implement custom function module in milvus expr
OSPP 2024 project: https://summer-ospp.ac.cn/org/prodetail/247410235?list=org&navpage=org Solutions: - parser (planparserv2) - add CallExpr in planparserv2/Plan.g4 - update parser_visitor and show_visitor - grpc protobuf - add CallExpr in plan.proto - execution (`core/src/exec`) - add `CallExpr`, `ValueExpr` and `ColumnExpr` (both logical and physical) for function call and function parameters - function factory (`core/src/exec/expression/function`) - create a global hashmap when starting milvus (see server.go) - the global hashmap stores function signatures and their function pointers, the CallExpr in execution engine can get the function pointer by function signature. - `common/Vector.h` - add ConstantVector, update ColumnVector - `segcore/SegmentChunkReader.h` - extracted some methods from `CompareExpr.h` - custom functions - empty(string) - starts_with(string, string) - add cpp/go unittests and E2E tests closes: #36559 Signed-off-by: Yinzuo Jiang <[email protected]>
- Loading branch information
1 parent
0dbf948
commit 8382c28
Showing
50 changed files
with
2,988 additions
and
776 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 |
---|---|---|
@@ -1,20 +1,15 @@ | ||
# Visitor Pattern | ||
Visitor Pattern is used in segcore for parse and execute Execution Plan. | ||
|
||
1. Inside `${core}/src/query/PlanNode.h`, contains physical plan for vector search: | ||
1. Inside `${internal/core}/src/query/PlanNode.h`, contains physical plan for vector search: | ||
1. `FloatVectorANNS` FloatVector search execution node | ||
2. `BinaryVectorANNS` BinaryVector search execution node | ||
2. `${core}/src/query/Expr.h` contains physical plan for scalar expression: | ||
2. `${internal/core}/src/query/Expr.h` contains physical plan for scalar expression: | ||
1. `TermExpr` support operation like `col in [1, 2, 3]` | ||
2. `RangeExpr` support constant compare with data column like `a >= 5` `1 < b < 2` | ||
3. `CompareExpr` support compare with different columns, like `a < b` | ||
4. `LogicalBinaryExpr` support and/or | ||
5. `LogicalUnaryExpr` support not | ||
|
||
Currently, under `${core/query/visitors}` directory, there are the following visitors: | ||
1. `ShowPlanNodeVisitor` prints PlanNode in json | ||
2. `ShowExprVisitor` Expr -> json | ||
3. `Verify...Visitor` validates ... | ||
4. `ExtractInfo...Visitor` extracts info from..., including involved_fields and else | ||
5. `ExecExprVisitor` generates bitmask according to expression | ||
6. `ExecPlanNodeVistor` physical plan executor only supports ANNS node for now | ||
Currently, under `${internal/core/src/query}` directory, there are the following visitors: | ||
1. `ExecPlanNodeVistor` physical plan executor only supports ANNS node for now |
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 |
---|---|---|
|
@@ -235,4 +235,4 @@ Task::Next(ContinueFuture* future) { | |
} | ||
|
||
} // namespace exec | ||
} // namespace milvus | ||
} // 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,46 @@ | ||
// 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 "common/FieldDataInterface.h" | ||
#include "common/Vector.h" | ||
#include "exec/expression/CallExpr.h" | ||
#include "exec/expression/EvalCtx.h" | ||
#include "exec/expression/function/FunctionFactory.h" | ||
|
||
#include <utility> | ||
#include <vector> | ||
|
||
namespace milvus { | ||
namespace exec { | ||
|
||
void | ||
PhyCallExpr::Eval(EvalCtx& context, VectorPtr& result) { | ||
AssertInfo(inputs_.size() == expr_->inputs().size(), | ||
"logical call expr needs {} inputs, but {} inputs are provided", | ||
expr_->inputs().size(), | ||
inputs_.size()); | ||
std::vector<VectorPtr> args; | ||
for (auto& input : this->inputs_) { | ||
VectorPtr arg_result; | ||
input->Eval(context, arg_result); | ||
args.push_back(std::move(arg_result)); | ||
} | ||
RowVector row_vector(std::move(args)); | ||
this->expr_->function_ptr()(row_vector, result); | ||
} | ||
|
||
} // namespace exec | ||
} // namespace milvus |
Oops, something went wrong.