Search in sources :

Example 1 with LogicalClause

use of com.yahoo.bullet.parsing.LogicalClause in project bullet-core by yahoo.

the class FilterOperationsTest method testLogicalNoOperation.

// ***************************************** Logical Clause *********************************************************
@Test(expectedExceptions = NullPointerException.class)
public void testLogicalNoOperation() {
    LogicalClause clause = new LogicalClause();
    clause.setClauses(asList(makeClause("foo", asList("foo", "bar"), EQUALS), makeClause("bar", asList("foo", "bar"), EQUALS)));
    Assert.assertNull(clause.getOperation());
    FilterOperations.perform(RecordBox.get().getRecord(), clause);
}
Also used : LogicalClause(com.yahoo.bullet.parsing.LogicalClause) Test(org.testng.annotations.Test)

Example 2 with LogicalClause

use of com.yahoo.bullet.parsing.LogicalClause in project bullet-core by yahoo.

the class FilterOperationsTest method testNotMultiple.

@Test
public void testNotMultiple() {
    // NOT(id IN [1, 3, 5], field NOT IN ["foo"])
    // Only the id is negated
    LogicalClause clause = clause(NOT, 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", 1).getRecord();
    BulletRecord recordD = RecordBox.get().add("field", "baz").getRecord();
    BulletRecord recordE = RecordBox.get().getRecord();
    Assert.assertFalse(FilterOperations.perform(recordA, clause));
    Assert.assertFalse(FilterOperations.perform(recordB, clause));
    Assert.assertFalse(FilterOperations.perform(recordC, clause));
    Assert.assertTrue(FilterOperations.perform(recordD, clause));
    Assert.assertTrue(FilterOperations.perform(recordE, clause));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) LogicalClause(com.yahoo.bullet.parsing.LogicalClause) Test(org.testng.annotations.Test)

Example 3 with LogicalClause

use of com.yahoo.bullet.parsing.LogicalClause in project bullet-core by yahoo.

the class FilterOperationsTest method testOr.

@Test
public void testOr() {
    // id IN [1, 3, 5] OR field NOT IN ["foo"]
    LogicalClause clause = clause(OR, 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().add("id", 2).add("field", "foo").getRecord();
    BulletRecord recordF = RecordBox.get().getRecord();
    Assert.assertTrue(FilterOperations.perform(recordA, clause));
    Assert.assertTrue(FilterOperations.perform(recordB, clause));
    Assert.assertTrue(FilterOperations.perform(recordC, clause));
    Assert.assertTrue(FilterOperations.perform(recordD, clause));
    Assert.assertFalse(FilterOperations.perform(recordE, clause));
    // field != "foo" is true because field is null
    Assert.assertTrue(FilterOperations.perform(recordF, clause));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) LogicalClause(com.yahoo.bullet.parsing.LogicalClause) Test(org.testng.annotations.Test)

Example 4 with LogicalClause

use of com.yahoo.bullet.parsing.LogicalClause 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));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) LogicalClause(com.yahoo.bullet.parsing.LogicalClause) Test(org.testng.annotations.Test)

Example 5 with LogicalClause

use of com.yahoo.bullet.parsing.LogicalClause 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));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) LogicalClause(com.yahoo.bullet.parsing.LogicalClause) Test(org.testng.annotations.Test)

Aggregations

LogicalClause (com.yahoo.bullet.parsing.LogicalClause)7 Test (org.testng.annotations.Test)7 BulletRecord (com.yahoo.bullet.record.BulletRecord)5