1
1
from dataclasses import dataclass
2
- from typing import Dict
2
+ from typing import Dict , Any , Optional
3
3
4
4
5
5
@dataclass
6
6
class MetadataOptions :
7
7
"""Passed into metadata_options on get_features, controls what metadata is returned as part of the response.
8
8
9
9
Attributes:
10
- include_names: Include the name of each feature in the response
11
- include_data_types: Include the data type of each feature in the response
12
- include_effective_times: Include the effective times of the feature values in the response.
13
- include_slo_info: Include the SLO information as well as the Batch SLO Information in the response.
14
- include_serving_status: Include feature statuses in the response.
15
- include_feature_descriptions: Include user-defined feature descriptions in the response.
16
- include_feature_tags: Include user-defined feature tags in the response.
10
+ include_names: Include the name of each feature in the response. Defaults to None (not set).
11
+ include_data_types: Include the data type of each feature in the response. Defaults to None (not set).
12
+ include_effective_times: Include the effective times of the feature values in the response. Defaults to None (not set).
13
+ include_slo_info: Include the SLO information as well as the Batch SLO Information in the response. Defaults to None (not set).
14
+ include_serving_status: Include feature statuses in the response. Defaults to None (not set).
15
+ include_feature_descriptions: Include user-defined feature descriptions in the response. Defaults to None (not set).
16
+ include_feature_tags: Include user-defined feature tags in the response. Defaults to None (not set).
17
17
"""
18
18
19
- include_names : bool = True
20
- include_data_types : bool = True
21
- include_effective_times : bool = False
22
- include_slo_info : bool = False
23
- include_serving_status : bool = False
24
- include_feature_descriptions : bool = False
25
- include_feature_tags : bool = False
19
+ include_names : Optional [ bool ] = None
20
+ include_data_types : Optional [ bool ] = None
21
+ include_effective_times : Optional [ bool ] = None
22
+ include_slo_info : Optional [ bool ] = None
23
+ include_serving_status : Optional [ bool ] = None
24
+ include_feature_descriptions : Optional [ bool ] = None
25
+ include_feature_tags : Optional [ bool ] = None
26
26
27
27
@classmethod
28
28
def all (cls ):
29
+ """Return a MetadataOptions object with all options set to True"""
29
30
return MetadataOptions (
30
31
include_names = True ,
31
32
include_data_types = True ,
@@ -38,32 +39,57 @@ def all(cls):
38
39
39
40
def to_request (self ) -> Dict [str , bool ]:
40
41
"""Format for inclusion in GetFeaturesRequest"""
41
- return {
42
- "includeNames" : self .include_names ,
43
- "includeDataTypes" : self .include_data_types ,
44
- "includeEffectiveTimes" : self .include_effective_times ,
45
- "includeSloInfo" : self .include_slo_info ,
46
- "includeServingStatus" : self .include_serving_status ,
47
- "includeFeatureDescriptions" : self .include_feature_descriptions ,
48
- "includeFeatureTags" : self .include_feature_tags ,
49
- }
42
+ request_dict = {}
43
+
44
+ if self .include_names is not None :
45
+ request_dict ["includeNames" ] = self .include_names
46
+ if self .include_data_types is not None :
47
+ request_dict ["includeDataTypes" ] = self .include_data_types
48
+ if self .include_effective_times is not None :
49
+ request_dict ["includeEffectiveTimes" ] = self .include_effective_times
50
+ if self .include_slo_info is not None :
51
+ request_dict ["includeSloInfo" ] = self .include_slo_info
52
+ if self .include_serving_status is not None :
53
+ request_dict ["includeServingStatus" ] = self .include_serving_status
54
+ if self .include_feature_descriptions is not None :
55
+ request_dict ["includeFeatureDescriptions" ] = self .include_feature_descriptions
56
+ if self .include_feature_tags is not None :
57
+ request_dict ["includeFeatureTags" ] = self .include_feature_tags
58
+
59
+ return request_dict
50
60
51
61
52
62
@dataclass
53
63
class RequestOptions :
54
64
"""Passed into request_options on get_features, request level options to control feature server behavior.
55
65
56
66
Attributes:
57
- read_from_cache: Disable if you want to skip the cache and read from the online store. Defaults to True.
58
- write_to_cache: Disable if you want to skip writing to the cache. Defaults to True.
67
+ read_from_cache: Disable if you want to skip the cache and read from the online store. Defaults to None (not set).
68
+ write_to_cache: Disable if you want to skip writing to the cache. Defaults to None (not set).
69
+ ignore_extra_request_context_fields: Enable if you don't want to fail the request if there are extra fields nested in Struct fields of request context. Defaults to None (not set).
70
+ latency_budget_ms: Cutoff time for collecting results from feature service request. Once time is elapsed the feature server will make a best effort to return all feature values that have already been computed. Should be 100 or greater. Defaults to None (not set).
71
+ coerce_null_counts_to_zero: Enable if you want to convert null count aggregation feature results to zero. Default behavior is determined by a cluster-wide flag (false by default). Contact Tecton support to change the default behavior. Defaults to None (not set).
59
72
"""
60
73
61
- read_from_cache : bool = True
62
- write_to_cache : bool = True
74
+ read_from_cache : Optional [bool ] = None
75
+ write_to_cache : Optional [bool ] = None
76
+ ignore_extra_request_context_fields : Optional [bool ] = None
77
+ latency_budget_ms : Optional [int ] = None
78
+ coerce_null_counts_to_zero : Optional [bool ] = None
63
79
64
- def to_request (self ) -> Dict [str , bool ]:
80
+ def to_request (self ) -> Dict [str , Any ]:
65
81
"""Format for inclusion in GetFeaturesRequest"""
66
- return {
67
- "readFromCache" : self .read_from_cache ,
68
- "writeToCache" : self .write_to_cache ,
69
- }
82
+ request_dict = {}
83
+
84
+ if self .read_from_cache is not None :
85
+ request_dict ["readFromCache" ] = self .read_from_cache
86
+ if self .write_to_cache is not None :
87
+ request_dict ["writeToCache" ] = self .write_to_cache
88
+ if self .ignore_extra_request_context_fields is not None :
89
+ request_dict ["ignoreExtraRequestContextFields" ] = self .ignore_extra_request_context_fields
90
+ if self .latency_budget_ms is not None :
91
+ request_dict ["latencyBudgetMs" ] = self .latency_budget_ms
92
+ if self .coerce_null_counts_to_zero is not None :
93
+ request_dict ["coerceNullCountsToZero" ] = self .coerce_null_counts_to_zero
94
+
95
+ return request_dict
0 commit comments