use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class FilterOperationsTest method testNested.
@SuppressWarnings("unchecked")
@Test
public void testNested() {
/*
(
field IN ["abc"]
AND
(
(experience IN ["app", "tv"] AND id IN ["1, 2])
OR
mid > 10
)
)
OR
(
demographic_map.age > 65
AND
filter_map.is_fake_event IN [true]
)
*/
LogicalClause clause = clause(OR, clause(AND, clause("field", EQUALS, "abc"), clause(OR, clause(AND, clause("experience", EQUALS, "app", "tv"), clause("id", EQUALS, "1", "2")), clause("mid", GREATER_THAN, "10"))), clause(AND, clause("demographic_map.age", GREATER_THAN, "65"), clause("filter_map.is_fake_event", EQUALS, "true")));
// second clause is true : age > 65 and is_fake_event
BulletRecord recordA = RecordBox.get().addMap("demographic_map", Pair.of("age", "67")).addMap("filter_map", Pair.of("is_fake_event", true)).getRecord();
// age > 65 and is_fake_event == null
BulletRecord recordB = RecordBox.get().addMap("demographic_map", Pair.of("age", "67")).getRecord();
// field != "abc"
BulletRecord recordC = RecordBox.get().add("field", "cba").getRecord();
// field == "abc" but experience != "app" or "tv"
BulletRecord recordD = RecordBox.get().add("field", "abc").getRecord();
// field == "abc", experience == "app" or "tv", mid == null
BulletRecord recordE = RecordBox.get().add("field", "abc").add("experience", "tv").getRecord();
// first clause is false : field == "abc", experience == "app" or "tv", mid < 10 and so is the second
BulletRecord recordF = RecordBox.get().add("field", "abc").add("experience", "tv").add("mid", 9).getRecord();
// first clause is true : field == "abc", experience == "app" or "tv", mid > 10
BulletRecord recordG = RecordBox.get().add("field", "abc").add("experience", "tv").add("mid", 12).getRecord();
Assert.assertTrue(FilterOperations.perform(recordA, clause));
Assert.assertFalse(FilterOperations.perform(recordB, clause));
Assert.assertFalse(FilterOperations.perform(recordC, clause));
Assert.assertFalse(FilterOperations.perform(recordD, clause));
Assert.assertFalse(FilterOperations.perform(recordE, clause));
Assert.assertFalse(FilterOperations.perform(recordF, clause));
Assert.assertTrue(FilterOperations.perform(recordG, clause));
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class FilterOperationsTest method testAnd.
@Test
public void testAnd() {
// id IN [1, 3, 5] AND field NOT IN ["foo"]
LogicalClause clause = clause(AND, clause("id", EQUALS, "1", "3", "5"), clause("field", NOT_EQUALS, "foo"));
BulletRecord recordA = RecordBox.get().add("id", 5).add("field", "foo").getRecord();
BulletRecord recordB = RecordBox.get().add("id", 3).add("field", "bar").getRecord();
BulletRecord recordC = RecordBox.get().add("id", 3).getRecord();
BulletRecord recordD = RecordBox.get().add("field", "baz").getRecord();
BulletRecord recordE = RecordBox.get().getRecord();
Assert.assertFalse(FilterOperations.perform(recordA, clause));
Assert.assertTrue(FilterOperations.perform(recordB, clause));
// field != "foo" is true because field is null
Assert.assertTrue(FilterOperations.perform(recordC, clause));
Assert.assertFalse(FilterOperations.perform(recordD, clause));
Assert.assertFalse(FilterOperations.perform(recordE, clause));
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class ProjectionOperationsTest method testUnsupportedProjection.
@Test
public void testUnsupportedProjection() {
Projection projection = makeProjection(ImmutablePair.of("list_field.1.foo", "bar"), ImmutablePair.of("field", "foo"));
BulletRecord record = RecordBox.get().addList("list_field", emptyMap(), singletonMap("foo", "bar")).add("field", "123").getRecord();
BulletRecord actual = ProjectionOperations.project(record, projection);
BulletRecord expected = RecordBox.get().add("foo", "123").getRecord();
Assert.assertEquals(actual, expected);
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class ProjectionOperationsTest method testMapList.
@Test
public void testMapList() {
Projection projection = makeProjection("list_field", "foo");
BulletRecord record = RecordBox.get().addList("list_field", emptyMap(), singletonMap("foo", "baz")).getRecord();
BulletRecord expected = RecordBox.get().addList("foo", emptyMap(), singletonMap("foo", "baz")).getRecord();
BulletRecord actual = ProjectionOperations.project(record, projection);
Assert.assertEquals(actual, expected);
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class ProjectionOperationsTest method testProjection.
@Test
public void testProjection() {
Projection projection = makeProjection("map_field.foo", "bar");
RecordBox box = RecordBox.get().addMap("map_field", Pair.of("foo", "baz"));
BulletRecord actual = ProjectionOperations.project(box.getRecord(), projection);
BulletRecord expected = RecordBox.get().add("bar", "baz").getRecord();
Assert.assertEquals(actual, expected);
}
Aggregations