Search in sources :

Example 11 with TypedObject

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

the class FilterOperationsTest method testEquality.

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

Example 12 with TypedObject

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

the class FilterOperations method performRelational.

private static boolean performRelational(BulletRecord record, FilterClause clause) {
    Clause.Operation operator = clause.getOperation();
    if (isEmpty(clause.getValues())) {
        return true;
    }
    TypedObject object = extractTypedObject(clause.getField(), record);
    if (operator == Clause.Operation.REGEX_LIKE) {
        return REGEX_LIKE.compare(object, clause.getPatterns().stream());
    }
    return COMPARATORS.get(operator).compare(object, cast(object, clause.getValues()));
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) Utilities.extractTypedObject(com.yahoo.bullet.common.Utilities.extractTypedObject) FilterClause(com.yahoo.bullet.parsing.FilterClause) LogicalClause(com.yahoo.bullet.parsing.LogicalClause) Clause(com.yahoo.bullet.parsing.Clause)

Example 13 with TypedObject

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

the class Utilities method extractFieldAsNumber.

/**
 * Extracts the field from the given (@link BulletRecord} as a {@link Number}, if possible.
 *
 * @param field The field containing a numeric value to get. It can be "." separated to look inside maps.
 * @param record The record containing the field.
 * @return The value of the field as a {@link Number} or null if it cannot be forced to one.
 */
public static Number extractFieldAsNumber(String field, BulletRecord record) {
    Object value = extractField(field, record);
    // Also checks for null
    if (value instanceof Number) {
        return (Number) value;
    }
    TypedObject asNumber = TypedObject.makeNumber(value);
    if (asNumber.getType() == Type.UNKNOWN) {
        return null;
    }
    return (Number) asNumber.getValue();
}
Also used : TypedObject(com.yahoo.bullet.typesystem.TypedObject) TypedObject(com.yahoo.bullet.typesystem.TypedObject)

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