Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow entities and features to be updated #1105

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions core/src/main/java/feast/core/model/FeatureTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import feast.proto.core.FeatureTableProto;
import feast.proto.core.FeatureTableProto.FeatureTableSpec;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -158,7 +156,8 @@ public static FeatureTable fromProto(
* @param spec the Protobuf spec to update the FeatureTable from.
* @throws IllegalArgumentException if the update will make prohibited changes.
*/
public void updateFromProto(FeatureTableSpec spec) {
public void updateFromProto(
String projectName, FeatureTableSpec spec, EntityRepository entityRepo) {
// Check for prohibited changes made in spec:
// - Name cannot be changed
if (!getName().equals(spec.getName())) {
Expand All @@ -167,16 +166,11 @@ public void updateFromProto(FeatureTableSpec spec) {
"Updating the name of a registered FeatureTable is not allowed: %s to %s",
getName(), spec.getName()));
}
// - Entities cannot be changed
List<String> entityNames =
getEntities().stream().map(EntityV2::getName).collect(Collectors.toList());
if (!new HashSet<>(entityNames).equals(new HashSet<>(spec.getEntitiesList()))) {
Collections.sort(entityNames);
throw new IllegalArgumentException(
String.format(
"Updating the entities of a registered FeatureTable is not allowed: %s to %s",
entityNames, spec.getEntitiesList()));
}
// Update Entities if changed
Set<EntityV2> entities =
FeatureTable.resolveEntities(
projectName, spec.getName(), entityRepo, spec.getEntitiesList());
this.setEntities(entities);

// Update FeatureTable based on spec
// Update existing features, create new feature, drop missing features
Expand Down
11 changes: 5 additions & 6 deletions core/src/main/java/feast/core/model/FeatureV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
import java.util.Objects;
import javax.persistence.*;
import javax.persistence.Entity;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;

/** Defines a single Feature defined in a {@link FeatureTable} */
@Getter
@Entity
@Setter(AccessLevel.PRIVATE)
@Table(
name = "features_v2",
uniqueConstraints = @UniqueConstraint(columnNames = {"name", "feature_table_id"}))
Expand Down Expand Up @@ -96,12 +99,8 @@ public void updateFromProto(FeatureSpecV2 spec) {
"Updating the name of a registered Feature is not allowed: %s to %s",
getName(), spec.getName()));
}
if (!getType().equals(spec.getValueType())) {
throw new IllegalArgumentException(
String.format(
"Updating the value type of a registered Feature is not allowed: %s to %s",
getType(), spec.getValueType()));
}
// Update feature type
this.setType(spec.getValueType());

// Update Feature based on spec
this.labelsJSON = TypeConversion.convertMapToJsonString(spec.getLabelsMap());
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/feast/core/service/SpecService.java
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ public ApplyFeatureTableResponse applyFeatureTable(ApplyFeatureTableRequest requ
return ApplyFeatureTableResponse.newBuilder().setTable(existingTable.get().toProto()).build();
}
if (existingTable.isPresent()) {
existingTable.get().updateFromProto(applySpec);
existingTable.get().updateFromProto(projectName, applySpec, entityRepository);
table = existingTable.get();
}

Expand Down
82 changes: 35 additions & 47 deletions core/src/test/java/feast/core/service/SpecServiceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1108,39 +1108,9 @@ public void shouldUpdateExistingTableWithValidSpec() {
}

@Test
public void shouldNotUpdateIfNoChanges() {
FeatureTableProto.FeatureTable table = apiClient.applyFeatureTable("default", getTestSpec());
FeatureTableProto.FeatureTable updatedTable =
apiClient.applyFeatureTable("default", getTestSpec());

assertThat(updatedTable.getMeta().getRevision(), equalTo(table.getMeta().getRevision()));
}

@Test
public void shouldErrorOnMissingBatchSource() {
FeatureTableProto.FeatureTableSpec spec =
DataGenerator.createFeatureTableSpec(
"ft",
List.of("entity1"),
Map.of("event_timestamp", ValueProto.ValueType.Enum.INT64),
3600,
Map.of())
.toBuilder()
.build();

StatusRuntimeException exc =
assertThrows(
StatusRuntimeException.class, () -> apiClient.applyFeatureTable("default", spec));

assertThat(
exc.getMessage(),
equalTo("INVALID_ARGUMENT: FeatureTable batch source cannot be empty."));
}

@Test
public void shouldErrorIfEntityChangeOnUpdate() {
public void shouldUpdateFeatureTableOnEntityChange() {
List<String> entities = Arrays.asList("entity1", "entity2");
FeatureTableProto.FeatureTableSpec spec =
FeatureTableProto.FeatureTableSpec updatedSpec =
DataGenerator.createFeatureTableSpec(
"featuretable1",
Arrays.asList("entity1"),
Expand All @@ -1157,21 +1127,15 @@ public void shouldErrorIfEntityChangeOnUpdate() {
DataGenerator.createFileDataSourceSpec("file:///path/to/file", "ts_col", ""))
.build();

StatusRuntimeException exc =
assertThrows(
StatusRuntimeException.class, () -> apiClient.applyFeatureTable("default", spec));
FeatureTableProto.FeatureTable updatedTable =
apiClient.applyFeatureTable("default", updatedSpec);

assertThat(
exc.getMessage(),
equalTo(
String.format(
"INVALID_ARGUMENT: Updating the entities of a registered FeatureTable is not allowed: %s to %s",
entities, spec.getEntitiesList())));
assertTrue(TestUtil.compareFeatureTableSpec(updatedTable.getSpec(), updatedSpec));
}

@Test
public void shouldErrorIfFeatureValueTypeChangeOnUpdate() {
FeatureTableProto.FeatureTableSpec spec =
public void shouldUpdateFeatureTableOnFeatureTypeChange() {
FeatureTableProto.FeatureTableSpec updatedSpec =
DataGenerator.createFeatureTableSpec(
"featuretable1",
Arrays.asList("entity1", "entity2"),
Expand All @@ -1188,16 +1152,40 @@ public void shouldErrorIfFeatureValueTypeChangeOnUpdate() {
DataGenerator.createFileDataSourceSpec("file:///path/to/file", "ts_col", ""))
.build();

FeatureTableProto.FeatureTable updatedTable =
apiClient.applyFeatureTable("default", updatedSpec);

assertTrue(TestUtil.compareFeatureTableSpec(updatedTable.getSpec(), updatedSpec));
}

@Test
public void shouldNotUpdateIfNoChanges() {
FeatureTableProto.FeatureTable table = apiClient.applyFeatureTable("default", getTestSpec());
FeatureTableProto.FeatureTable updatedTable =
apiClient.applyFeatureTable("default", getTestSpec());

assertThat(updatedTable.getMeta().getRevision(), equalTo(table.getMeta().getRevision()));
}

@Test
public void shouldErrorOnMissingBatchSource() {
FeatureTableProto.FeatureTableSpec spec =
DataGenerator.createFeatureTableSpec(
"ft",
List.of("entity1"),
Map.of("event_timestamp", ValueProto.ValueType.Enum.INT64),
3600,
Map.of())
.toBuilder()
.build();

StatusRuntimeException exc =
assertThrows(
StatusRuntimeException.class, () -> apiClient.applyFeatureTable("default", spec));

assertThat(
exc.getMessage(),
equalTo(
String.format(
"INVALID_ARGUMENT: Updating the value type of a registered Feature is not allowed: %s to %s",
ValueProto.ValueType.Enum.FLOAT, ValueProto.ValueType.Enum.STRING_LIST)));
equalTo("INVALID_ARGUMENT: FeatureTable batch source cannot be empty."));
}

@Test
Expand Down