use of com.orientechnologies.orient.core.serialization.serializer.record.binary.OBinaryField in project orientdb by orientechnologies.
the class OQueryOperatorEquality method evaluateRecord.
@Override
public Object evaluateRecord(final OIdentifiable iRecord, ODocument iCurrentResult, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight, OCommandContext iContext) {
if (iLeft instanceof OBinaryField && iRight instanceof OBinaryField)
// BINARY COMPARISON
return evaluate((OBinaryField) iLeft, (OBinaryField) iRight, iContext);
else if (iLeft instanceof OQueryRuntimeValueMulti) {
// LEFT = MULTI
final OQueryRuntimeValueMulti left = (OQueryRuntimeValueMulti) iLeft;
if (left.getValues().length == 0)
return false;
if (left.getDefinition().getRoot().startsWith(OSQLFilterItemFieldAll.NAME)) {
// ALL VALUES
for (int i = 0; i < left.getValues().length; ++i) {
Object v = left.getValues()[i];
Object r = iRight;
final OCollate collate = left.getCollate(i);
if (collate != null) {
v = collate.transform(v);
r = collate.transform(iRight);
}
if (v == null || !evaluateExpression(iRecord, iCondition, v, r, iContext))
return false;
}
return true;
} else {
// ANY VALUES
for (int i = 0; i < left.getValues().length; ++i) {
Object v = left.getValues()[i];
Object r = iRight;
final OCollate collate = left.getCollate(i);
if (collate != null) {
v = collate.transform(v);
r = collate.transform(iRight);
}
if (v != null && evaluateExpression(iRecord, iCondition, v, r, iContext))
return true;
}
return false;
}
} else if (iRight instanceof OQueryRuntimeValueMulti) {
// RIGHT = MULTI
final OQueryRuntimeValueMulti right = (OQueryRuntimeValueMulti) iRight;
if (right.getValues().length == 0)
return false;
if (right.getDefinition().getRoot().startsWith(OSQLFilterItemFieldAll.NAME)) {
// ALL VALUES
for (int i = 0; i < right.getValues().length; ++i) {
Object v = right.getValues()[i];
Object l = iLeft;
final OCollate collate = right.getCollate(i);
if (collate != null) {
v = collate.transform(v);
l = collate.transform(iLeft);
}
if (v == null || !evaluateExpression(iRecord, iCondition, l, v, iContext))
return false;
}
return true;
} else {
// ANY VALUES
for (int i = 0; i < right.getValues().length; ++i) {
Object v = right.getValues()[i];
Object l = iLeft;
final OCollate collate = right.getCollate(i);
if (collate != null) {
v = collate.transform(v);
l = collate.transform(iLeft);
}
if (v != null && evaluateExpression(iRecord, iCondition, l, v, iContext))
return true;
}
return false;
}
} else {
// SINGLE SIMPLE ITEM
return evaluateExpression(iRecord, iCondition, iLeft, iRight, iContext);
}
}
use of com.orientechnologies.orient.core.serialization.serializer.record.binary.OBinaryField in project orientdb by orientechnologies.
the class AbstractComparatorTest method field.
protected OBinaryField field(final OType type, final Object value, OCollate collate) {
BytesContainer bytes = new BytesContainer();
bytes.offset = serializer.serializeValue(bytes, value, type, null);
return new OBinaryField(null, type, bytes, collate);
}
use of com.orientechnologies.orient.core.serialization.serializer.record.binary.OBinaryField in project orientdb by orientechnologies.
the class BinaryComparatorEqualsTest method testBinaryFieldCopy.
@Test
public void testBinaryFieldCopy() {
final OBinaryField f = field(OType.BYTE, 10, new OCaseInsensitiveCollate()).copy();
Assert.assertEquals(f.type, OType.BYTE);
Assert.assertNotNull(f.bytes);
Assert.assertEquals(f.collate.getName(), OCaseInsensitiveCollate.NAME);
}
use of com.orientechnologies.orient.core.serialization.serializer.record.binary.OBinaryField in project orientdb by orientechnologies.
the class OSQLFilterCondition method evaluate.
public Object evaluate(final OIdentifiable iCurrentRecord, final ODocument iCurrentResult, final OCommandContext iContext) {
boolean binaryEvaluation = operator != null && operator.isSupportingBinaryEvaluate() && iCurrentRecord != null && iCurrentRecord.getIdentity().isPersistent();
if (left instanceof OSQLQuery<?>)
// EXECUTE SUB QUERIES ONLY ONCE
left = ((OSQLQuery<?>) left).setContext(iContext).execute();
Object l = evaluate(iCurrentRecord, iCurrentResult, left, iContext, binaryEvaluation);
if (operator == null || operator.canShortCircuit(l))
return l;
if (right instanceof OSQLQuery<?>)
// EXECUTE SUB QUERIES ONLY ONCE
right = ((OSQLQuery<?>) right).setContext(iContext).execute();
Object r = evaluate(iCurrentRecord, iCurrentResult, right, iContext, binaryEvaluation);
if (binaryEvaluation && l instanceof OBinaryField) {
if (r != null && !(r instanceof OBinaryField)) {
final OType type = OType.getTypeByValue(r);
if (ORecordSerializerBinary.INSTANCE.getCurrentSerializer().getComparator().isBinaryComparable(type)) {
final BytesContainer bytes = new BytesContainer();
ORecordSerializerBinary.INSTANCE.getCurrentSerializer().serializeValue(bytes, r, type, null);
bytes.offset = 0;
final OCollate collate = r instanceof OSQLFilterItemField ? ((OSQLFilterItemField) r).getCollate(iCurrentRecord) : null;
r = new OBinaryField(null, type, bytes, collate);
if (!(right instanceof OSQLFilterItem || right instanceof OSQLFilterCondition))
// FIXED VALUE, REPLACE IT
right = r;
}
} else if (r instanceof OBinaryField)
// GET THE COPY OR MT REASONS
r = ((OBinaryField) r).copy();
}
if (binaryEvaluation && r instanceof OBinaryField) {
if (l != null && !(l instanceof OBinaryField)) {
final OType type = OType.getTypeByValue(l);
if (ORecordSerializerBinary.INSTANCE.getCurrentSerializer().getComparator().isBinaryComparable(type)) {
final BytesContainer bytes = new BytesContainer();
ORecordSerializerBinary.INSTANCE.getCurrentSerializer().serializeValue(bytes, l, type, null);
bytes.offset = 0;
final OCollate collate = l instanceof OSQLFilterItemField ? ((OSQLFilterItemField) l).getCollate(iCurrentRecord) : null;
l = new OBinaryField(null, type, bytes, collate);
if (!(left instanceof OSQLFilterItem || left instanceof OSQLFilterCondition))
// FIXED VALUE, REPLACE IT
left = l;
}
} else if (l instanceof OBinaryField)
// GET THE COPY OR MT REASONS
l = ((OBinaryField) l).copy();
}
if (binaryEvaluation)
binaryEvaluation = l instanceof OBinaryField && r instanceof OBinaryField;
if (!binaryEvaluation) {
// no collate for regular expressions, otherwise quotes will result in no match
final OCollate collate = operator instanceof OQueryOperatorMatches ? null : getCollate(iCurrentRecord);
final Object[] convertedValues = checkForConversion(iCurrentRecord, l, r, collate);
if (convertedValues != null) {
l = convertedValues[0];
r = convertedValues[1];
}
}
Object result;
try {
result = operator.evaluateRecord(iCurrentRecord, iCurrentResult, this, l, r, iContext);
} catch (OCommandExecutionException e) {
throw e;
} catch (Exception e) {
if (OLogManager.instance().isDebugEnabled())
OLogManager.instance().debug(this, "Error on evaluating expression (%s)", e, toString());
result = Boolean.FALSE;
}
return result;
}
use of com.orientechnologies.orient.core.serialization.serializer.record.binary.OBinaryField in project orientdb by orientechnologies.
the class OSQLFilterCondition method evaluate.
protected Object evaluate(OIdentifiable iCurrentRecord, final ODocument iCurrentResult, final Object iValue, final OCommandContext iContext, final boolean binaryEvaluation) {
if (iValue == null)
return null;
if (iValue instanceof BytesContainer)
return iValue;
if (iCurrentRecord != null) {
iCurrentRecord = iCurrentRecord.getRecord();
if (iCurrentRecord != null && ((ORecord) iCurrentRecord).getInternalStatus() == ORecordElement.STATUS.NOT_LOADED) {
try {
iCurrentRecord = iCurrentRecord.getRecord().load();
} catch (ORecordNotFoundException e) {
return null;
}
}
}
if (binaryEvaluation && iValue instanceof OSQLFilterItemField) {
final OBinaryField bField = ((OSQLFilterItemField) iValue).getBinaryField(iCurrentRecord);
if (bField != null)
return bField;
}
if (iValue instanceof OSQLFilterItem) {
return ((OSQLFilterItem) iValue).getValue(iCurrentRecord, iCurrentResult, iContext);
}
if (iValue instanceof OSQLFilterCondition) {
// NESTED CONDITION: EVALUATE IT RECURSIVELY
return ((OSQLFilterCondition) iValue).evaluate(iCurrentRecord, iCurrentResult, iContext);
}
if (iValue instanceof OSQLFunctionRuntime) {
// STATELESS FUNCTION: EXECUTE IT
final OSQLFunctionRuntime f = (OSQLFunctionRuntime) iValue;
return f.execute(iCurrentRecord, iCurrentRecord, iCurrentResult, iContext);
}
if (OMultiValue.isMultiValue(iValue)) {
final Iterable<?> multiValue = OMultiValue.getMultiValueIterable(iValue, false);
// MULTI VALUE: RETURN A COPY
final ArrayList<Object> result = new ArrayList<Object>(OMultiValue.getSize(iValue));
for (final Object value : multiValue) {
if (value instanceof OSQLFilterItem) {
result.add(((OSQLFilterItem) value).getValue(iCurrentRecord, iCurrentResult, iContext));
} else {
result.add(value);
}
}
return result;
}
// SIMPLE VALUE: JUST RETURN IT
return iValue;
}
Aggregations