Skip to content
Open
51 changes: 33 additions & 18 deletions api/persistence/v1/cluster_metadata.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion common/searchattribute/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,25 @@ var (
"KeywordList02": enumspb.INDEXED_VALUE_TYPE_KEYWORD_LIST,
"KeywordList03": enumspb.INDEXED_VALUE_TYPE_KEYWORD_LIST,
}

archetypeSearchAttributes = map[string]enumspb.IndexedValueType{
"TemporalBool01": enumspb.INDEXED_VALUE_TYPE_BOOL,
"TemporalBool02": enumspb.INDEXED_VALUE_TYPE_BOOL,
"TemporalDatetime01": enumspb.INDEXED_VALUE_TYPE_DATETIME,
"TemporalDatetime02": enumspb.INDEXED_VALUE_TYPE_DATETIME,
"TemporalDouble01": enumspb.INDEXED_VALUE_TYPE_DOUBLE,
"TemporalDouble02": enumspb.INDEXED_VALUE_TYPE_DOUBLE,
"TemporalInt01": enumspb.INDEXED_VALUE_TYPE_INT,
"TemporalInt02": enumspb.INDEXED_VALUE_TYPE_INT,
"TemporalKeyword01": enumspb.INDEXED_VALUE_TYPE_KEYWORD,
"TemporalKeyword02": enumspb.INDEXED_VALUE_TYPE_KEYWORD,
"TemporalKeyword03": enumspb.INDEXED_VALUE_TYPE_KEYWORD,
"TemporalKeyword04": enumspb.INDEXED_VALUE_TYPE_KEYWORD,
"TemporalText01": enumspb.INDEXED_VALUE_TYPE_TEXT,
"TemporalText02": enumspb.INDEXED_VALUE_TYPE_TEXT,
"TemporalKeywordList01": enumspb.INDEXED_VALUE_TYPE_KEYWORD_LIST,
"TemporalKeywordList02": enumspb.INDEXED_VALUE_TYPE_KEYWORD_LIST,
}
)

// IsSystem returns true if name is system search attribute
Expand Down Expand Up @@ -260,10 +279,16 @@ func GetSqlDbColName(name string) string {

func GetSqlDbIndexSearchAttributes() *persistencespb.IndexSearchAttributes {
return &persistencespb.IndexSearchAttributes{
CustomSearchAttributes: sqlDbCustomSearchAttributes,
CustomSearchAttributes: sqlDbCustomSearchAttributes,
ArchetypeSearchAttributes: archetypeSearchAttributes,
}
}

// GetArchetypeIndexSearchAttributes returns the predefined Archetype search attributes.
func GetArchetypeIndexSearchAttributes() map[string]enumspb.IndexedValueType {
return archetypeSearchAttributes
}

// QueryWithAnyNamespaceDivision returns a modified workflow visibility query that disables
// special handling of namespace division and so matches workflows in all namespace divisions.
// Normally a query that didn't explicitly mention TemporalNamespaceDivision would be limited
Expand Down
12 changes: 11 additions & 1 deletion common/searchattribute/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (m *managerImpl) GetSearchAttributes(
}
if indexSearchAttributes, ok := saCache.searchAttributes[indexName]; ok {
result.customSearchAttributes = maps.Clone(indexSearchAttributes.customSearchAttributes)
result.archetypeSearchAttributes = maps.Clone(indexSearchAttributes.archetypeSearchAttributes)
}
return result, nil
}
Expand Down Expand Up @@ -177,7 +178,16 @@ func (m *managerImpl) SaveSearchAttributes(
if clusterMetadata.IndexSearchAttributes == nil {
clusterMetadata.IndexSearchAttributes = map[string]*persistencespb.IndexSearchAttributes{indexName: nil}
}
clusterMetadata.IndexSearchAttributes[indexName] = &persistencespb.IndexSearchAttributes{CustomSearchAttributes: newCustomSearchAttributes}
// Preserve any existing ArchetypeSearchAttributes while updating custom ones.
existing := clusterMetadata.IndexSearchAttributes[indexName]
var archetype map[string]enumspb.IndexedValueType
if existing != nil {
archetype = existing.GetArchetypeSearchAttributes()
}
clusterMetadata.IndexSearchAttributes[indexName] = &persistencespb.IndexSearchAttributes{
CustomSearchAttributes: newCustomSearchAttributes,
ArchetypeSearchAttributes: archetype,
}
_, err = m.clusterMetadataManager.SaveClusterMetadata(ctx, &persistence.SaveClusterMetadataRequest{
ClusterMetadata: clusterMetadata,
Version: clusterMetadataResponse.Version,
Expand Down
18 changes: 15 additions & 3 deletions common/searchattribute/name_type_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type (
NameTypeMap struct {
// customSearchAttributes are defined by cluster admin per cluster level and passed and stored in SearchAttributes object.
customSearchAttributes map[string]enumspb.IndexedValueType
// archetypeSearchAttributes are defined during component registration, pre-allocated field name to type map is stored here.
archetypeSearchAttributes map[string]enumspb.IndexedValueType
}

category int32
Expand All @@ -20,13 +22,15 @@ const (
systemCategory category = 1 << iota
predefinedCategory
customCategory
archetypeCategory
)

func buildIndexNameTypeMap(indexSearchAttributes map[string]*persistencespb.IndexSearchAttributes) map[string]NameTypeMap {
indexNameTypeMap := make(map[string]NameTypeMap, len(indexSearchAttributes))
for indexName, customSearchAttributes := range indexSearchAttributes {
for indexName, attrs := range indexSearchAttributes {
indexNameTypeMap[indexName] = NameTypeMap{
customSearchAttributes: customSearchAttributes.GetCustomSearchAttributes(),
customSearchAttributes: attrs.GetCustomSearchAttributes(),
archetypeSearchAttributes: attrs.GetArchetypeSearchAttributes(),
}
}
return indexNameTypeMap
Expand All @@ -48,7 +52,7 @@ func (m NameTypeMap) Custom() map[string]enumspb.IndexedValueType {
}

func (m NameTypeMap) All() map[string]enumspb.IndexedValueType {
allSearchAttributes := make(map[string]enumspb.IndexedValueType, len(system)+len(m.customSearchAttributes)+len(predefined))
allSearchAttributes := make(map[string]enumspb.IndexedValueType, len(system)+len(predefined)+len(m.customSearchAttributes)+len(m.archetypeSearchAttributes))
for saName, saType := range system {
allSearchAttributes[saName] = saType
}
Expand All @@ -58,6 +62,9 @@ func (m NameTypeMap) All() map[string]enumspb.IndexedValueType {
for saName, saType := range m.customSearchAttributes {
allSearchAttributes[saName] = saType
}
for saName, saType := range m.archetypeSearchAttributes {
allSearchAttributes[saName] = saType
}
return allSearchAttributes
}

Expand All @@ -73,6 +80,11 @@ func (m NameTypeMap) getType(name string, cat category) (enumspb.IndexedValueTyp
return t, nil
}
}
if cat|archetypeCategory == cat && len(m.archetypeSearchAttributes) != 0 {
if t, isArchetype := m.archetypeSearchAttributes[name]; isArchetype {
return t, nil
}
}
if cat|predefinedCategory == cat {
if t, isPredefined := predefined[name]; isPredefined {
return t, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ message ClusterMetadata {

message IndexSearchAttributes{
map<string,temporal.api.enums.v1.IndexedValueType> custom_search_attributes = 1;
map<string,temporal.api.enums.v1.IndexedValueType> archetype_search_attributes = 2;
}
Loading