Skip to content

Commit

Permalink
added check in the query engine for binary comparation support by ser…
Browse files Browse the repository at this point in the history
…ializer
  • Loading branch information
tglman committed Oct 23, 2015
1 parent 4efb760 commit 43e294d
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 30 deletions.
Expand Up @@ -34,4 +34,6 @@ public interface ORecordSerializer {
int getMinSupportedVersion();

String[] getFieldNames(byte[] iSource);

boolean getSupportBinaryEvaluate();
}
Expand Up @@ -74,4 +74,8 @@ public byte[] toStream(final ORecord iSource, boolean iOnlyDelta) {
throw OException.wrapException(new OSerializationException(message), e);
}
}

public boolean getSupportBinaryEvaluate() {
return false;
}
}
Expand Up @@ -137,4 +137,8 @@ public byte[] writeClassOnly(ORecord iSource) {
return container.fitBytes();
}

@Override
public boolean getSupportBinaryEvaluate() {
return true;
}
}
Expand Up @@ -130,4 +130,8 @@ public byte[] writeClassOnly(ORecord iSource) {
return container.fitBytes();
}

public boolean getSupportBinaryEvaluate() {
return false;
}

}
Expand Up @@ -682,8 +682,7 @@ public byte[] toStream(final ORecord iRecord, boolean iOnlyDelta) {
final long timer = PROFILER.startChrono();

try {
return OBinaryProtocol.string2bytes(toString(iRecord, new StringBuilder(2048), null, null,
OSerializationSetThreadLocal.INSTANCE.get(), iOnlyDelta, true).toString());
return OBinaryProtocol.string2bytes(toString(iRecord, new StringBuilder(2048), null, null, OSerializationSetThreadLocal.INSTANCE.get(), iOnlyDelta, true).toString());
} finally {

PROFILER.stopChrono(PROFILER.getProcessMetric("serializer.record.string.toStream"), "Serialize record to stream", timer);
Expand All @@ -693,4 +692,8 @@ public byte[] toStream(final ORecord iRecord, boolean iOnlyDelta) {
protected abstract StringBuilder toString(final ORecord iRecord, final StringBuilder iOutput, final String iFormat,
final OUserObject2RecordHandler iObjHandler, final Map<ODocument, Boolean> iMarshalledRecords, boolean iOnlyDelta,
boolean autoDetectCollectionType);

public boolean getSupportBinaryEvaluate() {
return false;
}
}
Expand Up @@ -21,6 +21,8 @@

import com.orientechnologies.common.collection.OMultiValue;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OCompositeIndexDefinition;
Expand All @@ -46,18 +48,22 @@

/**
* EQUALS operator.
*
*
* @author Luca Garulli
*
*/
public class OQueryOperatorEquals extends OQueryOperatorEqualityNotNulls {

private boolean binaryEvaluate = false;

public OQueryOperatorEquals() {
super("=", 5, false);
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null)
binaryEvaluate = db.getSerializer().getSupportBinaryEvaluate();
}

public static boolean equals(final Object iLeft, final Object iRight, OType type) {
if(type==null){
if (type == null) {
return equals(iLeft, iRight);
}
Object left = OType.convert(iLeft, type.getDefaultJavaType());
Expand Down Expand Up @@ -192,17 +198,15 @@ public ORID getBeginRidRange(final Object iLeft, final Object iRight) {
if (iRight instanceof ORID)
return (ORID) iRight;
else {
if (iRight instanceof OSQLFilterItemParameter
&& ((OSQLFilterItemParameter) iRight).getValue(null, null, null) instanceof ORID)
if (iRight instanceof OSQLFilterItemParameter && ((OSQLFilterItemParameter) iRight).getValue(null, null, null) instanceof ORID)
return (ORID) ((OSQLFilterItemParameter) iRight).getValue(null, null, null);
}

if (iRight instanceof OSQLFilterItemField && ODocumentHelper.ATTRIBUTE_RID.equals(((OSQLFilterItemField) iRight).getRoot()))
if (iLeft instanceof ORID)
return (ORID) iLeft;
else {
if (iLeft instanceof OSQLFilterItemParameter
&& ((OSQLFilterItemParameter) iLeft).getValue(null, null, null) instanceof ORID)
if (iLeft instanceof OSQLFilterItemParameter && ((OSQLFilterItemParameter) iLeft).getValue(null, null, null) instanceof ORID)
return (ORID) ((OSQLFilterItemParameter) iLeft).getValue(null, null, null);
}

Expand All @@ -215,18 +219,16 @@ public ORID getEndRidRange(final Object iLeft, final Object iRight) {
}

@Override
protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft,
final Object iRight, OCommandContext iContext) {
protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight, OCommandContext iContext) {
return equals(iLeft, iRight);
}

public boolean evaluate(final OBinaryField iFirstField, final OBinaryField iSecondField, OCommandContext iContext) {
return ORecordSerializerBinary.INSTANCE.getCurrentSerializer().getComparator()
.isEqual(iFirstField, iSecondField);
return ORecordSerializerBinary.INSTANCE.getCurrentSerializer().getComparator().isEqual(iFirstField, iSecondField);
}

@Override
public boolean isSupportingBinaryEvaluate(){
return true;
public boolean isSupportingBinaryEvaluate() {
return binaryEvaluate;
}
}
Expand Up @@ -20,6 +20,8 @@
package com.orientechnologies.orient.core.sql.operator;

import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
Expand Down Expand Up @@ -47,8 +49,13 @@
*/
public class OQueryOperatorMajor extends OQueryOperatorEqualityNotNulls {

private boolean binaryEvaluate=false;

public OQueryOperatorMajor() {
super(">", 5, false);
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null)
binaryEvaluate = db.getSerializer().getSupportBinaryEvaluate();
}

@Override
Expand Down Expand Up @@ -138,6 +145,6 @@ public boolean evaluate(final OBinaryField iFirstField, final OBinaryField iSeco

@Override
public boolean isSupportingBinaryEvaluate() {
return true;
return binaryEvaluate;
}
}
Expand Up @@ -20,6 +20,8 @@
package com.orientechnologies.orient.core.sql.operator;

import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OCompositeIndexDefinition;
Expand All @@ -46,8 +48,13 @@
*/
public class OQueryOperatorMajorEquals extends OQueryOperatorEqualityNotNulls {

private boolean binaryEvaluate=false;

public OQueryOperatorMajorEquals() {
super(">=", 5, false);
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null)
binaryEvaluate = db.getSerializer().getSupportBinaryEvaluate();
}

@Override
Expand Down Expand Up @@ -138,6 +145,6 @@ public boolean evaluate(final OBinaryField iFirstField, final OBinaryField iSeco

@Override
public boolean isSupportingBinaryEvaluate() {
return true;
return binaryEvaluate;
}
}
Expand Up @@ -20,6 +20,8 @@
package com.orientechnologies.orient.core.sql.operator;

import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OCompositeIndexDefinition;
Expand All @@ -46,8 +48,13 @@
*/
public class OQueryOperatorMinor extends OQueryOperatorEqualityNotNulls {

private boolean binaryEvaluate=false;

public OQueryOperatorMinor() {
super("<", 5, false);
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null)
binaryEvaluate = db.getSerializer().getSupportBinaryEvaluate();
}

@Override
Expand Down Expand Up @@ -138,6 +145,6 @@ public boolean evaluate(final OBinaryField iFirstField, final OBinaryField iSeco

@Override
public boolean isSupportingBinaryEvaluate() {
return true;
return binaryEvaluate;
}
}
Expand Up @@ -20,6 +20,8 @@
package com.orientechnologies.orient.core.sql.operator;

import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OCompositeIndexDefinition;
Expand All @@ -40,20 +42,23 @@

/**
* MINOR EQUALS operator.
*
*
* @author Luca Garulli
*
*/
public class OQueryOperatorMinorEquals extends OQueryOperatorEqualityNotNulls {

private boolean binaryEvaluate = true;

public OQueryOperatorMinorEquals() {
super("<=", 5, false);
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null)
binaryEvaluate = db.getSerializer().getSupportBinaryEvaluate();
}

@Override
@SuppressWarnings("unchecked")
protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft,
final Object iRight, OCommandContext iContext) {
protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight, OCommandContext iContext) {
final Object right = OType.convert(iRight, iLeft.getClass());
if (right == null)
return false;
Expand Down Expand Up @@ -123,8 +128,7 @@ public ORID getEndRidRange(final Object iLeft, final Object iRight) {
if (iRight instanceof ORID)
return (ORID) iRight;
else {
if (iRight instanceof OSQLFilterItemParameter
&& ((OSQLFilterItemParameter) iRight).getValue(null, null, null) instanceof ORID)
if (iRight instanceof OSQLFilterItemParameter && ((OSQLFilterItemParameter) iRight).getValue(null, null, null) instanceof ORID)
return (ORID) ((OSQLFilterItemParameter) iRight).getValue(null, null, null);
}

Expand All @@ -138,6 +142,6 @@ public boolean evaluate(final OBinaryField iFirstField, final OBinaryField iSeco

@Override
public boolean isSupportingBinaryEvaluate() {
return true;
return binaryEvaluate;
}
}
Expand Up @@ -20,6 +20,8 @@
package com.orientechnologies.orient.core.sql.operator;

import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.serialization.serializer.record.binary.OBinaryField;
Expand All @@ -28,25 +30,28 @@

/**
* NOT EQUALS operator.
*
*
* @author Luca Garulli
*
*/
public class OQueryOperatorNotEquals extends OQueryOperatorEqualityNotNulls {

private boolean binaryEvaluate = false;

public OQueryOperatorNotEquals() {
super("<>", 5, false);
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null)
binaryEvaluate = db.getSerializer().getSupportBinaryEvaluate();
}

@Override
protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft,
final Object iRight, OCommandContext iContext) {
protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight, OCommandContext iContext) {
return !OQueryOperatorEquals.equals(iLeft, iRight);
}

@Override
public boolean isSupportingBinaryEvaluate() {
return true;
return binaryEvaluate;
}

@Override
Expand Down

0 comments on commit 43e294d

Please sign in to comment.