Skip to content

Commit 495b435

Browse files
authored
fix: Preserve ordering of features in _get_column_names (#2457)
* Preserve ordering of features in _get_column_names * Correction + unit test Signed-off-by: David Y Liu <davidyliuliu@gmail.com> * lint corrections Signed-off-by: David Y Liu <davidyliuliu@gmail.com> * correction Signed-off-by: David Y Liu <davidyliuliu@gmail.com> * my 'make lint' seems to work differently than the ones in the PR tests. Reverting lint changes Signed-off-by: David Y Liu <davidyliuliu@gmail.com>
1 parent 4fa73a9 commit 495b435

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

‎sdk/python/feast/infra/provider.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,13 @@ def _get_column_names(
290290

291291
# We need to exclude join keys and timestamp columns from the list of features, after they are mapped to
292292
# their final column names via the `field_mapping` field of the source.
293-
_feature_names = set(feature_names) - set(join_keys)
294-
_feature_names = _feature_names - {event_timestamp_column, created_timestamp_column}
295-
feature_names = list(_feature_names)
293+
feature_names = [
294+
name
295+
for name in feature_names
296+
if name not in join_keys
297+
and name != event_timestamp_column
298+
and name != created_timestamp_column
299+
]
296300
return (
297301
join_keys,
298302
feature_names,

sdk/python/tests/unit/online_store/test_dynamodb_online_store.py renamed to sdk/python/tests/unit/infra/online_store/test_dynamodb_online_store.py

File renamed without changes.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2020 The Feast Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from datetime import timedelta
16+
17+
from feast import BigQuerySource
18+
from feast.entity import Entity
19+
from feast.feature import Feature
20+
from feast.feature_view import FeatureView
21+
from feast.infra.provider import _get_column_names
22+
from feast.value_type import ValueType
23+
24+
25+
def test_get_column_names_preserves_feature_ordering():
26+
entity = Entity("my-entity", description="My entity", value_type=ValueType.STRING)
27+
fv = FeatureView(
28+
name="my-fv",
29+
entities=["my-entity"],
30+
ttl=timedelta(days=1),
31+
batch_source=BigQuerySource(table="non-existent-mock"),
32+
features=[
33+
Feature(name="a", dtype=ValueType.STRING),
34+
Feature(name="b", dtype=ValueType.STRING),
35+
Feature(name="c", dtype=ValueType.STRING),
36+
Feature(name="d", dtype=ValueType.STRING),
37+
Feature(name="e", dtype=ValueType.STRING),
38+
Feature(name="f", dtype=ValueType.STRING),
39+
Feature(name="g", dtype=ValueType.STRING),
40+
Feature(name="h", dtype=ValueType.STRING),
41+
Feature(name="i", dtype=ValueType.STRING),
42+
Feature(name="j", dtype=ValueType.STRING),
43+
],
44+
)
45+
46+
_, feature_list, _, _ = _get_column_names(fv, [entity])
47+
assert feature_list == ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

0 commit comments

Comments
 (0)