Skip to content

Commit

Permalink
fix: avoid to create temporary records in query engine equal operator
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Aug 23, 2023
1 parent c6a0126 commit 3f9b97d
Showing 1 changed file with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,12 @@ public static boolean equals(Object iLeft, Object iRight) {
return true;
}

if (iLeft instanceof OResult && !(iRight instanceof OResult)) {
iLeft = ((OResult) iLeft).toElement();
}

if (iRight instanceof OResult && !(iLeft instanceof OResult)) {
iRight = ((OResult) iRight).toElement();
}

// RECORD & ORID
/*from this is only legacy query engine */
if (iLeft instanceof ORecord) return comparesValues(iRight, (ORecord) iLeft, true);
else if (iRight instanceof ORecord) return comparesValues(iLeft, (ORecord) iRight, true);
/*till this is only legacy query engine */
else if (iRight instanceof OResult) return comparesValues(iLeft, (OResult) iRight, true);
else if (iRight instanceof OResult) {
return comparesValues(iLeft, (OResult) iRight, true);
}
Expand Down Expand Up @@ -139,21 +134,26 @@ protected static boolean comparesValues(

protected static boolean comparesValues(
final Object iValue, final OResult iRecord, final boolean iConsiderIn) {
// ODOCUMENT AS RESULT OF SUB-QUERY: GET THE FIRST FIELD IF ANY
Set<String> firstFieldName = iRecord.getPropertyNames();
if (firstFieldName.size() == 1) {
Object fieldValue = iRecord.getProperty(firstFieldName.iterator().next());
if (fieldValue != null) {
if (iConsiderIn && OMultiValue.isMultiValue(fieldValue)) {
for (Object o : OMultiValue.getMultiValueIterable(fieldValue, false)) {
if (o != null && o.equals(iValue)) return true;
if (iRecord.getIdentity().isPresent() && iRecord.getIdentity().get().isPersistent()) {
return iRecord.getIdentity().equals(iValue);
} else {
// ODOCUMENT AS RESULT OF SUB-QUERY: GET THE FIRST FIELD IF ANY
Set<String> firstFieldName = iRecord.getPropertyNames();
if (firstFieldName.size() == 1) {
Object fieldValue = iRecord.getProperty(firstFieldName.iterator().next());
if (fieldValue != null) {
if (iConsiderIn && OMultiValue.isMultiValue(fieldValue)) {
for (Object o : OMultiValue.getMultiValueIterable(fieldValue, false)) {
if (o != null && o.equals(iValue)) return true;
}
}
}

return fieldValue.equals(iValue);
return fieldValue.equals(iValue);
}
}

return false;
}
return false;
}

@Override
Expand Down

0 comments on commit 3f9b97d

Please sign in to comment.