From 727dca0530b13fbd4272679b51a53064bca15705 Mon Sep 17 00:00:00 2001 From: kennethmhc Date: Mon, 30 Oct 2023 14:01:07 +0100 Subject: [PATCH] [FSTORE-1037] ArrayIndexOutOfBounds in TrainingDatasetController (#1585) (#1422) * handle indexoutofbound error * reformat --- .../TrainingDatasetController.java | 8 ++++++++ .../TrainingDatasetControllerTest.java | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/hopsworks-common/src/main/java/io/hops/hopsworks/common/featurestore/trainingdatasets/TrainingDatasetController.java b/hopsworks-common/src/main/java/io/hops/hopsworks/common/featurestore/trainingdatasets/TrainingDatasetController.java index 15e85c3cb4..d696919680 100644 --- a/hopsworks-common/src/main/java/io/hops/hopsworks/common/featurestore/trainingdatasets/TrainingDatasetController.java +++ b/hopsworks-common/src/main/java/io/hops/hopsworks/common/featurestore/trainingdatasets/TrainingDatasetController.java @@ -1094,6 +1094,14 @@ public Query getQuery(List joins, List feature store name Map 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 diff --git a/hopsworks-common/src/test/io/hops/hopsworks/common/featurestore/trainingdatasets/TrainingDatasetControllerTest.java b/hopsworks-common/src/test/io/hops/hopsworks/common/featurestore/trainingdatasets/TrainingDatasetControllerTest.java index 5a761dc851..ab1c071b3c 100644 --- a/hopsworks-common/src/test/io/hops/hopsworks/common/featurestore/trainingdatasets/TrainingDatasetControllerTest.java +++ b/hopsworks-common/src/test/io/hops/hopsworks/common/featurestore/trainingdatasets/TrainingDatasetControllerTest.java @@ -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; @@ -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 { @@ -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