Skip to content

Commit 9215a9e

Browse files
pradithyafeast-ci-bot
authored andcommitted
Allow registration of feature without warehouse store (#80)
* Allow registration of feature without warehouse store * Change the order of comparison
1 parent 06cb1ec commit 9215a9e

2 files changed

Lines changed: 50 additions & 11 deletions

File tree

core/src/main/java/feast/core/validators/SpecValidator.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public class SpecValidator {
5454
private FeatureInfoRepository featureInfoRepository;
5555
private static final String FILE_ERROR_STORE_TYPE = "file.json";
5656

57+
private static final String NO_STORE = "";
58+
5759
private static String[] SUPPORTED_WAREHOUSE_STORES =
5860
new String[] {
5961
BigQueryStorageManager.TYPE, FILE_ERROR_STORE_TYPE,
@@ -110,8 +112,8 @@ public void validateFeatureSpec(FeatureSpec spec) throws IllegalArgumentExceptio
110112
Strings.lenientFormat("Entity with name %s does not exist", spec.getEntity()));
111113

112114
// TODO: clean up store validation for features
113-
String servingStoreId = "";
114-
String warehouseStoreId = "";
115+
String servingStoreId = NO_STORE;
116+
String warehouseStoreId = NO_STORE;
115117
if (spec.hasDataStores()) {
116118
servingStoreId =
117119
spec.getDataStores().hasServing() ? spec.getDataStores().getServing().getId() : "";
@@ -126,9 +128,9 @@ public void validateFeatureSpec(FeatureSpec spec) throws IllegalArgumentExceptio
126128
}
127129
FeatureGroupInfo group = (FeatureGroupInfo) groupOptional.get();
128130
servingStoreId =
129-
servingStoreId.equals("") ? group.getServingStore().getId() : servingStoreId;
131+
servingStoreId.equals(NO_STORE) ? group.getServingStore().getId() : servingStoreId;
130132
warehouseStoreId =
131-
warehouseStoreId.equals("") ? group.getWarehouseStore().getId() : warehouseStoreId;
133+
warehouseStoreId.equals(NO_STORE) ? group.getWarehouseStore().getId() : warehouseStoreId;
132134
}
133135
Optional<StorageInfo> servingStore = storageInfoRepository.findById(servingStoreId);
134136
Optional<StorageInfo> warehouseStore = storageInfoRepository.findById(warehouseStoreId);
@@ -138,13 +140,17 @@ public void validateFeatureSpec(FeatureSpec spec) throws IllegalArgumentExceptio
138140
checkArgument(
139141
Arrays.asList(SUPPORTED_SERVING_STORES).contains(servingStore.get().getType()),
140142
Strings.lenientFormat("Unsupported serving store type", servingStore.get().getType()));
141-
checkArgument(
142-
warehouseStore.isPresent(),
143-
Strings.lenientFormat("Warehouse store with id %s does not exist", warehouseStoreId));
144-
checkArgument(
145-
Arrays.asList(SUPPORTED_WAREHOUSE_STORES).contains(warehouseStore.get().getType()),
146-
Strings.lenientFormat(
147-
"Unsupported warehouse store type", warehouseStore.get().getType()));
143+
144+
if (!warehouseStoreId.equals(NO_STORE)) {
145+
checkArgument(
146+
warehouseStore.isPresent(),
147+
Strings.lenientFormat("Warehouse store with id %s does not exist", warehouseStoreId));
148+
149+
checkArgument(
150+
Arrays.asList(SUPPORTED_WAREHOUSE_STORES).contains(warehouseStore.get().getType()),
151+
Strings.lenientFormat(
152+
"Unsupported warehouse store type", warehouseStore.get().getType()));
153+
}
148154

149155
} catch (NullPointerException | IllegalArgumentException e) {
150156
throw new IllegalArgumentException(

core/src/test/java/feast/core/validators/SpecValidatorTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,39 @@ public void featureSpecWithoutExistingWarehouseStoreShouldThrowIllegalArgumentEx
396396
validator.validateFeatureSpec(input);
397397
}
398398

399+
@Test
400+
public void featureSpecWithoutWarehouseStoreShouldBeAllowed() {
401+
String servingStoreId = "REDIS1";
402+
when(entityInfoRepository.existsById("entity")).thenReturn(true);
403+
when(storageInfoRepository.existsById(servingStoreId)).thenReturn(true);
404+
405+
StorageInfo redis1 = new StorageInfo();
406+
redis1.setId(servingStoreId);
407+
redis1.setType("redis");
408+
when(storageInfoRepository.findById( servingStoreId)).thenReturn(Optional.of(redis1));
409+
410+
SpecValidator validator =
411+
new SpecValidator(
412+
storageInfoRepository,
413+
entityInfoRepository,
414+
featureGroupInfoRepository,
415+
featureInfoRepository);
416+
DataStore servingStore = DataStore.newBuilder().setId(servingStoreId).build();
417+
DataStores dataStores =
418+
DataStores.newBuilder().setServing(servingStore).build();
419+
FeatureSpec input =
420+
FeatureSpec.newBuilder()
421+
.setId("entity.none.name")
422+
.setName("name")
423+
.setOwner("owner")
424+
.setDescription("dasdad")
425+
.setEntity("entity")
426+
.setGranularity(Granularity.Enum.forNumber(0))
427+
.setDataStores(dataStores)
428+
.build();
429+
validator.validateFeatureSpec(input);
430+
}
431+
399432
@Test
400433
public void featureSpecWithUnsupportedWarehouseStoreShouldThrowIllegalArgumentException() {
401434
String servingStoreId = "REDIS1";

0 commit comments

Comments
 (0)