-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Split Field model into distinct Feature and Entity objects #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3c08158
Split Field model into distinct Feature and Entity objects
17904da
Remove TFX fields for entities in testdata
9bcbabe
Split Field model into distinct Feature and Entity objects
2c0a86f
Index jointables
4939b6c
Explicitly name tables, remove redundant constructor
25b8da9
Integrate labels
fc6c498
Fix code comments
7031753
Change FeatureSetId to int
fd9a9d7
Retrieve featuresets from repository so that ids are consistent
d579424
Add uniqueness constraint to FeatureSets, fix tests
935602e
Remove feature and entity references
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright 2018-2019 The Feast Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package feast.core.model; | ||
|
|
||
| import feast.core.FeatureSetProto.EntitySpec; | ||
| import feast.types.ValueProto.ValueType; | ||
| import java.util.Objects; | ||
| import javax.persistence.*; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| /** Feast entity object. Contains name and type of the entity. */ | ||
| @Getter | ||
| @Setter | ||
| @javax.persistence.Entity | ||
| @Table( | ||
| name = "entities", | ||
| uniqueConstraints = @UniqueConstraint(columnNames = {"name", "feature_set_id"})) | ||
| public class Entity { | ||
|
|
||
| @Id @GeneratedValue private Long id; | ||
|
|
||
| private String name; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| private FeatureSet featureSet; | ||
|
|
||
| /** Data type of the entity. String representation of {@link ValueType} * */ | ||
| private String type; | ||
|
|
||
| public Entity() {} | ||
|
|
||
| private Entity(String name, ValueType.Enum type) { | ||
| this.setName(name); | ||
| this.setType(type.toString()); | ||
| } | ||
|
|
||
| public static Entity fromProto(EntitySpec entitySpec) { | ||
| Entity entity = new Entity(entitySpec.getName(), entitySpec.getValueType()); | ||
| return entity; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| Entity entity = (Entity) o; | ||
| return getName().equals(entity.getName()) && getType().equals(entity.getType()); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(super.hashCode(), getName(), getType()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright 2018-2019 The Feast Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package feast.core.model; | ||
|
|
||
| import feast.core.FeatureSetProto.FeatureSpec; | ||
| import feast.core.util.TypeConversion; | ||
| import feast.types.ValueProto.ValueType; | ||
| import java.util.Arrays; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import javax.persistence.*; | ||
| import javax.persistence.Entity; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| /** | ||
| * Feature belonging to a featureset. Contains name, type as well as domain metadata about the | ||
| * feature. | ||
| */ | ||
| @Getter | ||
| @Setter | ||
| @Entity | ||
| @Table( | ||
| name = "features", | ||
| uniqueConstraints = @UniqueConstraint(columnNames = {"name", "feature_set_id"})) | ||
| public class Feature { | ||
|
|
||
| @Id @GeneratedValue private Long id; | ||
|
|
||
| private String name; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| private FeatureSet featureSet; | ||
|
|
||
| /** Data type of the feature. String representation of {@link ValueType} * */ | ||
| private String type; | ||
|
|
||
| // Labels for this feature | ||
| @Column(name = "labels", columnDefinition = "text") | ||
ches marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private String labels; | ||
|
|
||
| // Presence constraints (refer to proto feast.core.FeatureSet.FeatureSpec) | ||
| // Only one of them can be set. | ||
| private byte[] presence; | ||
| private byte[] groupPresence; | ||
|
|
||
| // Shape type (refer to proto feast.core.FeatureSet.FeatureSpec) | ||
| // Only one of them can be set. | ||
| private byte[] shape; | ||
| private byte[] valueCount; | ||
|
|
||
| // Domain info for the values (refer to proto feast.core.FeatureSet.FeatureSpec) | ||
| // Only one of them can be set. | ||
| private String domain; | ||
| private byte[] intDomain; | ||
| private byte[] floatDomain; | ||
| private byte[] stringDomain; | ||
| private byte[] boolDomain; | ||
| private byte[] structDomain; | ||
| private byte[] naturalLanguageDomain; | ||
| private byte[] imageDomain; | ||
| private byte[] midDomain; | ||
| private byte[] urlDomain; | ||
| private byte[] timeDomain; | ||
| private byte[] timeOfDayDomain; | ||
|
|
||
| public Feature() {} | ||
|
|
||
| private Feature(String name, ValueType.Enum type) { | ||
| this.setName(name); | ||
| this.setType(type.toString()); | ||
| } | ||
|
|
||
| public static Feature fromProto(FeatureSpec featureSpec) { | ||
| Feature feature = new Feature(featureSpec.getName(), featureSpec.getValueType()); | ||
| feature.labels = TypeConversion.convertMapToJsonString(featureSpec.getLabelsMap()); | ||
|
|
||
| switch (featureSpec.getPresenceConstraintsCase()) { | ||
| case PRESENCE: | ||
| feature.setPresence(featureSpec.getPresence().toByteArray()); | ||
| break; | ||
| case GROUP_PRESENCE: | ||
| feature.setGroupPresence(featureSpec.getGroupPresence().toByteArray()); | ||
| break; | ||
| case PRESENCECONSTRAINTS_NOT_SET: | ||
| break; | ||
| } | ||
|
|
||
| switch (featureSpec.getShapeTypeCase()) { | ||
| case SHAPE: | ||
| feature.setShape(featureSpec.getShape().toByteArray()); | ||
| break; | ||
| case VALUE_COUNT: | ||
| feature.setValueCount(featureSpec.getValueCount().toByteArray()); | ||
| break; | ||
| case SHAPETYPE_NOT_SET: | ||
| break; | ||
| } | ||
|
|
||
| switch (featureSpec.getDomainInfoCase()) { | ||
| case DOMAIN: | ||
| feature.setDomain(featureSpec.getDomain()); | ||
| break; | ||
| case INT_DOMAIN: | ||
| feature.setIntDomain(featureSpec.getIntDomain().toByteArray()); | ||
| break; | ||
| case FLOAT_DOMAIN: | ||
| feature.setFloatDomain(featureSpec.getFloatDomain().toByteArray()); | ||
| break; | ||
| case STRING_DOMAIN: | ||
| feature.setStringDomain(featureSpec.getStringDomain().toByteArray()); | ||
| break; | ||
| case BOOL_DOMAIN: | ||
| feature.setBoolDomain(featureSpec.getBoolDomain().toByteArray()); | ||
| break; | ||
| case STRUCT_DOMAIN: | ||
| feature.setStructDomain(featureSpec.getStructDomain().toByteArray()); | ||
| break; | ||
| case NATURAL_LANGUAGE_DOMAIN: | ||
| feature.setNaturalLanguageDomain(featureSpec.getNaturalLanguageDomain().toByteArray()); | ||
| break; | ||
| case IMAGE_DOMAIN: | ||
| feature.setImageDomain(featureSpec.getImageDomain().toByteArray()); | ||
| break; | ||
| case MID_DOMAIN: | ||
| feature.setMidDomain(featureSpec.getMidDomain().toByteArray()); | ||
| break; | ||
| case URL_DOMAIN: | ||
| feature.setUrlDomain(featureSpec.getUrlDomain().toByteArray()); | ||
| break; | ||
| case TIME_DOMAIN: | ||
| feature.setTimeDomain(featureSpec.getTimeDomain().toByteArray()); | ||
| break; | ||
| case TIME_OF_DAY_DOMAIN: | ||
| feature.setTimeOfDayDomain(featureSpec.getTimeOfDayDomain().toByteArray()); | ||
| break; | ||
| case DOMAININFO_NOT_SET: | ||
| break; | ||
| } | ||
| return feature; | ||
| } | ||
|
|
||
| public Map<String, String> getLabels() { | ||
| return TypeConversion.convertJsonStringToMap(this.labels); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| Feature feature = (Feature) o; | ||
| return Objects.equals(getName(), feature.getName()) | ||
| && Objects.equals(labels, feature.labels) | ||
| && Arrays.equals(getPresence(), feature.getPresence()) | ||
| && Arrays.equals(getGroupPresence(), feature.getGroupPresence()) | ||
| && Arrays.equals(getShape(), feature.getShape()) | ||
| && Arrays.equals(getValueCount(), feature.getValueCount()) | ||
| && Objects.equals(getDomain(), feature.getDomain()) | ||
| && Arrays.equals(getIntDomain(), feature.getIntDomain()) | ||
| && Arrays.equals(getFloatDomain(), feature.getFloatDomain()) | ||
| && Arrays.equals(getStringDomain(), feature.getStringDomain()) | ||
| && Arrays.equals(getBoolDomain(), feature.getBoolDomain()) | ||
| && Arrays.equals(getStructDomain(), feature.getStructDomain()) | ||
| && Arrays.equals(getNaturalLanguageDomain(), feature.getNaturalLanguageDomain()) | ||
| && Arrays.equals(getImageDomain(), feature.getImageDomain()) | ||
| && Arrays.equals(getMidDomain(), feature.getMidDomain()) | ||
| && Arrays.equals(getUrlDomain(), feature.getUrlDomain()) | ||
| && Arrays.equals(getTimeDomain(), feature.getTimeDomain()) | ||
| && Arrays.equals(getTimeDomain(), feature.getTimeOfDayDomain()); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(super.hashCode(), getName(), getType(), getLabels()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.