Skip to content

Commit 3b6cae4

Browse files
committed
add featurestoreId to featurestore search doc
1 parent 95ac512 commit 3b6cae4

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

hopsworks-api/src/main/java/io/hops/hopsworks/api/opensearch/featurestore/OpenSearchFeaturestoreItemBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import io.hops.hopsworks.common.featurestore.xattr.dto.FeatureStoreItem;
2323
import io.hops.hopsworks.common.featurestore.xattr.dto.FeatureViewXAttrDTO;
2424
import io.hops.hopsworks.common.featurestore.xattr.dto.FeaturegroupXAttr;
25-
import io.hops.hopsworks.common.opensearch.OpenSearchFeaturestoreHit;
2625
import io.hops.hopsworks.common.featurestore.xattr.dto.FeaturestoreXAttrsConstants;
2726
import io.hops.hopsworks.common.featurestore.xattr.dto.TrainingDatasetXAttrDTO;
27+
import io.hops.hopsworks.common.opensearch.OpenSearchFeaturestoreHit;
2828
import io.hops.hopsworks.exceptions.GenericException;
2929
import io.hops.hopsworks.restutils.RESTCodes;
3030

@@ -57,6 +57,7 @@ public OpenSearchFeaturestoreItemDTO.Base fromBaseArtifact(OpenSearchFeaturestor
5757
item.datasetIId = hit.getDatasetIId();
5858
item.parentProjectId = hit.getProjectId();
5959
item.parentProjectName = hit.getProjectName();
60+
item.featurestoreId = hit.getFeaturestoreId();
6061
Object featureStoreXAttr = hit.getXattrs().get(FeaturestoreXAttrsConstants.FEATURESTORE);
6162
if(featureStoreXAttr != null) {
6263
switch(hit.getDocType()) {
@@ -77,7 +78,6 @@ public OpenSearchFeaturestoreItemDTO.Base fromBaseArtifact(OpenSearchFeaturestor
7778

7879
private OpenSearchFeaturestoreItemDTO.Base populateFeatureStoreItem(OpenSearchFeaturestoreItemDTO.Base item,
7980
FeatureStoreItem src){
80-
item.featurestoreId = src.getFeaturestoreId();
8181
item.description = src.getDescription();
8282
item.created = new Date(src.getCreateDate());
8383
item.creator = new UserDTO(userFacade.findByEmail(src.getCreator()));

hopsworks-common/src/main/java/io/hops/hopsworks/common/commands/featurestore/search/SearchDoc.java

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class SearchDoc {
4040
@JsonProperty(FeaturestoreXAttrsConstants.DATASET_INODE_ID)
4141
@JsonInclude(JsonInclude.Include.NON_NULL)
4242
private Long datasetIId;
43+
@JsonProperty(FeaturestoreXAttrsConstants.FEATURESTORE_ID)
44+
@JsonInclude(JsonInclude.Include.NON_NULL)
45+
private Integer featurestoreId;
4346
@JsonProperty(FeaturestoreXAttrsConstants.OPENSEARCH_XATTR)
4447
@JsonInclude(JsonInclude.Include.NON_NULL)
4548
private XAttr xattr;
@@ -92,6 +95,14 @@ public void setDatasetIId(Long datasetIId) {
9295
this.datasetIId = datasetIId;
9396
}
9497

98+
public Integer getFeaturestoreId() {
99+
return featurestoreId;
100+
}
101+
102+
public void setFeaturestoreId(Integer featurestoreId) {
103+
this.featurestoreId = featurestoreId;
104+
}
105+
95106
public XAttr getXattr() {
96107
return xattr;
97108
}

hopsworks-common/src/main/java/io/hops/hopsworks/common/commands/featurestore/search/SearchFSOpenSearchController.java

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.fasterxml.jackson.databind.ObjectMapper;
1919
import io.hops.hopsworks.common.commands.CommandException;
20+
import io.hops.hopsworks.common.featurestore.FeaturestoreController;
2021
import io.hops.hopsworks.common.featurestore.featuregroup.FeaturegroupController;
2122
import io.hops.hopsworks.common.featurestore.metadata.FeatureStoreKeywordControllerIface;
2223
import io.hops.hopsworks.common.featurestore.metadata.FeatureStoreTagControllerIface;
@@ -40,9 +41,11 @@
4041
import io.hops.hopsworks.exceptions.OpenSearchException;
4142
import io.hops.hopsworks.exceptions.ServiceException;
4243
import io.hops.hopsworks.persistence.entity.commands.search.SearchFSCommand;
44+
import io.hops.hopsworks.persistence.entity.featurestore.Featurestore;
4345
import io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView;
4446
import io.hops.hopsworks.persistence.entity.featurestore.metadata.FeatureStoreTag;
4547
import io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.TrainingDatasetFeature;
48+
import io.hops.hopsworks.persistence.entity.project.Project;
4649
import io.hops.hopsworks.restutils.RESTCodes;
4750
import org.opensearch.action.delete.DeleteRequest;
4851
import org.opensearch.action.index.IndexRequest;
@@ -79,6 +82,8 @@ public class SearchFSOpenSearchController {
7982
@EJB
8083
private FeaturegroupController featureGroupCtrl;
8184
@EJB
85+
private FeaturestoreController featurestoreController;
86+
@EJB
8287
private TrainingDatasetController trainingDatasetCtrl;
8388
@EJB
8489
private InodeController inodeCtrl;
@@ -158,6 +163,8 @@ private SearchDoc create(SearchFSCommand c) throws CommandException {
158163
String featureStorePath = Utils.getFeaturestorePath(c.getProject(), settings);
159164
Long featureStoreInode = inodeCtrl.getInodeAtPath(featureStorePath).getId();
160165
doc.setDatasetIId(featureStoreInode);
166+
Featurestore featurestore = getFeatureStoreForProject(c.getProject());
167+
doc.setFeaturestoreId(featurestore.getId());
161168
if(c.getFeatureGroup() != null) {
162169
doc.setDocType(OpenSearchDocType.FEATURE_GROUP);
163170
doc.setName(c.getFeatureGroup().getName());
@@ -176,6 +183,15 @@ private SearchDoc create(SearchFSCommand c) throws CommandException {
176183
return doc;
177184
}
178185

186+
private Featurestore getFeatureStoreForProject(Project project) throws CommandException {
187+
try {
188+
return featurestoreController.getProjectFeaturestore(project);
189+
} catch (FeaturestoreException e) {
190+
throw new CommandException(RESTCodes.CommandErrorCode.INTERNAL_SERVER_ERROR, Level.FINE,
191+
e.getUsrMsg(), e.getDevMsg());
192+
}
193+
}
194+
179195
private SearchDoc updateTags(SearchFSCommand c) throws CommandException {
180196
SearchDoc doc = new SearchDoc();
181197
Map<String, FeatureStoreTag> tags;

hopsworks-common/src/main/java/io/hops/hopsworks/common/opensearch/OpenSearchFeaturestoreHit.java

+11
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class OpenSearchFeaturestoreHit implements Comparator<OpenSearchFeaturest
4646
private Integer projectId;
4747
private String projectName;
4848
private Long datasetIId;
49+
private Integer featurestoreId;
4950
private Map<String, Object> xattrs = new HashMap<>();
5051

5152
public OpenSearchFeaturestoreHit() {
@@ -72,6 +73,8 @@ public static OpenSearchFeaturestoreHit instance(SearchHit hit) throws OpenSearc
7273
feHit.projectName = entry.getValue().toString();
7374
} else if (entry.getKey().equals(FeaturestoreXAttrsConstants.DATASET_INODE_ID)) {
7475
feHit.datasetIId = Long.parseLong(entry.getValue().toString());
76+
} else if (entry.getKey().equals(FeaturestoreXAttrsConstants.FEATURESTORE_ID)) {
77+
feHit.featurestoreId = Integer.parseInt(entry.getValue().toString());
7578
} else if (entry.getKey().equals(FeaturestoreXAttrsConstants.OPENSEARCH_XATTR)) {
7679
feHit.xattrs = (Map)entry.getValue();
7780
}
@@ -158,6 +161,14 @@ public Map<String, Object> getXattrs() {
158161
return xattrs;
159162
}
160163

164+
public Integer getFeaturestoreId() {
165+
return featurestoreId;
166+
}
167+
168+
public void setFeaturestoreId(Integer featurestoreId) {
169+
this.featurestoreId = featurestoreId;
170+
}
171+
161172
public void setXattrs(Map<String, Object> xattrs) {
162173
this.xattrs = xattrs;
163174
}

0 commit comments

Comments
 (0)