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")));
}
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()));
}
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();
}
Aggregations