Skip to content

Commit bcb3b66

Browse files
committed
Make all options optional and update RequestOptions
1 parent febd055 commit bcb3b66

File tree

2 files changed

+60
-34
lines changed

2 files changed

+60
-34
lines changed
Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
from dataclasses import dataclass
2-
from typing import Dict
2+
from typing import Dict, Any, Optional
33

44

55
@dataclass
66
class MetadataOptions:
77
"""Passed into metadata_options on get_features, controls what metadata is returned as part of the response.
88
99
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).
1717
"""
1818

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
2626

2727
@classmethod
2828
def all(cls):
29+
"""Return a MetadataOptions object with all options set to True"""
2930
return MetadataOptions(
3031
include_names=True,
3132
include_data_types=True,
@@ -38,32 +39,57 @@ def all(cls):
3839

3940
def to_request(self) -> Dict[str, bool]:
4041
"""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
5060

5161

5262
@dataclass
5363
class RequestOptions:
5464
"""Passed into request_options on get_features, request level options to control feature server behavior.
5565
5666
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).
5972
"""
6073

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
6379

64-
def to_request(self) -> Dict[str, bool]:
80+
def to_request(self) -> Dict[str, Any]:
6581
"""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

tecton_client/_internal/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def build_get_features_request(
1818
request_context_map: Optional[Dict[str, Any]] = None,
1919
metadata_options: Optional[MetadataOptions] = None,
2020
workspace_name: Optional[str] = None,
21-
request_options: Optional[Dict[str, bool]] = None,
21+
request_options: Optional[RequestOptions] = None,
2222
allow_partial_results: bool = False,
2323
):
2424
params = {

0 commit comments

Comments
 (0)