Skip to content

Commit

Permalink
Fix usage of any() function in new SQL executor
Browse files Browse the repository at this point in the history
Resolves: #8302
  • Loading branch information
luigidellaquila committed Jun 4, 2018
1 parent 54b3d63 commit 9aca423
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ protected boolean supportsBasicCalculation() {
return true;
}

@Override
public boolean isFunctionAny() {
if (this.identifier == null) {
return false;
}
return identifier.isFunctionAny();
}

@Override
public boolean isIndexedFunctionCall() {
if (this.identifier == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public Object execute(OResult iCurrentRecord, OCommandContext ctx) {
return null;
}

public boolean isFunctionAny() {
if (levelZero != null) {
return levelZero.isFunctionAny();
}
return false;
}


public boolean isIndexedFunctionCall() {
if (levelZero != null) {
return levelZero.isIndexedFunctionCall();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public boolean evaluate(OIdentifiable currentRecord, OCommandContext ctx) {

@Override
public boolean evaluate(OResult currentRecord, OCommandContext ctx) {
if (left.isFunctionAny()) {
return evaluateAny(currentRecord, ctx);
}
Object leftVal = left.execute(currentRecord, ctx);
Object rightVal = right.execute(currentRecord, ctx);
OCollate collate = left.getCollate(currentRecord, ctx);
Expand All @@ -54,6 +57,20 @@ public boolean evaluate(OResult currentRecord, OCommandContext ctx) {
return operator.execute(leftVal, rightVal);
}

private boolean evaluateAny(OResult currentRecord, OCommandContext ctx) {
for (String s : currentRecord.getPropertyNames()) {
Object leftVal = currentRecord.getProperty(s);
Object rightVal = right.execute(currentRecord, ctx);

//TODO collate

if (operator.execute(leftVal, rightVal)) {
return true;
}
}
return false;
}

public void toString(Map<Object, Object> params, StringBuilder builder) {
left.toString(params, builder);
builder.append(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,17 @@ public boolean isCacheable() {
}

public boolean isIndexChain(OCommandContext ctx, OClass clazz) {
if(mathExpression!=null){
if (mathExpression != null) {
return mathExpression.isIndexChain(ctx, clazz);
}
return false;
}

public boolean isFunctionAny() {
if (mathExpression != null) {
return mathExpression.isFunctionAny();
}
return false;
}
}
/* JavaCC - OriginalChecksum=9c860224b121acdc89522ae97010be01 (do not edit this line) */
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public boolean isIndexedFunctionCall() {
return false;
}

public boolean isFunctionAny() {
if (functionCall != null) {
return functionCall.getName().getStringValue().equalsIgnoreCase("any") && functionCall.params.size() == 0;
}
return false;
}

public long estimateIndexedFunction(OFromClause target, OCommandContext context, OBinaryCompareOperator operator, Object right) {
if (functionCall != null) {
return functionCall.estimateIndexedFunction(target, context, operator, right);
Expand All @@ -98,7 +105,9 @@ public Iterable<OIdentifiable> executeIndexedFunction(OFromClause target, OComma
* @param context the execution context
* @param operator
* @param right
* @return true if current expression is an indexed funciton AND that function can also be executed without using the index, false otherwise
*
* @return true if current expression is an indexed funciton AND that function can also be executed without using the index, false
* otherwise
*/
public boolean canExecuteIndexedFunctionWithoutIndex(OFromClause target, OCommandContext context, OBinaryCompareOperator operator,
Object right) {
Expand All @@ -110,30 +119,34 @@ public boolean canExecuteIndexedFunctionWithoutIndex(OFromClause target, OComman

/**
* tests if current expression is an indexed function AND that function can be used on this target
* @param target the query target
* @param context the execution context
*
* @param target the query target
* @param context the execution context
* @param operator
* @param right
*
* @return true if current expression involves an indexed function AND that function can be used on this target, false otherwise
*/
public boolean allowsIndexedFunctionExecutionOnTarget(OFromClause target, OCommandContext context, OBinaryCompareOperator operator,
Object right){
public boolean allowsIndexedFunctionExecutionOnTarget(OFromClause target, OCommandContext context,
OBinaryCompareOperator operator, Object right) {
if (this.functionCall == null) {
return false;
}
return functionCall.allowsIndexedFunctionExecutionOnTarget(target, context, operator, right);
}

/**
* tests if current expression is an indexed function AND the function has also to be executed after the index search.
* In some cases, the index search is accurate, so this condition can be excluded from further evaluation. In other cases
* the result from the index is a superset of the expected result, so the function has to be executed anyway for further filtering
* @param target the query target
* tests if current expression is an indexed function AND the function has also to be executed after the index search. In some
* cases, the index search is accurate, so this condition can be excluded from further evaluation. In other cases the result from
* the index is a superset of the expected result, so the function has to be executed anyway for further filtering
*
* @param target the query target
* @param context the execution context
*
* @return true if current expression is an indexed function AND the function has also to be executed after the index search.
*/
public boolean executeIndexedFunctionAfterIndexSearch(OFromClause target, OCommandContext context, OBinaryCompareOperator operator,
Object right){
public boolean executeIndexedFunctionAfterIndexSearch(OFromClause target, OCommandContext context,
OBinaryCompareOperator operator, Object right) {
if (this.functionCall == null) {
return false;
}
Expand Down Expand Up @@ -175,7 +188,7 @@ public boolean isAggregate() {
}

public boolean isCount() {
return functionCall!=null && functionCall.name.getStringValue().equalsIgnoreCase("count");
return functionCall != null && functionCall.name.getStringValue().equalsIgnoreCase("count");
}

public boolean isEarlyCalculated() {
Expand Down Expand Up @@ -225,13 +238,14 @@ public AggregationContext getAggregationContext(OCommandContext ctx) {

public OLevelZeroIdentifier copy() {
OLevelZeroIdentifier result = new OLevelZeroIdentifier(-1);
result.functionCall= functionCall==null?null:functionCall.copy();
result.functionCall = functionCall == null ? null : functionCall.copy();
result.self = self;
result.collection = collection==null?null:collection.copy();
result.collection = collection == null ? null : collection.copy();
return result;
}

@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
Expand All @@ -249,7 +263,8 @@ public OLevelZeroIdentifier copy() {
return true;
}

@Override public int hashCode() {
@Override
public int hashCode() {
int result = functionCall != null ? functionCall.hashCode() : 0;
result = 31 * result + (self != null ? self.hashCode() : 0);
result = 31 * result + (collection != null ? collection.hashCode() : 0);
Expand All @@ -261,10 +276,10 @@ public void setCollection(OCollection collection) {
}

public boolean refersToParent() {
if(functionCall!=null && functionCall.refersToParent()){
if (functionCall != null && functionCall.refersToParent()) {
return true;
}
if(collection!=null && collection.refersToParent()){
if (collection != null && collection.refersToParent()) {
return true;
}
return false;
Expand Down Expand Up @@ -319,10 +334,10 @@ public void extractSubQueries(SubQueryCollector collector) {
}

public boolean isCacheable() {
if(functionCall!=null){
if (functionCall != null) {
return functionCall.isCacheable();
}
if(collection!=null){
if (collection != null) {
return collection.isCacheable();
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,13 @@ public boolean executeIndexedFunctionAfterIndexSearch(OFromClause target, OComma
return this.childExpressions.get(0).executeIndexedFunctionAfterIndexSearch(target, context, operator, right);
}

public boolean isFunctionAny() {
if (this.childExpressions.size() != 1) {
return false;
}
return this.childExpressions.get(0).isFunctionAny();
}

public boolean isBaseIdentifier() {
if (childExpressions.size() == 1) {
return childExpressions.get(0).isBaseIdentifier();
Expand Down

0 comments on commit 9aca423

Please sign in to comment.