Skip to content

Commit

Permalink
[FSTORE-1037] ArrayIndexOutOfBounds in TrainingDatasetController (#15…
Browse files Browse the repository at this point in the history
…85) (#1422)

* handle indexoutofbound error

* reformat
  • Loading branch information
kennethmhc authored Oct 30, 2023
1 parent 9e38378 commit 727dca0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,14 @@ public Query getQuery(List<TrainingDatasetJoin> joins, List<TrainingDatasetFeatu
// Keep a map feature store id -> feature store name
Map<Integer, String> fsLookup = getFsLookupTableJoins(joins);

if (joins.size() == 0) {
throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.FEATURE_NOT_FOUND,
Level.FINE,
"Failed to construct the query because the query contains no features."
+ " It is possible that some feature groups are deleted. Please create a new query."
);
}

Query query = new Query(
fsLookup.get(joins.get(0).getFeatureGroup().getFeaturestore().getId()),
onlineFeaturestoreController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.hops.hopsworks.common.featurestore.query.Query;
import io.hops.hopsworks.common.featurestore.query.join.Join;
import io.hops.hopsworks.common.featurestore.transformationFunction.TransformationFunctionDTO;
import io.hops.hopsworks.exceptions.FeaturestoreException;
import io.hops.hopsworks.persistence.entity.featurestore.featureview.FeatureView;
import io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.SqlCondition;
import io.hops.hopsworks.common.featurestore.query.filter.Filter;
Expand Down Expand Up @@ -52,6 +53,7 @@
import static io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.SqlFilterLogic.AND;
import static io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.SqlFilterLogic.OR;
import static io.hops.hopsworks.persistence.entity.featurestore.trainingdataset.SqlFilterLogic.SINGLE;
import static io.hops.hopsworks.restutils.RESTCodes.FeaturestoreErrorCode.FEATURE_NOT_FOUND;
import static org.mockito.Mockito.doReturn;

public class TrainingDatasetControllerTest {
Expand Down Expand Up @@ -453,6 +455,18 @@ public void testGetQuery_deletedFeatureGroup() throws Exception {
Assert.assertEquals("feature_missing", result.getDeletedFeatureGroups().get(0));
}

@Test
public void testGetQuery_noFeature() {
try {
target.getQuery(new ArrayList<>(), Collections.emptyList(), Collections.emptyList(),
Mockito.mock(Project.class), Mockito.mock(Users.class), false);

Assert.fail("Expected FeaturestoreException, but no exception was thrown.");
} catch (FeaturestoreException e) {
Assert.assertEquals(FEATURE_NOT_FOUND, e.getErrorCode());
}
}

@Test
public void testCollectFeatures() throws Exception {
// prepare TransformationFunctionDTO
Expand Down

0 comments on commit 727dca0

Please sign in to comment.