1818package feast .ingestion .model ;
1919
2020import com .google .common .base .Preconditions ;
21+ import com .google .common .collect .Lists ;
2122import feast .ingestion .service .SpecService ;
2223import feast .specs .EntitySpecProto .EntitySpec ;
2324import feast .specs .FeatureSpecProto .FeatureSpec ;
3132import java .util .Map .Entry ;
3233import lombok .Builder ;
3334import lombok .Getter ;
35+ import lombok .ToString ;
36+ import lombok .extern .slf4j .Slf4j ;
3437
3538@ Builder
3639@ Getter
40+ @ Slf4j
41+ @ ToString
3742public class Specs implements Serializable {
43+
3844 private String jobName ;
3945 private ImportSpec importSpec ;
4046 private Map <String , EntitySpec > entitySpecs ;
@@ -57,14 +63,23 @@ public static Specs of(String jobName, ImportSpec importSpec, SpecService specSe
5763 specsBuilder .featureSpecs (specService .getFeatureSpecs (featureIds ));
5864
5965 List <String > entityNames = importSpec .getEntitiesList ();
66+ List <String > storageIds = Lists .newArrayList ();
6067 for (FeatureSpec featureSpec : specsBuilder .featureSpecs .values ()) {
6168 Preconditions .checkArgument (
6269 entityNames .contains (featureSpec .getEntity ()),
6370 "Feature has entity not listed in import spec featureSpec=" + featureSpec .toString ());
71+ String servingId = featureSpec .getDataStores ().getServing ().getId ();
72+ if (!servingId .isEmpty ()) {
73+ storageIds .add (servingId );
74+ }
75+ String warehouseId = featureSpec .getDataStores ().getWarehouse ().getId ();
76+ if (!warehouseId .isEmpty ()) {
77+ storageIds .add (warehouseId );
78+ }
6479 }
6580 specsBuilder .entitySpecs (specService .getEntitySpecs (entityNames ));
6681
67- specsBuilder .storageSpecs (specService .getAllStorageSpecs ( ));
82+ specsBuilder .storageSpecs (specService .getStorageSpecs ( storageIds ));
6883
6984 return specsBuilder .build ();
7085 } catch (RuntimeException e ) {
@@ -79,13 +94,19 @@ public void validate() {
7994
8095 // Sanity checks that our maps are built correctly
8196 for (Entry <String , FeatureSpec > entry : featureSpecs .entrySet ()) {
82- Preconditions .checkArgument (entry .getKey ().equals (entry .getValue ().getId ()));
97+ Preconditions .checkArgument (entry .getKey ().equals (entry .getValue ().getId ()),
98+ String .format ("Feature id does not match spec %s!=%s" , entry .getKey (),
99+ entry .getValue ().getId ()));
83100 }
84101 for (Entry <String , EntitySpec > entry : entitySpecs .entrySet ()) {
85- Preconditions .checkArgument (entry .getKey ().equals (entry .getValue ().getName ()));
102+ Preconditions .checkArgument (entry .getKey ().equals (entry .getValue ().getName ()),
103+ String .format ("Entity name does not match spec %s!=%s" , entry .getKey (),
104+ entry .getValue ().getName ()));
86105 }
87106 for (Entry <String , StorageSpec > entry : storageSpecs .entrySet ()) {
88- Preconditions .checkArgument (entry .getKey ().equals (entry .getValue ().getId ()));
107+ Preconditions .checkArgument (entry .getKey ().equals (entry .getValue ().getId ()),
108+ String .format ("Storage id does not match spec %s!=%s" , entry .getKey (),
109+ entry .getValue ().getId ()));
89110 }
90111
91112 for (FeatureSpec featureSpec : featureSpecs .values ()) {
@@ -96,17 +117,21 @@ public void validate() {
96117 "Feature %s references unknown entity %s" ,
97118 featureSpec .getId (), featureSpec .getEntity ()));
98119 // Check that feature has a matching serving store
99- Preconditions .checkArgument (
100- storageSpecs .containsKey (featureSpec .getDataStores ().getServing ().getId ()),
101- String .format (
102- "Feature %s references unknown serving store %s" ,
103- featureSpec .getId (), featureSpec .getDataStores ().getServing ().getId ()));
120+ if (!featureSpec .getDataStores ().getServing ().getId ().isEmpty ()) {
121+ Preconditions .checkArgument (
122+ storageSpecs .containsKey (featureSpec .getDataStores ().getServing ().getId ()),
123+ String .format (
124+ "Feature %s references unknown serving store %s" ,
125+ featureSpec .getId (), featureSpec .getDataStores ().getServing ().getId ()));
126+ }
104127 // Check that feature has a matching warehouse store
105- Preconditions .checkArgument (
106- storageSpecs .containsKey (featureSpec .getDataStores ().getWarehouse ().getId ()),
107- String .format (
108- "Feature %s references unknown warehouse store %s" ,
109- featureSpec .getId (), featureSpec .getDataStores ().getWarehouse ().getId ()));
128+ if (!featureSpec .getDataStores ().getWarehouse ().getId ().isEmpty ()) {
129+ Preconditions .checkArgument (
130+ storageSpecs .containsKey (featureSpec .getDataStores ().getWarehouse ().getId ()),
131+ String .format (
132+ "Feature %s references unknown warehouse store %s" ,
133+ featureSpec .getId (), featureSpec .getDataStores ().getWarehouse ().getId ()));
134+ }
110135 }
111136 }
112137
0 commit comments