use of io.hops.hopsworks.common.featurestore.query.filter.FilterValue in project hopsworks by logicalclocks.
the class TrainingDatasetController method convertToFilter.
private Filter convertToFilter(TrainingDatasetFilterCondition condition, Map<String, Feature> features) {
FilterValue filterValue;
if (condition.getValueFeatureGroupId() == null) {
filterValue = new FilterValue(condition.getValue());
} else {
Feature filterValueFeature = features.get(makeFeatureLookupKey(condition.getValueFeatureGroupId(), condition.getValue()));
filterValue = new FilterValue(condition.getValueFeatureGroupId(), filterValueFeature.getFgAlias(), condition.getValue());
}
return new Filter(features.get(makeFeatureLookupKey(condition.getFeatureGroup().getId(), condition.getFeature())), condition.getCondition(), filterValue);
}
use of io.hops.hopsworks.common.featurestore.query.filter.FilterValue in project hopsworks by logicalclocks.
the class TrainingDatasetControllerTest method testConvertToFilterLogic_multipleFeatureValueCondition.
public void testConvertToFilterLogic_multipleFeatureValueCondition() throws Exception {
// fg.feature > fg.otherFeature and fg.feature > fg1.otherFeature
List<TrainingDatasetFilter> filters = new ArrayList<>();
filters.add(createTrainingDatasetFilter(null, AND, "L"));
filters.add(createTrainingDatasetFilter(createTrainingDatasetFilterCondition("test_f", GREATER_THAN, "test_f1", 0, 0), SINGLE, "L.L"));
filters.add(createTrainingDatasetFilter(createTrainingDatasetFilterCondition("test_f", GREATER_THAN, "test_f2", 0, 1), SINGLE, "L.R"));
Map<String, Feature> featureLookup = Maps.newHashMap();
Feature feature = new Feature("test_f", "fg0");
Feature feature1 = new Feature("test_f1", "fg0");
Feature feature2 = new Feature("test_f2", "fg1");
Featuregroup featuregroup0 = new Featuregroup();
featuregroup0.setId(0);
Featuregroup featuregroup1 = new Featuregroup();
featuregroup1.setId(1);
feature.setFeatureGroup(featuregroup0);
feature1.setFeatureGroup(featuregroup0);
feature2.setFeatureGroup(featuregroup1);
featureLookup.put("0.test_f", feature);
featureLookup.put("0.test_f1", feature1);
featureLookup.put("1.test_f2", feature2);
FilterLogic actual = target.convertToFilterLogic(filters, featureLookup, "L");
Filter left = new Filter(feature, GREATER_THAN, new FilterValue(0, "fg0", "test_f1"));
Filter right = new Filter(feature, GREATER_THAN, new FilterValue(1, "fg1", "test_f2"));
Assert.assertEquals(actual.getType(), AND);
Assert.assertEquals(actual.getLeftFilter(), left);
Assert.assertNull(actual.getLeftLogic());
Assert.assertEquals(actual.getRightFilter(), right);
Assert.assertNull(actual.getRightLogic());
}
use of io.hops.hopsworks.common.featurestore.query.filter.FilterValue in project hopsworks by logicalclocks.
the class TrainingDatasetControllerTest method testConvertToFilterLogic_featureValueCondition.
public void testConvertToFilterLogic_featureValueCondition() throws Exception {
// fg.feature > fg.otherFeature
List<TrainingDatasetFilter> filters = new ArrayList<>();
filters.add(createTrainingDatasetFilter(createTrainingDatasetFilterCondition("test_f", GREATER_THAN, "test_f1", 0, 0), SINGLE, "L"));
Map<String, Feature> featureLookup = Maps.newHashMap();
Feature feature = new Feature("test_f", "fg0");
Feature feature1 = new Feature("test_f1", "fg0");
Featuregroup featuregroup = new Featuregroup();
featuregroup.setId(0);
feature.setFeatureGroup(featuregroup);
feature1.setFeatureGroup(featuregroup);
featureLookup.put("0.test_f", feature);
featureLookup.put("0.test_f1", feature1);
FilterLogic actual = target.convertToFilterLogic(filters, featureLookup, "L");
Filter left = new Filter(feature, GREATER_THAN, new FilterValue(0, "fg0", "test_f1"));
Assert.assertEquals(actual.getType(), SINGLE);
Assert.assertEquals(actual.getLeftFilter(), left);
Assert.assertNull(actual.getLeftLogic());
Assert.assertNull(actual.getRightFilter());
Assert.assertNull(actual.getRightLogic());
}
use of io.hops.hopsworks.common.featurestore.query.filter.FilterValue in project hopsworks by logicalclocks.
the class TrainingDatasetControllerTest method testconvertToFilterEntities_featureComparison.
@Test
public void testconvertToFilterEntities_featureComparison() throws Exception {
// fg.feature > fg.otherFeature and fg.feature > fg1.otherFeature
TrainingDataset trainingDataset = new TrainingDataset();
Feature f1 = new Feature("test_f", "fg0");
FilterLogic head = new FilterLogic();
head.setType(AND);
FilterValue filterValueLeft = new FilterValue(0, "fg0", "test_f1");
Filter left = new Filter(f1, GREATER_THAN, filterValueLeft);
head.setLeftFilter(left);
FilterValue filterValueRight = new FilterValue(1, "fg1", "test_f2");
Filter right = new Filter(f1, GREATER_THAN, filterValueRight);
head.setRightFilter(right);
List<TrainingDatasetFilter> actual = target.convertToFilterEntities(head, trainingDataset, "L");
List<TrainingDatasetFilter> expected = new ArrayList<>();
expected.add(createTrainingDatasetFilter(null, AND, "L"));
expected.add(createTrainingDatasetFilter(createTrainingDatasetFilterCondition("test_f", GREATER_THAN, "test_f1", null, 0), SINGLE, "L.L"));
expected.add(createTrainingDatasetFilter(createTrainingDatasetFilterCondition("test_f", GREATER_THAN, "test_f2", null, 1), SINGLE, "L.R"));
Assert.assertEquals(expected.size(), actual.size());
Assert.assertTrue(expected.containsAll(actual));
Assert.assertTrue(actual.containsAll(expected));
}
Aggregations