go.temporal.io/server/common/searchattribute/encode.go

101 LOC · 53 covered · 48 uncovered · 18 ranges · 91 concepts · 12 introducers · 41 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the fileworkflow_handler.go ×11 · 117 introduced LOCworkflow_handler.go ×11common.go ×1 · 11 introduced LOCcommon.go ×1request_response.pb.go ×6 · 246 introduced LOCrequest_response.pb.go ×…visibility_store.go ×17 · 171 introduced LOCvisibility_store.go ×17telemetry.go ×2 · 15 introduced LOCtelemetry.go ×2fx.go ×1 · 4 introduced LOCfx.go ×1collector.go ×7 · 33 introduced LOCcollector.go ×7data_store_factory.go ×29 · 703 introduced LOCdata_store_factory.go ×2…TestNewServer · 0 introduced LOCTestNewServerpri_matcher.go ×1 · 2 introduced LOCpri_matcher.go ×1timer_queue_active_task_executor.go ×1 · 3 introduced LOCtimer_queue_active_task_…TestNewServer · 0 introduced LOCTestNewServermetric_client.go ×3 · 18 introduced LOCmetric_client.go ×3request_response.pb.go ×12 · 137 introduced LOCrequest_response.pb.go ×…workflow_task_completed_handler.go ×9 · 75 introduced LOCworkflow_task_completed_…pri_forwarder.go ×2 · 4 introduced LOCpri_forwarder.go ×2request_response.pb.go ×1 · 7 introduced LOCrequest_response.pb.go ×…logger.go ×1 · 5 introduced LOClogger.go ×1connections.go ×1 · 9 introduced LOCconnections.go ×1persistence_rate_limited_clients.go ×2 · 17 introduced LOCpersistence_rate_limited…logger.go ×1 · 2 introduced LOClogger.go ×1metric_client.go ×2 · 7 introduced LOCmetric_client.go ×2pri_matcher.go ×1 · 4 introduced LOCpri_matcher.go ×1task_queue_partition_manager.go ×2 · 10 introduced LOCtask_queue_partition_man…connections.go ×2 · 12 introduced LOCconnections.go ×2workflow_handler.go ×8 · 144 introduced LOCworkflow_handler.go ×8pri_matcher.go ×1 · 2 introduced LOCpri_matcher.go ×1handler.go ×1 · 20 introduced LOChandler.go ×1pri_matcher.go ×8 · 55 introduced LOCpri_matcher.go ×8matching_engine.go ×1 · 8 introduced LOCmatching_engine.go ×1server.go ×1 · 3 introduced LOCserver.go ×1logger.go ×2 · 21 introduced LOClogger.go ×2queue_scheduled.go ×1 · 2 introduced LOCqueue_scheduled.go ×1handler.go ×25 · 728 introduced LOChandler.go ×25visibility_queue_task_executor.go ×10 · 27 introduced LOCvisibility_queue_task_ex…TestProcessCloseExecution · 0 introduced LOCTestProcessCloseExecutio…visibility_queue_task_executor.go ×1 · 5 introduced LOCvisibility_queue_task_ex…visibility_manager_mock.go ×2 · 10 introduced LOCvisibility_manager_mock.…TestProcessModifyWorkflowProperties, TestProcessUpsertWorkflowSearchAttributes · 0 introduced LOCTestProcessModifyWorkflo…TestUpsertWorkflowExecution · 0 introduced LOCTestUpsertWorkflowExecut…TestUpsertWorkflowExecution · 0 introduced LOCTestUpsertWorkflowExecut…TestUpsertWorkflowExecution · 0 introduced LOCTestUpsertWorkflowExecut…typeconv.go ×1 · 5 introduced LOCtypeconv.go ×1typeconv.go ×1 · 5 introduced LOCtypeconv.go ×1typeconv.go ×1 · 2 introduced LOCtypeconv.go ×1visibility_persistence_suite.go ×1 · 52 introduced LOCvisibility_persistence_s…visibility.go ×2 · 6 introduced LOCvisibility.go ×2visibility_store.go ×5 · 27 introduced LOCvisibility_store.go ×5visibility_store.go ×7 · 29 introduced LOCvisibility_store.go ×7TestParseESDoc_SearchAttributes · 0 introduced LOCTestParseESDoc_SearchAtt…TestRecordWorkflowExecutionClosed · 0 introduced LOCTestRecordWorkflowExecut…TestRecordWorkflowExecutionStarted · 0 introduced LOCTestRecordWorkflowExecut…visibility_store.go ×7 · 11 introduced LOCvisibility_store.go ×7visibility_store.go ×5 · 25 introduced LOCvisibility_store.go ×5visibility_store.go ×5 · 17 introduced LOCvisibility_store.go ×5TestParseESDoc_ChasmSearchAttributes · 0 introduced LOCTestParseESDoc_ChasmSear…visibility_store.go ×1 · 6 introduced LOCvisibility_store.go ×1visibility_store.go ×1 · 3 introduced LOCvisibility_store.go ×1visibility_store.go ×3 · 10 introduced LOCvisibility_store.go ×3visibility_store.go ×2 · 4 introduced LOCvisibility_store.go ×2visibility_store.go ×1 · 2 introduced LOCvisibility_store.go ×1TestParseESDoc_ChasmSearchAttributes_NoMapper · 0 introduced LOCTestParseESDoc_ChasmSear…TestRecordWorkflowExecutionClosed_EmptyRequest · 0 introduced LOCTestRecordWorkflowExecut…visibility_store.go ×4 · 15 introduced LOCvisibility_store.go ×4TestRecordWorkflowExecutionStarted_EmptyRequest · 0 introduced LOCTestRecordWorkflowExecut…visibility_store.go ×1 · 3 introduced LOCvisibility_store.go ×1visibility_store.go ×2 · 5 introduced LOCvisibility_store.go ×2encode.go ×1 · 2 introduced LOCencode.go ×1visibility_store.go ×2 · 11 introduced LOCvisibility_store.go ×2visibility_store.go ×2 · 6 introduced LOCvisibility_store.go ×2visibility_store.go ×10 · 38 introduced LOCvisibility_store.go ×10visibility_store.go ×13 · 35 introduced LOCvisibility_store.go ×13encode.go ×1 · 2 introduced LOCencode.go ×1Test_Decode_SkipsUnknownSAWithNoMetadataType · 0 introduced LOCTest_Decode_SkipsUnknown…Test_Decode_FallsBackToMetadataTypeForUnknownSA · 0 introduced LOCTest_Decode_FallsBackToM…Test_Decode_NilMap · 0 introduced LOCTest_Decode_NilMapencode.go ×2 · 12 introduced LOCencode.go ×2Test_Decode_Success · 0 introduced LOCTest_Decode_Successstringify.go ×2 · 6 introduced LOCstringify.go ×2stringify.go ×2 · 4 introduced LOCstringify.go ×2constants.go ×1 · 4 introduced LOCconstants.go ×1encode.go ×1 · 3 introduced LOCencode.go ×1encode.go ×1 · 6 introduced LOCencode.go ×1encode.go ×1 · 3 introduced LOCencode.go ×1encode.go ×1 · 1 introduced LOCencode.go ×1Test_Encode_Success · 0 introduced LOCTest_Encode_Successencode.go ×2 · 3 introduced LOCencode.go ×2encode.go ×3 · 8 introduced LOCencode.go ×3encode.go ×3 · 9 introduced LOCencode.go ×3encode.go ×1 · 2 introduced LOCencode.go ×1encode.go ×1 · 2 introduced LOCencode.go ×1TestUpsertWorkflowExecution · introduced test · go.temporal.io/server/common/persistence/tests/TestMySQLVisibilityPersistenceSuite/TestUpsertWorkflowExecutionTestUpsertWorkflowExecut…TestUpsertWorkflowExecution · introduced test · go.temporal.io/server/common/persistence/tests/TestPGX/TestPostgreSQLVisibilityPersistenceSuite/TestUpsertWorkflowExecutionTestUpsertWorkflowExecut…TestUpsertWorkflowExecution · introduced test · go.temporal.io/server/common/persistence/tests/TestPGXSP/TestPostgreSQLVisibilityPersistenceSuite/TestUpsertWorkflowExecutionTestUpsertWorkflowExecut…TestUpsertWorkflowExecution · introduced test · go.temporal.io/server/common/persistence/tests/TestPQ/TestPostgreSQLVisibilityPersistenceSuite/TestUpsertWorkflowExecutionTestUpsertWorkflowExecut…TestUpsertWorkflowExecution · introduced test · go.temporal.io/server/common/persistence/tests/TestSQLiteVisibilityPersistenceSuite/TestUpsertWorkflowExecutionTestUpsertWorkflowExecut…TestGetListWorkflowExecutionsResponse · introduced test · go.temporal.io/server/common/persistence/visibility/store/elasticsearch/TestESVisibilitySuite/TestGetListWorkflowExecutionsResponseTestGetListWorkflowExecu…TestGetWorkflowExecution · introduced test · go.temporal.io/server/common/persistence/visibility/store/elasticsearch/TestESVisibilitySuite/TestGetWorkflowExecutionTestGetWorkflowExecutionTestParseESDoc · introduced test · go.temporal.io/server/common/persistence/visibility/store/elasticsearch/TestESVisibilitySuite/TestParseESDocTestParseESDocTestParseESDoc_ChasmSearchAttributes · introduced test · go.temporal.io/server/common/persistence/visibility/store/elasticsearch/TestESVisibilitySuite/TestParseESDoc_ChasmSearchAttributesTestParseESDoc_ChasmSear…TestParseESDoc_ChasmSearchAttributes_NoMapper · introduced test · go.temporal.io/server/common/persistence/visibility/store/elasticsearch/TestESVisibilitySuite/TestParseESDoc_ChasmSearchAttributes_NoMapperTestParseESDoc_ChasmSear…TestParseESDoc_SearchAttributes · introduced test · go.temporal.io/server/common/persistence/visibility/store/elasticsearch/TestESVisibilitySuite/TestParseESDoc_SearchAttributesTestParseESDoc_SearchAtt…TestParseESDoc_SearchAttributes_WithMapper · introduced test · go.temporal.io/server/common/persistence/visibility/store/elasticsearch/TestESVisibilitySuite/TestParseESDoc_SearchAttributes_WithMapperTestParseESDoc_SearchAtt…TestRecordWorkflowExecutionClosed · introduced test · go.temporal.io/server/common/persistence/visibility/store/elasticsearch/TestESVisibilitySuite/TestRecordWorkflowExecutionClosedTestRecordWorkflowExecut…TestRecordWorkflowExecutionClosed_EmptyRequest · introduced test · go.temporal.io/server/common/persistence/visibility/store/elasticsearch/TestESVisibilitySuite/TestRecordWorkflowExecutionClosed_EmptyRequestTestRecordWorkflowExecut…TestRecordWorkflowExecutionStarted · introduced test · go.temporal.io/server/common/persistence/visibility/store/elasticsearch/TestESVisibilitySuite/TestRecordWorkflowExecutionStartedTestRecordWorkflowExecut…TestRecordWorkflowExecutionStarted_EmptyRequest · introduced test · go.temporal.io/server/common/persistence/visibility/store/elasticsearch/TestESVisibilitySuite/TestRecordWorkflowExecutionStarted_EmptyRequestTestRecordWorkflowExecut…Test_Stringify · introduced test · go.temporal.io/server/common/searchattribute/TestStringifySuite/Test_StringifyTest_StringifyTest_Stringify_Array · introduced test · go.temporal.io/server/common/searchattribute/TestStringifySuite/Test_Stringify_ArrayTest_Stringify_ArrayTest_Decode_Error · introduced test · go.temporal.io/server/common/searchattribute/Test_Decode_ErrorTest_Decode_ErrorTest_Decode_FallsBackToMetadataTypeForUnknownSA · introduced test · go.temporal.io/server/common/searchattribute/Test_Decode_FallsBackToMetadataTypeForUnknownSATest_Decode_FallsBackToM…Test_Decode_NilMap · introduced test · go.temporal.io/server/common/searchattribute/Test_Decode_NilMapTest_Decode_NilMapTest_Decode_SkipsUnknownSAWithNoMetadataType · introduced test · go.temporal.io/server/common/searchattribute/Test_Decode_SkipsUnknownSAWithNoMetadataTypeTest_Decode_SkipsUnknown…Test_Decode_Success · introduced test · go.temporal.io/server/common/searchattribute/Test_Decode_SuccessTest_Decode_SuccessTest_Encode_NilMap · introduced test · go.temporal.io/server/common/searchattribute/Test_Encode_NilMapTest_Encode_NilMapTest_Encode_SkipsUnknownSearchAttributes · introduced test · go.temporal.io/server/common/searchattribute/Test_Encode_SkipsUnknownSearchAttributesTest_Encode_SkipsUnknown…Test_Encode_Success · introduced test · go.temporal.io/server/common/searchattribute/Test_Encode_SuccessTest_Encode_SuccessTestProcessCloseExecution · introduced test · go.temporal.io/server/service/history/TestVisibilityQueueTaskExecutorSuite/TestProcessCloseExecutionTestProcessCloseExecutio…TestProcessCloseExecutionWithWorkflowClosedCleanup · introduced test · go.temporal.io/server/service/history/TestVisibilityQueueTaskExecutorSuite/TestProcessCloseExecutionWithWorkflowClosedCleanupTestProcessCloseExecutio…TestProcessModifyWorkflowProperties · introduced test · go.temporal.io/server/service/history/TestVisibilityQueueTaskExecutorSuite/TestProcessModifyWorkflowPropertiesTestProcessModifyWorkflo…TestProcessRecordWorkflowStartedTask · introduced test · go.temporal.io/server/service/history/TestVisibilityQueueTaskExecutorSuite/TestProcessRecordWorkflowStartedTaskTestProcessRecordWorkflo…TestProcessUpsertWorkflowSearchAttributes · introduced test · go.temporal.io/server/service/history/TestVisibilityQueueTaskExecutorSuite/TestProcessUpsertWorkflowSearchAttributesTestProcessUpsertWorkflo…TestNewServer · introduced test · go.temporal.io/server/temporal/TestNewServerTestNewServerTestNewServerWithJSONEncoding · introduced test · go.temporal.io/server/temporal/TestNewServerWithJSONEncodingTestNewServerWithJSONEnc…with_OTEL_Collector_running · introduced test · go.temporal.io/server/temporal/TestNewServerWithOTEL/with_OTEL_Collector_runningwith_OTEL_Collector_runn…without_OTEL_Collector_running · introduced test · go.temporal.io/server/temporal/TestNewServerWithOTEL/without_OTEL_Collector_runningwithout_OTEL_Collector_r…ExampleNewServer · introduced test · go.temporal.io/server/temporaltest/ExampleNewServerExampleNewServerTestClientWithCustomInterceptor · introduced test · go.temporal.io/server/temporaltest/TestClientWithCustomInterceptorTestClientWithCustomInte…TestDefaultWorkerOptions · introduced test · go.temporal.io/server/temporaltest/TestDefaultWorkerOptionsTestDefaultWorkerOptionsTestNewServer · introduced test · go.temporal.io/server/temporaltest/TestNewServerTestNewServerTestNewWorkerWithOptions · introduced test · go.temporal.io/server/temporaltest/TestNewWorkerWithOptionsTestNewWorkerWithOptionsTestSearchAttributeRegistration · introduced test · go.temporal.io/server/temporaltest/TestSearchAttributeRegistrationTestSearchAttributeRegis…Focused file · go.temporal.io/server/common/searchattribute/encode.go · 101 LOCsearchattribute/encode.g…

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 package searchattribute
2
3 import (
4 "errors"
5
6 commonpb "go.temporal.io/api/common/v1"
7 enumspb "go.temporal.io/api/enums/v1"
8 "go.temporal.io/server/common/payload"
9 "go.temporal.io/server/common/searchattribute/sadefs"
10 )
11
12 // Encode encodes map of search attribute values to search attributes.
13 // typeMap can be nil (then MetadataType field won't be set).
14 // In case of error, it will continue to next search attribute and return last error.
15 > func Encode(searchAttributes map[string]any, typeMap *NameTypeMap) (*commonpb.SearchAttributes, error) { encode.go ×1
16 > if len(searchAttributes) == 0 {
17 > return nil, nil encode.go ×1
18 > }
19
20 > indexedFields := make(map[string]*commonpb.Payload, len(searchAttributes)) encode.go ×3
21 > var lastErr error
22 > for saName, saValue := range searchAttributes {
23 > valPayload, err := payload.Encode(saValue)
24 > if err != nil {
25 lastErr = err
26 indexedFields[saName] = nil
27 continue
28 }
29
30 > indexedFields[saName] = valPayload encode.go ×3
31 > saType := enumspb.INDEXED_VALUE_TYPE_UNSPECIFIED
32 > if typeMap != nil {
33 > saType, err = typeMap.getType(saName, customCategory|predefinedCategory) encode.go ×2
34 > if err != nil {
35 > if errors.Is(err, sadefs.ErrInvalidName) { encode.go ×1
36 > // Silently skip unknown search attributes. This can happen due to
37 > // version mismatches where a newer server wrote a predefined SA
38 > // that this server doesn't recognize.
39 > delete(indexedFields, saName)
40 > continue
41 }
42 lastErr = err
43 continue
44 }
45 > sadefs.SetMetadataType(valPayload, saType) encode.go ×2
46 }
47 }
48 > return &commonpb.SearchAttributes{IndexedFields: indexedFields}, lastErr encode.go ×3
49 }
50
51 // Decode decodes search attributes to the map of search attribute values using (in order):
52 // 1. type from typeMap,
53 // 2. if typeMap is nil, type from MetadataType field is used.
54 // In case of error, it will continue to next search attribute and return last error.
55 func Decode(
56 searchAttributes *commonpb.SearchAttributes,
57 typeMap *NameTypeMap,
58 allowList bool,
59 > ) (map[string]any, error) { encode.go ×1
60 > if len(searchAttributes.GetIndexedFields()) == 0 {
61 > return nil, nil encode.go ×1
62 > }
63
64 > result := make(map[string]any, len(searchAttributes.GetIndexedFields())) encode.go ×3
65 > var lastErr error
66 > for saName, saPayload := range searchAttributes.GetIndexedFields() {
67 > saType := enumspb.INDEXED_VALUE_TYPE_UNSPECIFIED
68 > if typeMap != nil {
69 > var err error encode.go ×1
70 > saType, err = typeMap.getType(saName, customCategory|predefinedCategory)
71 > if err != nil {
72 > if sadefs.IsChasmSearchAttribute(saName) { encode.go ×2
73 // Chasm search attributes are not in the standard type map;
74 // allow them through with UNSPECIFIED type.
75 > } else if errors.Is(err, sadefs.ErrInvalidName) { encode.go ×2
76 > // SA not found in the type map. Fall through to DecodeValue with
77 > // UNSPECIFIED type, which uses the payload's MetadataType as a
78 > // fallback. This handles two cases:
79 > // 1. Version mismatch: a newer server wrote a predefined SA that
80 > // this server's constants don't recognize.
81 > // 2. Cache lag: a recently registered custom SA that hasn't yet
82 > // propagated to this server's SA manager cache.
83 > // If MetadataType is also UNSPECIFIED (truly unknown payload),
84 > // DecodeValue returns an error and the SA is excluded from the result.
85 > } else {
86 lastErr = err
87 }
88 }
89 }
90
91 > searchAttributeValue, err := sadefs.DecodeValue(saPayload, saType, allowList) encode.go ×3
92 > if err != nil {
93 > lastErr = err encode.go ×1
94 > result[saName] = nil
95 > continue
96 }
97 > result[saName] = searchAttributeValue encode.go ×1
98 }
99
100 > return result, lastErr encode.go ×3
101 }