Skip to content

Commit

Permalink
Support for cos/sin/tan/acos/asin/atan/toDegrees/toRadians. Fixes dat…
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjefferson committed Jan 14, 2018
1 parent b9768d5 commit 595c381
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.datanucleus.store.neo4j.query.expression.Neo4jExpression;
import org.datanucleus.store.neo4j.query.expression.Neo4jFieldExpression;
import org.datanucleus.store.neo4j.query.expression.Neo4jLiteral;
import org.datanucleus.store.neo4j.query.expression.Neo4jNumericExpression;
import org.datanucleus.store.neo4j.query.expression.Neo4jStringExpression;
import org.datanucleus.store.query.Query;
import org.datanucleus.store.schema.table.MemberColumnMapping;
Expand All @@ -57,6 +58,8 @@
import org.datanucleus.util.NucleusLogger;
import org.datanucleus.util.StringUtils;

import scala.math.Numeric;

/**
* Mapper to convert a generic query compilation into components for a Neo4j Cypher query.
*/
Expand Down Expand Up @@ -872,6 +875,58 @@ else if (neo4jExprArgs.size() == 1)
}
}
}
else if (Numeric.class.isAssignableFrom(invokedFieldExpr.getMemberMetaData().getType()))
{
// Numeric methods
if ("Math.cos".equals(operation))
{
Neo4jExpression neo4jExpr = new Neo4jNumericExpression("cos(" + invokedFieldExpr.getCypherText() + ")");
stack.push(neo4jExpr);
return neo4jExpr;
}
else if ("Math.sin".equals(operation))
{
Neo4jExpression neo4jExpr = new Neo4jNumericExpression("sin(" + invokedFieldExpr.getCypherText() + ")");
stack.push(neo4jExpr);
return neo4jExpr;
}
else if ("Math.tan".equals(operation))
{
Neo4jExpression neo4jExpr = new Neo4jNumericExpression("tan(" + invokedFieldExpr.getCypherText() + ")");
stack.push(neo4jExpr);
return neo4jExpr;
}
else if ("Math.acos".equals(operation))
{
Neo4jExpression neo4jExpr = new Neo4jNumericExpression("acos(" + invokedFieldExpr.getCypherText() + ")");
stack.push(neo4jExpr);
return neo4jExpr;
}
else if ("Math.asin".equals(operation))
{
Neo4jExpression neo4jExpr = new Neo4jNumericExpression("asin(" + invokedFieldExpr.getCypherText() + ")");
stack.push(neo4jExpr);
return neo4jExpr;
}
else if ("Math.atan".equals(operation))
{
Neo4jExpression neo4jExpr = new Neo4jNumericExpression("atan(" + invokedFieldExpr.getCypherText() + ")");
stack.push(neo4jExpr);
return neo4jExpr;
}
else if ("Math.toDegrees".equals(operation))
{
Neo4jExpression neo4jExpr = new Neo4jNumericExpression("degrees(" + invokedFieldExpr.getCypherText() + ")");
stack.push(neo4jExpr);
return neo4jExpr;
}
else if ("Math.toRadians".equals(operation))
{
Neo4jExpression neo4jExpr = new Neo4jNumericExpression("radians(" + invokedFieldExpr.getCypherText() + ")");
stack.push(neo4jExpr);
return neo4jExpr;
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
*/
public class Neo4jBooleanExpression extends Neo4jExpression
{
public Neo4jBooleanExpression(String cypher)
{
cypherText = cypher;
}

public Neo4jBooleanExpression(Neo4jFieldExpression fieldExpr, Neo4jLiteral lit, Expression.Operator op)
{
String propName = fieldExpr.getFieldName();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**********************************************************************
Copyright (c) 2018 Andy Jefferson and others. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contributors:
...
**********************************************************************/
package org.datanucleus.store.neo4j.query.expression;

/**
* Representation of a Numeric expression in Neo4j queries.
*/
public class Neo4jNumericExpression extends Neo4jExpression
{
public Neo4jNumericExpression(String cypher)
{
cypherText = cypher;
}
}

0 comments on commit 595c381

Please sign in to comment.