Search in sources :

Example 1 with TypedObject

use of com.yahoo.bullet.typesystem.TypedObject in project bullet-core by yahoo.

the class FilterOperationsTest method testNulls.

@Test
public void testNulls() {
    TypedObject object = new TypedObject(Type.NULL, null);
    Assert.assertFalse(comparatorFor(EQUALS).compare(object, make(object, "foo")));
    Assert.assertTrue(comparatorFor(EQUALS).compare(object, make(object, "null")));
    Assert.assertTrue(comparatorFor(EQUALS).compare(object, make(object, "NULL")));
    Assert.assertTrue(comparatorFor(EQUALS).compare(object, make(object, "Null")));
    Assert.assertTrue(comparatorFor(NOT_EQUALS).compare(object, make(object, "foo")));
    Assert.assertFalse(comparatorFor(NOT_EQUALS).compare(object, make(object, "null")));
    Assert.assertFalse(comparatorFor(NOT_EQUALS).compare(object, make(object, "NULL")));
    Assert.assertFalse(comparatorFor(NOT_EQUALS).compare(object, make(object, "Null")));
    Assert.assertFalse(comparatorFor(GREATER_THAN).compare(object, make(object, "foo")));
    Assert.assertFalse(comparatorFor(LESS_THAN).compare(object, make(object, "foo")));
    Assert.assertFalse(comparatorFor(GREATER_EQUALS).compare(object, make(object, "foo")));
    Assert.assertFalse(comparatorFor(LESS_EQUALS).compare(object, make(object, "foo")));
    Assert.assertFalse(FilterOperations.REGEX_LIKE.compare(object, makePattern("foo")));
    Assert.assertFalse(FilterOperations.REGEX_LIKE.compare(object, makePattern("null")));
    Assert.assertFalse(FilterOperations.REGEX_LIKE.compare(object, makePattern("nu.*")));
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) Test(org.testng.annotations.Test)

Example 2 with TypedObject

use of com.yahoo.bullet.typesystem.TypedObject in project bullet-core by yahoo.

the class FilterOperationsTest method testComparatorUnsupportedType.

@Test
public void testComparatorUnsupportedType() {
    TypedObject object = new TypedObject(Type.MAP, singletonMap("foo", "bar"));
    // foo cannot be casted to map, so eq will return false (values will be empty)
    Assert.assertFalse(comparatorFor(EQUALS).compare(object, make(object, "foo")));
    // foo cannot be casted to map, so neq will return true (values will be empty)
    Assert.assertTrue(comparatorFor(NOT_EQUALS).compare(object, make(object, "foo")));
    Assert.assertFalse(comparatorFor(GREATER_THAN).compare(object, make(object, "foo")));
    Assert.assertFalse(comparatorFor(GREATER_EQUALS).compare(object, make(object, "foo")));
    Assert.assertFalse(comparatorFor(LESS_THAN).compare(object, make(object, "foo")));
    Assert.assertFalse(comparatorFor(LESS_EQUALS).compare(object, make(object, "foo")));
    Assert.assertFalse(FilterOperations.REGEX_LIKE.compare(object, makePattern("foo")));
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) Test(org.testng.annotations.Test)

Example 3 with TypedObject

use of com.yahoo.bullet.typesystem.TypedObject in project bullet-core by yahoo.

the class FilterOperationsTest method testComparatorUncastable.

@Test
public void testComparatorUncastable() {
    TypedObject object = new TypedObject(Double.valueOf("1.234"));
    Assert.assertFalse(comparatorFor(EQUALS).compare(object, make(object, "foo")));
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) Test(org.testng.annotations.Test)

Example 4 with TypedObject

use of com.yahoo.bullet.typesystem.TypedObject in project bullet-core by yahoo.

the class FilterOperationsTest method testMixedTypes.

@Test
public void testMixedTypes() {
    TypedObject object = new TypedObject(2.34);
    Assert.assertTrue(comparatorFor(EQUALS).compare(object, make(object, "foo", "2.34")));
    Assert.assertFalse(comparatorFor(EQUALS).compare(object, make(object, "foo", "3.42")));
    Assert.assertTrue(comparatorFor(NOT_EQUALS).compare(object, make(object, "baz", "bar")));
    Assert.assertFalse(comparatorFor(NOT_EQUALS).compare(object, make(object, "baz", "2.34")));
    Assert.assertTrue(comparatorFor(GREATER_THAN).compare(object, make(object, "baz", "2.1")));
    Assert.assertFalse(comparatorFor(GREATER_THAN).compare(object, make(object, "baz", "2.34")));
    Assert.assertFalse(comparatorFor(GREATER_THAN).compare(object, make(object, "baz", "2.4")));
    Assert.assertFalse(comparatorFor(LESS_THAN).compare(object, make(object, "baz", "2.1")));
    Assert.assertFalse(comparatorFor(LESS_THAN).compare(object, make(object, "baz", "2.34")));
    Assert.assertTrue(comparatorFor(LESS_THAN).compare(object, make(object, "baz", "2.4")));
    Assert.assertTrue(comparatorFor(GREATER_EQUALS).compare(object, make(object, "baz", "2.1")));
    Assert.assertTrue(comparatorFor(GREATER_EQUALS).compare(object, make(object, "baz", "2.34")));
    Assert.assertFalse(comparatorFor(GREATER_EQUALS).compare(object, make(object, "baz", "2.4")));
    Assert.assertFalse(comparatorFor(LESS_EQUALS).compare(object, make(object, "baz", "2.1")));
    Assert.assertTrue(comparatorFor(LESS_EQUALS).compare(object, make(object, "baz", "2.34")));
    Assert.assertTrue(comparatorFor(LESS_EQUALS).compare(object, make(object, "baz", "2.4")));
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) Test(org.testng.annotations.Test)

Example 5 with TypedObject

use of com.yahoo.bullet.typesystem.TypedObject in project bullet-core by yahoo.

the class FilterOperationsTest method testInEquality.

@Test
public void testInEquality() {
    TypedObject object = new TypedObject(1L);
    Assert.assertFalse(comparatorFor(NOT_EQUALS).compare(object, make(object, "1", "2")));
    Assert.assertTrue(comparatorFor(NOT_EQUALS).compare(object, make(object, "2", "3")));
    // Will become a string
    object = new TypedObject(singletonList("1"));
    Assert.assertTrue(comparatorFor(NOT_EQUALS).compare(object, make(object, "1", "2")));
    // Can't be casted to a list, so the inequality check will pass
    object = new TypedObject(Type.LIST, singletonList("foo"));
    Assert.assertTrue(comparatorFor(NOT_EQUALS).compare(object, make(object, "foo", "bar")));
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) Test(org.testng.annotations.Test)

Aggregations

TypedObject (com.yahoo.bullet.typesystem.TypedObject)13 Test (org.testng.annotations.Test)11 Utilities.extractTypedObject (com.yahoo.bullet.common.Utilities.extractTypedObject)1 Clause (com.yahoo.bullet.parsing.Clause)1 FilterClause (com.yahoo.bullet.parsing.FilterClause)1 LogicalClause (com.yahoo.bullet.parsing.LogicalClause)1