Skip to content
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

Change register to apply #4

Merged
merged 6 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/src/main/java/feast/core/model/EntityInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,16 @@ public EntityDetail getEntityDetail() {
.setLastUpdated(convertTimestamp(this.getLastUpdated()))
.build();
}

/**
* Checks if this is eq to the other given entity
*
* @param otherEntity
* @return boolean
*/
public boolean eq(EntityInfo otherEntity) {
return otherEntity.getName().equals(this.getName()) &&
otherEntity.getDescription().equals(this.getDescription()) &&
otherEntity.getTags().equals(this.getTags());
}
}
19 changes: 19 additions & 0 deletions core/src/main/java/feast/core/model/FeatureGroupInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,23 @@ public FeatureGroupDetail getFeatureGroupDetail() {
.setLastUpdated(TypeConversion.convertTimestamp(this.getLastUpdated()))
.build();
}

/**
* Checks if this is eq to the other given feature group
*
* @param otherFeatureGroup
* @return boolean
*/
public boolean eq(FeatureGroupInfo otherFeatureGroup) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it possible (and perhaps cleaner) to use the built in .equals() method that all Java objects have?

https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#equals(java.lang.Object)

return otherFeatureGroup.getId() == this.id &&
otherFeatureGroup.getTags() == this.getTags() &&
otherFeatureGroup.getServingStoreOpts() == this.servingStoreOpts &&
getStorageId(otherFeatureGroup.getServingStore()) == getStorageId(this.getServingStore()) &&
otherFeatureGroup.getWarehouseStoreOpts() == this.warehouseStoreOpts &&
getStorageId(otherFeatureGroup.getWarehouseStore()) == getStorageId(this.getWarehouseStore());
}

private String getStorageId(StorageInfo storage) {
return storage == null ? "" : storage.getId();
}
}
30 changes: 30 additions & 0 deletions core/src/main/java/feast/core/model/FeatureInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,34 @@ private String createBigqueryViewLink(StorageInfo warehouseStore) {
"https://bigquery.cloud.google.com/table/%s:%s.%s_%s_view",
projectId, dataset, entity.getName(), granularity.toString().toLowerCase());
}

/**
* Checks if this is eq to the other given feature
*
* @param otherFeature
* @return boolean
*/
public boolean eq(FeatureInfo otherFeature) {
return otherFeature.getId() == this.id &&
otherFeature.getEntity().getName() == this.entity.getName() &&
otherFeature.getOwner() == this.owner &&
otherFeature.getUri() == this.uri &&
otherFeature.getDescription() == this.description &&
otherFeature.getGranularity() == this.granularity &&
otherFeature.getValueType() == this.valueType &&
otherFeature.getTags() == this.tags &&
otherFeature.getOptions() == this.options &&
getFeatureGroupId(otherFeature.getFeatureGroup()) == getFeatureGroupId(this.getFeatureGroup()) &&
otherFeature.getServingStoreOpts() == this.servingStoreOpts &&
getStorageId(otherFeature.getServingStore()) == getStorageId(this.getServingStore()) &&
otherFeature.getWarehouseStoreOpts() == this.warehouseStoreOpts &&
getStorageId(otherFeature.getWarehouseStore()) == getStorageId(this.getWarehouseStore());
}

private String getFeatureGroupId(FeatureGroupInfo featureGroupInfo) {
return featureGroupInfo == null ? "" : featureGroupInfo.getId();
}
private String getStorageId(StorageInfo storage) {
return storage == null ? "" : storage.getId();
}
}
16 changes: 14 additions & 2 deletions core/src/main/java/feast/core/model/StorageInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

package feast.core.model;

import feast.core.UIServiceProto.UIServiceTypes.StorageDetail;
import feast.specs.StorageSpecProto.StorageSpec;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import feast.core.UIServiceProto.UIServiceTypes.StorageDetail;
import feast.specs.StorageSpecProto.StorageSpec;

import javax.persistence.Column;
import javax.persistence.Entity;
Expand Down Expand Up @@ -80,4 +80,16 @@ public StorageDetail getStorageDetail() {
.setLastUpdated(convertTimestamp(this.getLastUpdated()))
.build();
}

/**
* Checks if this is eq to the other given storage
*
* @param otherStorage
* @return boolean
*/
public boolean eq(StorageInfo otherStorage) {
return otherStorage.getId().equals(this.id) &&
otherStorage.getType().equals(this.type) &&
otherStorage.getOptions().equals(this.options);
}
}
10 changes: 10 additions & 0 deletions core/src/test/java/feast/core/model/EntityInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import feast.core.UIServiceProto.UIServiceTypes.EntityDetail;
import feast.specs.EntitySpecProto.EntitySpec;

import java.time.Instant;
import java.util.Date;

import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -66,4 +67,13 @@ public void shouldBuildAndReturnCorrespondingDetail() {
EntityDetail.newBuilder().setSpec(entitySpec).setLastUpdated(ts).build();
assertThat(entityInfo.getEntityDetail(), equalTo(expected));
}

@Test
public void shouldBeEqualToEntityFromSameSpecs() {
EntityInfo entity1 = new EntityInfo(entitySpec);
entity1.setCreated(Date.from(Instant.ofEpochSecond(1)));
EntityInfo entity2 = new EntityInfo(entitySpec);
entity1.setCreated(Date.from(Instant.ofEpochSecond(2)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line correct? Shouldn't it be entity2.setCreated(Date.from(Instant.ofEpochSecond(2)));?

assertThat(entity1.eq(entity2), equalTo(true));
}
}
10 changes: 10 additions & 0 deletions core/src/test/java/feast/core/model/FeatureGroupInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import feast.specs.FeatureSpecProto.DataStore;
import feast.specs.FeatureSpecProto.DataStores;

import java.time.Instant;
import java.util.Date;

import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -84,4 +85,13 @@ public void shouldBuildAndReturnCorrespondingDetail() {
FeatureGroupDetail.newBuilder().setSpec(featureGroupSpec).setLastUpdated(ts).build();
assertThat(featureGroupInfo.getFeatureGroupDetail(), equalTo(expected));
}

@Test
public void shouldBeEqualToFeatureGroupFromSameSpecs() {
FeatureGroupInfo featureGroup1 = new FeatureGroupInfo(featureGroupSpec, servingStorage, warehouseStorage);
featureGroup1.setCreated(Date.from(Instant.ofEpochSecond(1)));
FeatureGroupInfo featureGroup2 = new FeatureGroupInfo(featureGroupSpec, servingStorage, warehouseStorage);
featureGroup2.setCreated(Date.from(Instant.ofEpochSecond(2)));
assertThat(featureGroup1.eq(featureGroup2), equalTo(true));
}
}
10 changes: 10 additions & 0 deletions core/src/test/java/feast/core/model/FeatureInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import feast.specs.FeatureSpecProto.FeatureSpec;
import feast.types.ValueProto.ValueType;

import java.time.Instant;
import java.util.Date;

import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -168,4 +169,13 @@ public void shouldBuildCorrespondingResolvedSpec() {
FeatureInfo resolved = featureInfo.resolve();
assertThat(resolved.getFeatureSpec(), equalTo(expected));
}

@Test
public void shouldBeEqualToFeatureFromSameSpecs() {
FeatureInfo feature1 = new FeatureInfo(featureSpec, entityInfo, servingStorage, warehouseStorage, null);
feature1.setCreated(Date.from(Instant.ofEpochSecond(1)));
FeatureInfo feature2 = new FeatureInfo(featureSpec, entityInfo, servingStorage, warehouseStorage, null);
feature2.setCreated(Date.from(Instant.ofEpochSecond(2)));
assertThat(feature1.eq(feature2), equalTo(true));
}
}
10 changes: 10 additions & 0 deletions core/src/test/java/feast/core/model/StorageInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.Before;
import org.junit.Test;

import java.time.Instant;
import java.util.Date;

import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -65,4 +66,13 @@ public void shouldBuildAndReturnCorrespondingDetail() {
StorageDetail.newBuilder().setSpec(storageSpec).setLastUpdated(ts).build();
assertThat(storageInfo.getStorageDetail(), equalTo(expected));
}

@Test
public void shouldBeEqualToStorageFromSameSpecs() {
StorageInfo storage1 = new StorageInfo(storageSpec);
storage1.setCreated(Date.from(Instant.ofEpochSecond(1)));
StorageInfo storage2 = new StorageInfo(storageSpec);
storage2.setCreated(Date.from(Instant.ofEpochSecond(2)));
assertThat(storage1.eq(storage2), equalTo(true));
}
}