-
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: [cherry-pick]The expression supports filling elements through t…
…emplates (#37058) issue: #36672 master pr: #37033 milvus-proto pr: milvus-io/milvus-proto#332 Signed-off-by: Cai Zhang <[email protected]>
- Loading branch information
1 parent
4cb5b2c
commit 9c0f594
Showing
30 changed files
with
2,733 additions
and
1,371 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
73 changes: 73 additions & 0 deletions
73
internal/parser/planparserv2/convert_field_data_to_generic_value.go
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,73 @@ | ||
package planparserv2 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb" | ||
"github.com/milvus-io/milvus/internal/proto/planpb" | ||
) | ||
|
||
func ConvertToGenericValue(templateName string, templateValue *schemapb.TemplateValue) (*planpb.GenericValue, error) { | ||
if templateValue == nil { | ||
return nil, fmt.Errorf("expression template variable value is nil, template name: {%s}", templateName) | ||
} | ||
switch templateValue.GetType() { | ||
case schemapb.DataType_Bool: | ||
return &planpb.GenericValue{ | ||
Val: &planpb.GenericValue_BoolVal{ | ||
BoolVal: templateValue.GetBoolVal(), | ||
}, | ||
}, nil | ||
case schemapb.DataType_Int8, schemapb.DataType_Int16, schemapb.DataType_Int32, schemapb.DataType_Int64: | ||
return &planpb.GenericValue{ | ||
Val: &planpb.GenericValue_Int64Val{ | ||
Int64Val: templateValue.GetInt64Val(), | ||
}, | ||
}, nil | ||
case schemapb.DataType_Float, schemapb.DataType_Double: | ||
return &planpb.GenericValue{ | ||
Val: &planpb.GenericValue_FloatVal{ | ||
FloatVal: templateValue.GetFloatVal(), | ||
}, | ||
}, nil | ||
case schemapb.DataType_String, schemapb.DataType_VarChar: | ||
return &planpb.GenericValue{ | ||
Val: &planpb.GenericValue_StringVal{ | ||
StringVal: templateValue.GetStringVal(), | ||
}, | ||
}, nil | ||
case schemapb.DataType_Array: | ||
elements := templateValue.GetArrayVal().GetArray() | ||
arrayValues := make([]*planpb.GenericValue, len(elements)) | ||
for i, element := range elements { | ||
arrayElement, err := ConvertToGenericValue(templateName, element) | ||
if err != nil { | ||
return nil, err | ||
} | ||
arrayValues[i] = arrayElement | ||
} | ||
return &planpb.GenericValue{ | ||
Val: &planpb.GenericValue_ArrayVal{ | ||
ArrayVal: &planpb.Array{ | ||
Array: arrayValues, | ||
SameType: templateValue.GetArrayVal().GetSameType(), | ||
ElementType: templateValue.GetArrayVal().GetElementType(), | ||
}, | ||
}, | ||
}, nil | ||
default: | ||
return nil, fmt.Errorf("expression elements can only be scalars") | ||
} | ||
} | ||
|
||
func UnmarshalExpressionValues(input map[string]*schemapb.TemplateValue) (map[string]*planpb.GenericValue, error) { | ||
result := make(map[string]*planpb.GenericValue, len(input)) | ||
for name, value := range input { | ||
rv, err := ConvertToGenericValue(name, value) | ||
if err != nil { | ||
return nil, err | ||
} | ||
result[name] = rv | ||
} | ||
return result, nil | ||
} |
Oops, something went wrong.