Skip to content

Commit

Permalink
[FSTORE-993] HSFS Java should use UTF-8 when creating the StringEntity (
Browse files Browse the repository at this point in the history
  • Loading branch information
SirOibaf authored Aug 31, 2023
1 parent 837ef9c commit 209f822
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.logicalclocks.hsfs.Feature;
import com.logicalclocks.hsfs.FeatureStoreException;

import org.apache.http.entity.StringEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -113,9 +112,8 @@ protected <T extends FeatureGroupBase> T saveExtennalFeatureGroupMetaData(T ext
Class<T> fgClass)
throws FeatureStoreException, IOException {
HopsworksClient hopsworksClient = HopsworksClient.getInstance();
String featureGroupJson = hopsworksClient.getObjectMapper().writeValueAsString(externalFeatureGroup);

return (T) featureGroupApi.saveInternal(externalFeatureGroup, new StringEntity(featureGroupJson),
return (T) featureGroupApi.saveInternal(externalFeatureGroup,
hopsworksClient.buildStringEntity(externalFeatureGroup),
fgClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ public <T> T getInternal(FeatureStoreBase featureStoreBase, String fgName, Integ
public <U extends FeatureGroupBase> FeatureGroupBase save(FeatureGroupBase featureGroup, Class<U> fgType)
throws FeatureStoreException, IOException {
HopsworksClient hopsworksClient = HopsworksClient.getInstance();
String featureGroupJson = hopsworksClient.getObjectMapper().writeValueAsString(featureGroup);

return saveInternal(featureGroup, new StringEntity(featureGroupJson), fgType);
return saveInternal(featureGroup,
hopsworksClient.buildStringEntity(featureGroup), fgType);
}

public <U extends FeatureGroupBase> FeatureGroupBase saveInternal(FeatureGroupBase featureGroupBase,
Expand Down Expand Up @@ -156,13 +155,11 @@ public <T extends FeatureGroupBase> T updateMetadata(FeatureGroupBase featureGro
.set(queryParameter, value)
.expand();

String featureGroupJson = hopsworksClient.getObjectMapper().writeValueAsString(featureGroup);
HttpPut putRequest = new HttpPut(uri);
putRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
putRequest.setEntity(new StringEntity(featureGroupJson));
putRequest.setEntity(hopsworksClient.buildStringEntity(featureGroup));

LOGGER.info("Sending metadata request: " + uri);
LOGGER.info(featureGroupJson);
return hopsworksClient.handleRequest(putRequest, fgType);
}

Expand All @@ -179,10 +176,9 @@ public FeatureGroupCommit featureGroupCommit(FeatureGroupBase featureGroup, Feat
.set("fgId", featureGroup.getId())
.expand();

String featureGroupCommitJson = hopsworksClient.getObjectMapper().writeValueAsString(featureGroupCommit);
HttpPost postRequest = new HttpPost(uri);
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
postRequest.setEntity(new StringEntity(featureGroupCommitJson));
postRequest.setEntity(hopsworksClient.buildStringEntity(featureGroupCommit));

LOGGER.info("Sending metadata request: " + uri);
return hopsworksClient.handleRequest(postRequest, FeatureGroupCommit.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.logicalclocks.hsfs.FeatureStoreException;
import org.apache.http.HttpHeaders;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.ContentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -50,13 +50,11 @@ public <T> FsQueryBase constructQuery(FeatureStoreBase featureStoreBase, QueryBa
.set("projectId", featureStoreBase.getProjectId())
.expand();

String queryJson = hopsworksClient.getObjectMapper().writeValueAsString(queryBase);
LOGGER.info("Sending metadata request: " + uri);
HttpPut putRequest = new HttpPut(uri);
putRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
putRequest.setEntity(new StringEntity(queryJson));
putRequest.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
putRequest.setEntity(hopsworksClient.buildStringEntity(queryBase));

LOGGER.info("Sending metadata request: " + uri);
LOGGER.info("Sending query: " + queryJson);
FsQueryBase fsQueryBase = (FsQueryBase) hopsworksClient.handleRequest(putRequest, fsQueryType);
fsQueryBase.removeNewLines();
List<FeatureGroupAlias> onDemandFeatureGroupAliases = fsQueryBase.getOnDemandFeatureGroups();
Expand Down

0 comments on commit 209f822

Please sign in to comment.