Skip to content

Commit

Permalink
Allow registration of feature without warehouse store (#80)
Browse files Browse the repository at this point in the history
* Allow registration of feature without warehouse store

* Change the order of comparison
  • Loading branch information
pradithya authored and feast-ci-bot committed Jan 17, 2019
1 parent 06cb1ec commit 9215a9e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
28 changes: 17 additions & 11 deletions core/src/main/java/feast/core/validators/SpecValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class SpecValidator {
private FeatureInfoRepository featureInfoRepository;
private static final String FILE_ERROR_STORE_TYPE = "file.json";

private static final String NO_STORE = "";

private static String[] SUPPORTED_WAREHOUSE_STORES =
new String[] {
BigQueryStorageManager.TYPE, FILE_ERROR_STORE_TYPE,
Expand Down Expand Up @@ -110,8 +112,8 @@ public void validateFeatureSpec(FeatureSpec spec) throws IllegalArgumentExceptio
Strings.lenientFormat("Entity with name %s does not exist", spec.getEntity()));

// TODO: clean up store validation for features
String servingStoreId = "";
String warehouseStoreId = "";
String servingStoreId = NO_STORE;
String warehouseStoreId = NO_STORE;
if (spec.hasDataStores()) {
servingStoreId =
spec.getDataStores().hasServing() ? spec.getDataStores().getServing().getId() : "";
Expand All @@ -126,9 +128,9 @@ public void validateFeatureSpec(FeatureSpec spec) throws IllegalArgumentExceptio
}
FeatureGroupInfo group = (FeatureGroupInfo) groupOptional.get();
servingStoreId =
servingStoreId.equals("") ? group.getServingStore().getId() : servingStoreId;
servingStoreId.equals(NO_STORE) ? group.getServingStore().getId() : servingStoreId;
warehouseStoreId =
warehouseStoreId.equals("") ? group.getWarehouseStore().getId() : warehouseStoreId;
warehouseStoreId.equals(NO_STORE) ? group.getWarehouseStore().getId() : warehouseStoreId;
}
Optional<StorageInfo> servingStore = storageInfoRepository.findById(servingStoreId);
Optional<StorageInfo> warehouseStore = storageInfoRepository.findById(warehouseStoreId);
Expand All @@ -138,13 +140,17 @@ public void validateFeatureSpec(FeatureSpec spec) throws IllegalArgumentExceptio
checkArgument(
Arrays.asList(SUPPORTED_SERVING_STORES).contains(servingStore.get().getType()),
Strings.lenientFormat("Unsupported serving store type", servingStore.get().getType()));
checkArgument(
warehouseStore.isPresent(),
Strings.lenientFormat("Warehouse store with id %s does not exist", warehouseStoreId));
checkArgument(
Arrays.asList(SUPPORTED_WAREHOUSE_STORES).contains(warehouseStore.get().getType()),
Strings.lenientFormat(
"Unsupported warehouse store type", warehouseStore.get().getType()));

if (!warehouseStoreId.equals(NO_STORE)) {
checkArgument(
warehouseStore.isPresent(),
Strings.lenientFormat("Warehouse store with id %s does not exist", warehouseStoreId));

checkArgument(
Arrays.asList(SUPPORTED_WAREHOUSE_STORES).contains(warehouseStore.get().getType()),
Strings.lenientFormat(
"Unsupported warehouse store type", warehouseStore.get().getType()));
}

} catch (NullPointerException | IllegalArgumentException e) {
throw new IllegalArgumentException(
Expand Down
33 changes: 33 additions & 0 deletions core/src/test/java/feast/core/validators/SpecValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,39 @@ public void featureSpecWithoutExistingWarehouseStoreShouldThrowIllegalArgumentEx
validator.validateFeatureSpec(input);
}

@Test
public void featureSpecWithoutWarehouseStoreShouldBeAllowed() {
String servingStoreId = "REDIS1";
when(entityInfoRepository.existsById("entity")).thenReturn(true);
when(storageInfoRepository.existsById(servingStoreId)).thenReturn(true);

StorageInfo redis1 = new StorageInfo();
redis1.setId(servingStoreId);
redis1.setType("redis");
when(storageInfoRepository.findById( servingStoreId)).thenReturn(Optional.of(redis1));

SpecValidator validator =
new SpecValidator(
storageInfoRepository,
entityInfoRepository,
featureGroupInfoRepository,
featureInfoRepository);
DataStore servingStore = DataStore.newBuilder().setId(servingStoreId).build();
DataStores dataStores =
DataStores.newBuilder().setServing(servingStore).build();
FeatureSpec input =
FeatureSpec.newBuilder()
.setId("entity.none.name")
.setName("name")
.setOwner("owner")
.setDescription("dasdad")
.setEntity("entity")
.setGranularity(Granularity.Enum.forNumber(0))
.setDataStores(dataStores)
.build();
validator.validateFeatureSpec(input);
}

@Test
public void featureSpecWithUnsupportedWarehouseStoreShouldThrowIllegalArgumentException() {
String servingStoreId = "REDIS1";
Expand Down

0 comments on commit 9215a9e

Please sign in to comment.