Skip to content

Commit edd0796

Browse files
author
zhilingc
committed
Add maxage to feature set facade
1 parent 456c56b commit edd0796

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

core/src/main/java/feast/core/model/FeatureSet.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package feast.core.model;
22

3+
import com.google.protobuf.Duration;
34
import com.google.protobuf.InvalidProtocolBufferException;
45
import feast.core.FeatureSetProto.EntitySpec;
56
import feast.core.FeatureSetProto.FeatureSetSpec;
@@ -43,6 +44,10 @@ public class FeatureSet extends AbstractTimestampEntity implements Comparable<Fe
4344
@Column(name = "version")
4445
private int version;
4546

47+
// Max allowed staleness for features in this featureSet.
48+
@Column(name = "max_age")
49+
private long maxAgeSeconds;
50+
4651
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
4752
@Fetch(value = FetchMode.SUBSELECT)
4853
@JoinColumn(name = "entities")
@@ -63,25 +68,17 @@ public FeatureSet() {
6368
super();
6469
}
6570

66-
public FeatureSet(String name, int version, List<Field> entities, List<Field> features,
71+
public FeatureSet(String name, int version, long maxAgeSeconds, List<Field> entities, List<Field> features,
6772
Source source) {
6873
this.id = String.format("%s:%s", name, version);
6974
this.name = name;
7075
this.version = version;
76+
this.maxAgeSeconds = maxAgeSeconds;
7177
this.entities = entities;
7278
this.features = features;
7379
this.source = source;
7480
}
7581

76-
/**
77-
* Updates the source of the featureset to point to the correct topic.
78-
*
79-
* @param topic topic to write this featureset to.
80-
*/
81-
public void updateSourceTopic(String topic) throws InvalidProtocolBufferException {
82-
source.setTopic(topic);
83-
}
84-
8582
public static FeatureSet fromProto(FeatureSetSpec featureSetSpec) {
8683
Source source = Source.fromProto(featureSetSpec.getSource());
8784
String id = String.format("%s:%d", featureSetSpec.getName(), featureSetSpec.getVersion());
@@ -100,6 +97,7 @@ public static FeatureSet fromProto(FeatureSetSpec featureSetSpec) {
10097

10198
return new FeatureSet(featureSetSpec.getName(),
10299
featureSetSpec.getVersion(),
100+
featureSetSpec.getMaxAge().getSeconds(),
103101
entities,
104102
features,
105103
source);
@@ -124,6 +122,7 @@ public FeatureSetSpec toProto() throws InvalidProtocolBufferException {
124122
return FeatureSetSpec.newBuilder()
125123
.setName(name)
126124
.setVersion(version)
125+
.setMaxAge(Duration.newBuilder().setSeconds(maxAgeSeconds))
127126
.addAllEntities(entitySpecs)
128127
.addAllFeatures(featureSpecs)
129128
.setSource(source.toProto())

core/src/test/java/feast/core/service/SpecServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ private FeatureSet newDummyFeatureSet(String name, int version) {
365365
.build();
366366
Field feature = new Field(name, "feature", Enum.INT64);
367367
Field entity = new Field(name, "entity", Enum.STRING);
368-
return new FeatureSet(name, version, Arrays.asList(entity), Arrays.asList(feature),
368+
return new FeatureSet(name, version, 100L, Arrays.asList(entity), Arrays.asList(feature),
369369
new Source(
370370
SourceType.KAFKA, kafkaFeatureSourceOptions.toByteArray()));
371371
}

0 commit comments

Comments
 (0)