Permalink
Browse files

Added changes to allow clojure in cypher

  • Loading branch information...
ducky427 committed Oct 3, 2014
1 parent 33368fe commit 359294e8711550cf47cd553e09cb638a637cca3c
@@ -0,0 +1,8 @@

.PHONY: build

all: build

build:
mvn clean install -DminimalBuild -Dlicensing.skip=true
cp target/neo4j-cypher-compiler-2.1-2.1.6-SNAPSHOT.jar /home/developer/Downloads/neo4j-community-2.1.5/lib/neo4j-cypher-compiler-2.1-2.1.5.jar
@@ -118,7 +118,11 @@
<artifactId>opencsv</artifactId>
<version>2.3</version>
</dependency>

<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.6.0</version>
</dependency>
</dependencies>

</project>
@@ -92,7 +92,8 @@ object Function {
functions.ToUpper,
functions.Trim,
functions.Type,
functions.Upper
functions.Upper,
functions.SpecialFunc
)

val lookup: Map[String, Function] = knownFunctions.map { f => (f.name.toLowerCase, f) }.toMap
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2002-2014 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.cypher.internal.compiler.v2_1.commands.expressions

import org.neo4j.cypher.internal.compiler.v2_1._
import pipes.QueryState
import symbols._
import org.neo4j.cypher.internal.helpers.CollectionSupport

import scala.collection.JavaConverters._

import clojure.java.api.Clojure

case class SpecialFunc(inner: Expression)
extends NullInNullOutExpression(inner)
with CollectionSupport
{
def compute(value: Any, m: ExecutionContext)(implicit state: QueryState) = {
val require = Clojure.`var`("clojure.core", "require");
require.invoke(Clojure.read("cypher-ext.core"))
val fn = Clojure.`var`("cypher-ext.core", "call")
fn.invoke(makeTraversable(value).toSeq.asJava)
}

def rewrite(f: (Expression) => Expression) = f(SpecialFunc(inner.rewrite(f)))

def arguments = Seq(inner)

def calculateType(symbols: SymbolTable): CypherType = CTAny

def symbolTableDependencies = inner.symbolTableDependencies
}
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2002-2014 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.cypher.internal.compiler.v2_1.functions

import org.neo4j.cypher.internal.compiler.v2_1._
import ast.convert.ExpressionConverters._
import commands.{expressions => commandexpressions}
import symbols._

case object SpecialFunc extends Function with SimpleTypedFunction {
def name = "specialfunc"

val signatures = Vector(
Signature(Vector(CTCollection(CTAny)), CTAny)
)

def asCommandExpression(invocation: ast.FunctionInvocation) =
commandexpressions.SpecialFunc(invocation.arguments(0).asCommandExpression)
}

0 comments on commit 359294e

Please sign in to comment.