use of io.hops.hopsworks.common.featurestore.query.filter.FilterLogic in project hopsworks by logicalclocks.
the class TrainingDatasetControllerTest method testconvertToFilterEntities_rightOnlyFiler.
@Test
public void testconvertToFilterEntities_rightOnlyFiler() throws Exception {
// fg.feature > 2
// "fg.feature > 2" stores in the right-hand side
TrainingDataset trainingDataset = new TrainingDataset();
Feature f1 = new Feature("test_f", "fg0");
FilterLogic head = new FilterLogic();
head.setType(SINGLE);
Filter right = new Filter(f1, GREATER_THAN, "2");
head.setRightFilter(right);
List<TrainingDatasetFilter> actual = target.convertToFilterEntities(head, trainingDataset, "L");
List<TrainingDatasetFilter> expected = new ArrayList<>();
expected.add(createTrainingDatasetFilter(createTrainingDatasetFilterCondition("test_f", GREATER_THAN, "2"), SINGLE, "L"));
Assert.assertEquals(expected.size(), actual.size());
Assert.assertTrue(expected.containsAll(actual));
Assert.assertTrue(actual.containsAll(expected));
}
use of io.hops.hopsworks.common.featurestore.query.filter.FilterLogic in project hopsworks by logicalclocks.
the class TrainingDatasetControllerTest method testconvertToFilterEntities_leftFilterRightLogic.
@Test
public void testconvertToFilterEntities_leftFilterRightLogic() throws Exception {
// fg.feature > 1 and (fg.feature > 2 OR fg.feature > 3)
// "fg.feature > 1" stores as filter
TrainingDataset trainingDataset = new TrainingDataset();
Feature f1 = new Feature("test_f", "fg0");
FilterLogic head = new FilterLogic();
head.setType(AND);
Filter left = new Filter(f1, GREATER_THAN, "1");
head.setLeftFilter(left);
FilterLogic right = new FilterLogic();
right.setType(OR);
Filter right_left = new Filter(f1, GREATER_THAN, "2");
Filter right_right = new Filter(f1, GREATER_THAN, "3");
right.setLeftFilter(right_left);
right.setRightFilter(right_right);
head.setRightLogic(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, "1"), SINGLE, "L.L"));
expected.add(createTrainingDatasetFilter(null, OR, "L.R"));
expected.add(createTrainingDatasetFilter(createTrainingDatasetFilterCondition("test_f", GREATER_THAN, "2"), SINGLE, "L.R.L"));
expected.add(createTrainingDatasetFilter(createTrainingDatasetFilterCondition("test_f", GREATER_THAN, "3"), SINGLE, "L.R.R"));
Assert.assertEquals(expected.size(), actual.size());
Assert.assertTrue(expected.containsAll(actual));
Assert.assertTrue(actual.containsAll(expected));
}
use of io.hops.hopsworks.common.featurestore.query.filter.FilterLogic in project hopsworks by logicalclocks.
the class TestPitJoinController method testGenerateSqlWithFilter.
@Test
public void testGenerateSqlWithFilter() {
List<Feature> leftFeatures = new ArrayList<>();
leftFeatures.add(new Feature("pk1", "fg0", fgLeft, true));
leftFeatures.add(new Feature("pk2", "fg0", fgLeft));
leftFeatures.add(new Feature("ts", "fg0", fgLeft));
leftFeatures.add(new Feature("label", "fg0", fgLeft));
List<Feature> rightFeatures = new ArrayList<>();
rightFeatures.add(new Feature("pk1", "fg1", fgRight));
rightFeatures.add(new Feature("pk2", "fg1", fgRight));
rightFeatures.add(new Feature("ts", "fg1", fgRight));
rightFeatures.add(new Feature("ft1", "fg1", fgRight));
List<Feature> rightFeatures1 = new ArrayList<>();
rightFeatures1.add(new Feature("pk1", "fg2", fgRight1));
rightFeatures1.add(new Feature("ts", "fg2", fgRight1));
rightFeatures1.add(new Feature("ft1", "fg2", fgRight1));
List<Feature> leftOn = Arrays.asList(new Feature("pk1", "fg0", fgLeft), new Feature("pk2", "fg0", fgLeft));
List<Feature> rightOn = Arrays.asList(new Feature("pk1", "fg1", fgRight), new Feature("pk2", "fg1", fgRight));
// join on different pks
List<Feature> leftOn1 = Collections.singletonList(new Feature("pk1", "fg0", fgLeft));
List<Feature> rightOn1 = Collections.singletonList(new Feature("pk1", "fg2", fgRight1));
List<SqlCondition> joinOperator = Arrays.asList(SqlCondition.EQUALS, SqlCondition.EQUALS);
List<SqlCondition> joinOperator1 = Collections.singletonList(SqlCondition.EQUALS);
FilterLogic filter = new FilterLogic(new Filter(Arrays.asList(new Feature("label", "fg0", "int", null, null)), SqlCondition.EQUALS, "1"));
Query query = new Query("fs", "project", fgLeft, "fg0", leftFeatures, leftFeatures, false, filter);
Query right = new Query("fs", "project", fgRight, "fg1", rightFeatures, rightFeatures, false, null);
Query right1 = new Query("fs", "project", fgRight, "fg2", rightFeatures1, rightFeatures1, false, null);
Join join = new Join(query, right, leftOn, rightOn, JoinType.INNER, null, joinOperator);
Join join1 = new Join(query, right1, leftOn1, rightOn1, JoinType.INNER, "R_", joinOperator1);
query.setJoins(Arrays.asList(join, join1));
String result = pitJoinController.generateSQL(query, false).toSqlString(new SparkSqlDialect(SqlDialect.EMPTY_CONTEXT)).getSql();
String expected = "WITH right_fg0 AS (SELECT *\n" + "FROM (SELECT `fg0`.`pk1`, `fg0`.`pk2`, `fg0`.`ts`, `fg0`.`label`, `fg0`.`pk1` `join_pk_pk1`, `fg0`.`ts` `join_evt_ts`, `fg1`.`pk1`, `fg1`.`pk2`, `fg1`.`ts`, `fg1`.`ft1`, " + "RANK() OVER (PARTITION BY `fg0`.`pk1`, `fg0`.`pk2`, `fg0`.`ts` ORDER BY `fg1`.`ts` DESC) pit_rank_hopsworks\n" + "FROM `fs`.`fg0_1` `fg0`\n" + "INNER JOIN `fs`.`fg1_1` `fg1` ON `fg0`.`pk1` = `fg1`.`pk1` AND `fg0`.`pk2` = `fg1`.`pk2` AND `fg0`.`ts` >= `fg1`.`ts`\n" + "WHERE `fg0`.`label` = 1) NA\n" + "WHERE `pit_rank_hopsworks` = 1), " + "right_fg1 AS (SELECT *\n" + "FROM (SELECT `fg0`.`pk1`, `fg0`.`pk2`, `fg0`.`ts`, `fg0`.`label`, `fg0`.`pk1` `join_pk_pk1`, `fg0`.`ts` `join_evt_ts`, `fg2`.`pk1` `R_pk1`, `fg2`.`ts` `R_ts`, `fg2`.`ft1` `R_ft1`, " + "RANK() OVER (PARTITION BY `fg0`.`pk1`, `fg0`.`ts` ORDER BY `fg2`.`ts` DESC) pit_rank_hopsworks\n" + "FROM `fs`.`fg0_1` `fg0`\n" + "INNER JOIN `fs`.`fg1_1` `fg2` ON `fg0`.`pk1` = `fg2`.`pk1` AND `fg0`.`ts` >= `fg2`.`ts`\n" + "WHERE `fg0`.`label` = 1) NA\n" + "WHERE `pit_rank_hopsworks` = 1) (" + "SELECT `right_fg0`.`pk1`, `right_fg0`.`pk2`, `right_fg0`.`ts`, `right_fg0`.`label`, `right_fg0`.`pk1`, `right_fg0`.`pk2`, `right_fg0`.`ts`, `right_fg0`.`ft1`, `right_fg1`.`R_pk1`, `right_fg1`.`R_ts`, `right_fg1`.`R_ft1`\n" + "FROM right_fg0\n" + "INNER JOIN right_fg1 ON `right_fg0`.`join_pk_pk1` = `right_fg1`.`join_pk_pk1` AND `right_fg0`.`join_evt_ts` = `right_fg1`.`join_evt_ts`)";
Assert.assertEquals(expected, result);
}
use of io.hops.hopsworks.common.featurestore.query.filter.FilterLogic in project hopsworks by logicalclocks.
the class TestConstructorController method testThreeWayJoinSQLNodeWithFilters.
@Test
public void testThreeWayJoinSQLNodeWithFilters() throws Exception {
List<Feature> availableFirst = new ArrayList<>();
availableFirst.add(new Feature("ft1", "fg0", "Float", null, null));
List<Feature> availableSecond = new ArrayList<>();
availableSecond.add(new Feature("ft2", "fg1", "Float", null, null));
List<Feature> availableThird = new ArrayList<>();
availableThird.add(new Feature("ft1", "fg2", "Float", null, null));
availableThird.add(new Feature("ft2", "fg2", "Float", null, null));
Query leftQuery = new Query("fs1", "project_fs1", fg1, "fg0", availableFirst, availableFirst);
Query secondQuery = new Query("fs1", "project_fs1", fg2, "fg1", availableSecond, availableSecond);
Query thirdQuery = new Query("fs1", "project_fs1", fg3, "fg2", availableThird, availableThird);
FilterLogic firstFilter = new FilterLogic(SqlFilterLogic.AND);
firstFilter.setLeftFilter(new Filter(Arrays.asList(availableFirst.get(0)), SqlCondition.EQUALS, "10"));
FilterLogic rightLogic = new FilterLogic(SqlFilterLogic.OR);
rightLogic.setLeftFilter(new Filter(Arrays.asList(availableThird.get(0)), SqlCondition.EQUALS, "10"));
rightLogic.setRightFilter(new Filter(Arrays.asList(availableThird.get(1)), SqlCondition.EQUALS, "10"));
firstFilter.setRightLogic(rightLogic);
leftQuery.setFilter(firstFilter);
FilterLogic secondFilter = new FilterLogic(SqlFilterLogic.SINGLE);
secondFilter.setLeftFilter(new Filter(Arrays.asList(availableSecond.get(0)), SqlCondition.NOT_EQUALS, "10"));
secondQuery.setFilter(secondFilter);
Join join = new Join(leftQuery, secondQuery, availableFirst, availableSecond, JoinType.INNER, null, singleEqualsJoinOperator);
Join secondJoin = new Join(leftQuery, thirdQuery, availableFirst, availableFirst, JoinType.INNER, null, singleEqualsJoinOperator);
leftQuery.setJoins(Arrays.asList(join, secondJoin));
String query = target.generateSQL(leftQuery, false).toSqlString(new SparkSqlDialect(SqlDialect.EMPTY_CONTEXT)).getSql().replace("\n", " ");
Assert.assertEquals("SELECT `fg0`.`ft1`, `fg1`.`ft2`, `fg2`.`ft1`, `fg2`.`ft2` " + "FROM `fs1`.`fg1_1` `fg0` " + "INNER JOIN `fs1`.`fg2_1` `fg1` ON `fg0`.`ft1` = `fg1`.`ft2` " + "INNER JOIN `fs1`.`fg3_1` `fg2` ON `fg0`.`ft1` = `fg2`.`ft1` " + "WHERE `fg0`.`ft1` = 10 AND (`fg2`.`ft1` = 10 OR `fg2`.`ft2` = 10) AND `fg1`.`ft2` <> 10", query);
}
use of io.hops.hopsworks.common.featurestore.query.filter.FilterLogic 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());
}
Aggregations