|
31 | 31 | import org.apache.beam.sdk.transforms.DoFn; |
32 | 32 | import org.apache.beam.sdk.values.PCollectionView; |
33 | 33 | import org.apache.beam.sdk.values.TupleTag; |
| 34 | +import org.slf4j.Logger; |
| 35 | +import org.slf4j.LoggerFactory; |
34 | 36 |
|
35 | 37 | @AutoValue |
36 | 38 | public abstract class ValidateFeatureRowDoFn extends DoFn<FeatureRow, FeatureRow> { |
| 39 | + private static final Logger log = LoggerFactory.getLogger(ValidateFeatureRowDoFn.class); |
37 | 40 |
|
38 | 41 | public abstract PCollectionView<Map<String, Iterable<FeatureSetProto.FeatureSetSpec>>> |
39 | 42 | getFeatureSets(); |
@@ -65,40 +68,43 @@ public void processElement(ProcessContext context) { |
65 | 68 | FeatureRow featureRow = context.element(); |
66 | 69 | Iterable<FeatureSetProto.FeatureSetSpec> featureSetSpecs = |
67 | 70 | context.sideInput(getFeatureSets()).get(featureRow.getFeatureSet()); |
| 71 | + if (featureSetSpecs == null) { |
| 72 | + log.warn( |
| 73 | + String.format( |
| 74 | + "FeatureRow contains invalid featureSetReference %s." |
| 75 | + + " Please check that the feature rows are being published" |
| 76 | + + " to the correct topic on the feature stream.", |
| 77 | + featureRow.getFeatureSet())); |
| 78 | + return; |
| 79 | + } |
68 | 80 |
|
69 | 81 | List<FieldProto.Field> fields = new ArrayList<>(); |
70 | | - if (featureSetSpecs != null) { |
71 | | - FeatureSetProto.FeatureSetSpec latestSpec = Iterators.getLast(featureSetSpecs.iterator()); |
72 | | - FeatureSet featureSet = new FeatureSet(latestSpec); |
73 | | - |
74 | | - for (FieldProto.Field field : featureRow.getFieldsList()) { |
75 | | - Field fieldSpec = featureSet.getField(field.getName()); |
76 | | - if (fieldSpec == null) { |
77 | | - // skip |
78 | | - continue; |
79 | | - } |
80 | | - // If value is set in the FeatureRow, make sure the value type matches |
81 | | - // that defined in FeatureSetSpec |
82 | | - if (!field.getValue().getValCase().equals(ValCase.VAL_NOT_SET)) { |
83 | | - int expectedTypeFieldNumber = fieldSpec.getType().getNumber(); |
84 | | - int actualTypeFieldNumber = field.getValue().getValCase().getNumber(); |
85 | | - if (expectedTypeFieldNumber != actualTypeFieldNumber) { |
86 | | - error = |
87 | | - String.format( |
88 | | - "FeatureRow contains field '%s' with invalid type '%s'. Feast expects the field type to match that in FeatureSet '%s'. Please check the FeatureRow data.", |
89 | | - field.getName(), field.getValue().getValCase(), fieldSpec.getType()); |
90 | | - break; |
91 | | - } |
92 | | - } |
93 | | - if (!fields.contains(field)) { |
94 | | - fields.add(field); |
| 82 | + |
| 83 | + FeatureSetProto.FeatureSetSpec latestSpec = Iterators.getLast(featureSetSpecs.iterator()); |
| 84 | + FeatureSet featureSet = new FeatureSet(latestSpec); |
| 85 | + |
| 86 | + for (FieldProto.Field field : featureRow.getFieldsList()) { |
| 87 | + Field fieldSpec = featureSet.getField(field.getName()); |
| 88 | + if (fieldSpec == null) { |
| 89 | + // skip |
| 90 | + continue; |
| 91 | + } |
| 92 | + // If value is set in the FeatureRow, make sure the value type matches |
| 93 | + // that defined in FeatureSetSpec |
| 94 | + if (!field.getValue().getValCase().equals(ValCase.VAL_NOT_SET)) { |
| 95 | + int expectedTypeFieldNumber = fieldSpec.getType().getNumber(); |
| 96 | + int actualTypeFieldNumber = field.getValue().getValCase().getNumber(); |
| 97 | + if (expectedTypeFieldNumber != actualTypeFieldNumber) { |
| 98 | + error = |
| 99 | + String.format( |
| 100 | + "FeatureRow contains field '%s' with invalid type '%s'. Feast expects the field type to match that in FeatureSet '%s'. Please check the FeatureRow data.", |
| 101 | + field.getName(), field.getValue().getValCase(), fieldSpec.getType()); |
| 102 | + break; |
95 | 103 | } |
96 | 104 | } |
97 | | - } else { |
98 | | - error = |
99 | | - String.format( |
100 | | - "FeatureRow contains invalid feature set id %s. Please check that the feature rows are being published to the correct topic on the feature stream.", |
101 | | - featureRow.getFeatureSet()); |
| 105 | + if (!fields.contains(field)) { |
| 106 | + fields.add(field); |
| 107 | + } |
102 | 108 | } |
103 | 109 |
|
104 | 110 | if (error != null) { |
|
0 commit comments