Search in sources :

Example 66 with BulletRecord

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

Example 67 with BulletRecord

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

Example 68 with BulletRecord

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

Example 69 with BulletRecord

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

Example 70 with BulletRecord

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);
}
Also used : RecordBox(com.yahoo.bullet.result.RecordBox) BulletRecord(com.yahoo.bullet.record.BulletRecord) ProjectionUtils.makeProjection(com.yahoo.bullet.parsing.ProjectionUtils.makeProjection) Projection(com.yahoo.bullet.parsing.Projection) Test(org.testng.annotations.Test)

Aggregations

BulletRecord (com.yahoo.bullet.record.BulletRecord)210 Test (org.testng.annotations.Test)196 Tuple (org.apache.storm.tuple.Tuple)55 CountDistinctTest (com.yahoo.bullet.aggregations.CountDistinctTest)53 DistributionTest (com.yahoo.bullet.aggregations.DistributionTest)53 TopKTest (com.yahoo.bullet.aggregations.TopKTest)53 Clip (com.yahoo.bullet.result.Clip)53 HashMap (java.util.HashMap)53 Map (java.util.Map)53 BulletConfig (com.yahoo.bullet.common.BulletConfig)46 List (java.util.List)45 IntStream (java.util.stream.IntStream)45 Assert (org.testng.Assert)45 RecordBox (com.yahoo.bullet.result.RecordBox)43 Arrays.asList (java.util.Arrays.asList)40 Pair (org.apache.commons.lang3.tuple.Pair)40 AggregationUtils.makeAttributes (com.yahoo.bullet.parsing.AggregationUtils.makeAttributes)34 BulletError (com.yahoo.bullet.common.BulletError)33 Aggregation (com.yahoo.bullet.parsing.Aggregation)33 Concept (com.yahoo.bullet.result.Meta.Concept)33