FeatureTableValidator { public static void validateSpec(FeatureTableSpec spec) { if (spec.getName().isEmpty()) { throw new IllegalArgumentException("FeatureTable name must be provided"); } if (spec.getLabelsMap().containsKey("")) { throw new IllegalArgumentException("FeatureTable cannot have labels with empty key."); } if (spec.getEntitiesCount() == 0) { throw new IllegalArgumentException("FeatureTable entities list cannot be empty."); } if (spec.getFeaturesCount() == 0) { throw new IllegalArgumentException("FeatureTable features list cannot be empty."); } if (!spec.hasBatchSource()) { throw new IllegalArgumentException("FeatureTable batch source cannot be empty."); } checkValidCharacters(spec.getName(), "FeatureTable"); spec.getFeaturesList().forEach(FeatureTableValidator::validateFeatureSpec); if (!spec.getBatchSource().getBigqueryOptions().getTableRef().isEmpty()) { checkValidBigQueryTableRef( spec.getBatchSource().getBigqueryOptions().getTableRef(), "FeatureTable"); } ArrayList<String> fieldNames = new ArrayList<>(spec.getEntitiesList()); fieldNames.addAll( spec.getFeaturesList().stream().map(FeatureSpecV2::getName).collect(Collectors.toList())); if (!Collections.disjoint(fieldNames, RESERVED_NAMES)) { throw new IllegalArgumentException( String.format( "Reserved names has been used as Feature(s) names. Reserved: %s", RESERVED_NAMES)); } if (hasDuplicates(fieldNames)) { throw new IllegalArgumentException( String.format("Entity and Feature names within a Feature Table should be unique.")); } }  static void validateSpec(FeatureTableSpec spec);  }
@Test(expected = IllegalArgumentException.class) public void shouldErrorIfLabelsHasEmptyKey() { Map<String, String> badLabels = Map.of("", "empty"); FeatureTableSpec badSpec = getTestSpec().toBuilder().putAllLabels(badLabels).build(); FeatureTableValidator.validateSpec(badSpec); }
@Test(expected = IllegalArgumentException.class) public void shouldErrorIfFeaturesLabelsHasEmptyKey() { Map<String, String> badLabels = Map.of("", "empty"); List<FeatureSpecV2> badFeatureSpecs = getTestSpec().getFeaturesList().stream() .map(featureSpec -> featureSpec.toBuilder().putAllLabels(badLabels).build()) .collect(Collectors.toList()); FeatureTableSpec badSpec = getTestSpec().toBuilder().addAllFeatures(badFeatureSpecs).build(); FeatureTableValidator.validateSpec(badSpec); }
@Test(expected = IllegalArgumentException.class) public void shouldErrorIfUsedReservedName() { FeatureTableSpec badSpec = getTestSpec().toBuilder().addAllEntities(FeatureTableValidator.RESERVED_NAMES).build(); FeatureTableValidator.validateSpec(badSpec); }
@Test(expected = IllegalArgumentException.class) public void shouldErrorIfNamesUsedNotUnique() { FeatureTableSpec badSpec = DataGenerator.createFeatureTableSpec( "driver", List.of("region"), Map.of("region", STRING), 3600, Map.of()); FeatureTableValidator.validateSpec(badSpec); }