MCPcopy Index your code
hub / github.com/feast-dev/feast / apply_sorting

Function apply_sorting

sdk/python/feast/registry_server.py:111–145  ·  view source on GitHub ↗

Apply sorting to a list of objects using dot notation for nested attributes.

(objects: List[Any], sort_by: str, sort_order: str)

Source from the content-addressed store, hash-verified

109
110
111def apply_sorting(objects: List[Any], sort_by: str, sort_order: str) -> List[Any]:
112 """Apply sorting to a list of objects using dot notation for nested attributes."""
113
114 def get_nested_attr(obj, attr_path: str):
115 """Get nested attribute using dot notation."""
116 attrs = attr_path.split(".")
117 current = obj
118 for attr in attrs:
119 if hasattr(current, attr):
120 current = getattr(current, attr)
121 elif isinstance(current, dict) and attr in current:
122 current = current[attr]
123 else:
124 return None
125 return current
126
127 def sort_key(obj):
128 value = get_nested_attr(obj, sort_by)
129 if value is None:
130 return ("", 0, None)
131
132 if isinstance(value, str):
133 return (value.lower(), 1, None)
134 elif isinstance(value, (int, float)):
135 return ("", 1, value)
136 else:
137 return (str(value).lower(), 1, None)
138
139 reverse = sort_order.lower() == "desc"
140
141 try:
142 return sorted(objects, key=sort_key, reverse=reverse)
143 except Exception as e:
144 logger.warning(f"Failed to sort objects by '{sort_by}': {e}")
145 return objects
146
147
148def _build_any_feature_view_proto(feature_view: BaseFeatureView):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected