|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * Copyright 2018-2020 The Feast Authors |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package feast.common.models; |
| 18 | + |
| 19 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 20 | +import static org.hamcrest.core.IsEqual.equalTo; |
| 21 | + |
| 22 | +import feast.proto.core.FeatureSetProto.EntitySpec; |
| 23 | +import feast.proto.core.FeatureSetProto.FeatureSetSpec; |
| 24 | +import feast.proto.core.FeatureSetProto.FeatureSpec; |
| 25 | +import feast.proto.core.FeatureSetReferenceProto; |
| 26 | +import feast.proto.types.ValueProto; |
| 27 | +import java.util.Arrays; |
| 28 | +import java.util.List; |
| 29 | +import org.junit.Before; |
| 30 | +import org.junit.Test; |
| 31 | +import org.tensorflow.metadata.v0.*; |
| 32 | + |
| 33 | +public class FeatureSetTest { |
| 34 | + |
| 35 | + private List<EntitySpec> entitySpecs; |
| 36 | + private List<FeatureSpec> featureSpecs; |
| 37 | + |
| 38 | + @Before |
| 39 | + public void setUp() { |
| 40 | + // Entity Specs |
| 41 | + EntitySpec entitySpec1 = |
| 42 | + EntitySpec.newBuilder() |
| 43 | + .setName("entity1") |
| 44 | + .setValueType(ValueProto.ValueType.Enum.INT64) |
| 45 | + .build(); |
| 46 | + EntitySpec entitySpec2 = |
| 47 | + EntitySpec.newBuilder() |
| 48 | + .setName("entity2") |
| 49 | + .setValueType(ValueProto.ValueType.Enum.INT64) |
| 50 | + .build(); |
| 51 | + |
| 52 | + // Feature Specs |
| 53 | + FeatureSpec featureSpec1 = |
| 54 | + FeatureSpec.newBuilder() |
| 55 | + .setName("feature1") |
| 56 | + .setValueType(ValueProto.ValueType.Enum.INT64) |
| 57 | + .setPresence(FeaturePresence.getDefaultInstance()) |
| 58 | + .setShape(FixedShape.getDefaultInstance()) |
| 59 | + .setDomain("mydomain") |
| 60 | + .build(); |
| 61 | + FeatureSpec featureSpec2 = |
| 62 | + FeatureSpec.newBuilder() |
| 63 | + .setName("feature2") |
| 64 | + .setValueType(ValueProto.ValueType.Enum.INT64) |
| 65 | + .setGroupPresence(FeaturePresenceWithinGroup.getDefaultInstance()) |
| 66 | + .setValueCount(ValueCount.getDefaultInstance()) |
| 67 | + .setIntDomain(IntDomain.getDefaultInstance()) |
| 68 | + .build(); |
| 69 | + |
| 70 | + entitySpecs = Arrays.asList(entitySpec1, entitySpec2); |
| 71 | + featureSpecs = Arrays.asList(featureSpec1, featureSpec2); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + public void shouldReturnFeatureSetStringRef() { |
| 76 | + FeatureSetSpec featureSetSpec = |
| 77 | + FeatureSetSpec.newBuilder() |
| 78 | + .setProject("project1") |
| 79 | + .setName("featureSetWithConstraints") |
| 80 | + .addAllEntities(entitySpecs) |
| 81 | + .addAllFeatures(featureSpecs) |
| 82 | + .build(); |
| 83 | + |
| 84 | + FeatureSetReferenceProto.FeatureSetReference featureSetReference = |
| 85 | + FeatureSetReferenceProto.FeatureSetReference.newBuilder() |
| 86 | + .setName(featureSetSpec.getName()) |
| 87 | + .setProject(featureSetSpec.getProject()) |
| 88 | + .build(); |
| 89 | + |
| 90 | + String actualFeatureSetStringRef1 = FeatureSet.getFeatureSetStringRef(featureSetSpec); |
| 91 | + String actualFeatureSetStringRef2 = FeatureSet.getFeatureSetStringRef(featureSetReference); |
| 92 | + String expectedFeatureSetStringRef = "project1/featureSetWithConstraints"; |
| 93 | + |
| 94 | + assertThat(actualFeatureSetStringRef1, equalTo(expectedFeatureSetStringRef)); |
| 95 | + assertThat(actualFeatureSetStringRef2, equalTo(expectedFeatureSetStringRef)); |
| 96 | + } |
| 97 | +} |
0 commit comments