Skip to content

Commit

Permalink
Allow fetching procedures et al by id
Browse files Browse the repository at this point in the history
We spend a lot of time fetching procedures and functions from a hash map.
This introduces the option of getting procedures and functions by id.
  • Loading branch information
pontusmelke committed Mar 3, 2018
1 parent 99d7610 commit f9ca9f1
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 94 deletions.
5 changes: 5 additions & 0 deletions community/kernel-api/pom.xml
Expand Up @@ -64,6 +64,11 @@ the relevant Commercial Agreement.
<artifactId>neo4j-graphdb-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-procedure-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-common</artifactId>
Expand Down
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2002-2018 "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.internal.kernel.api;

import org.neo4j.internal.kernel.api.exceptions.ProcedureException;
import org.neo4j.internal.kernel.api.procs.QualifiedName;
import org.neo4j.internal.kernel.api.procs.UserAggregator;
import org.neo4j.internal.kernel.api.procs.UserFunctionHandle;
import org.neo4j.internal.kernel.api.security.AccessMode;
import org.neo4j.values.AnyValue;

public interface Procedures
{
UserFunctionHandle functionGet( QualifiedName name );

UserFunctionHandle aggregationFunctionGet( QualifiedName name );

/** Invoke a read-only function by name
* @param id the id of the function.
* @param arguments the function arguments.
* @throws ProcedureException if there was an exception thrown during function execution.
*/
AnyValue functionCall( int id, AnyValue[] arguments ) throws ProcedureException;

/** Invoke a read-only function by name, and set the transaction's access mode to
* {@link AccessMode.Static#READ READ} for the duration of the function execution.
* @param id the id of the function.
* @param arguments the function arguments.
* @throws ProcedureException if there was an exception thrown during function execution.
*/
AnyValue functionCallOverride( int id, AnyValue[] arguments ) throws ProcedureException;

/**
* Create a read-only aggregation function by name
* @param id the id of the function
* @return the aggregation function
* @throws ProcedureException
*/
UserAggregator aggregationFunction( int id ) throws ProcedureException;

/** Invoke a read-only aggregation function by name, and set the transaction's access mode to
* {@link AccessMode.Static#READ READ} for the duration of the function execution.
* @param id the id of the function.
* @throws ProcedureException if there was an exception thrown during function execution.
*/
UserAggregator aggregationFunctionOverride( int id ) throws ProcedureException;

}
Expand Up @@ -20,6 +20,8 @@
package org.neo4j.internal.kernel.api;

import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.internal.kernel.api.procs.QualifiedName;
import org.neo4j.internal.kernel.api.procs.UserFunctionHandle;

/**
* Defines the graph read operations of the Kernel.
Expand Down
Expand Up @@ -122,4 +122,6 @@ enum Type
* @return The cursor factory
*/
CursorFactory cursors();

Procedures procedures();
}
Expand Up @@ -17,9 +17,9 @@
* 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.kernel.api.exceptions;
package org.neo4j.internal.kernel.api.exceptions;

import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.kernel.api.exceptions.Status;

public class ProcedureException extends KernelException
{
Expand Down
Expand Up @@ -17,13 +17,11 @@
* 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.kernel.impl.proc;
package org.neo4j.internal.kernel.api.procs;

import java.util.List;
import java.util.Map;

import org.neo4j.kernel.api.proc.Neo4jTypes;

public class DefaultParameterValue
{
private final Object value;
Expand All @@ -50,27 +48,27 @@ public static DefaultParameterValue ntString( String value )
return new DefaultParameterValue( value, Neo4jTypes.NTString );
}

static DefaultParameterValue ntInteger( long value )
public static DefaultParameterValue ntInteger( long value )
{
return new DefaultParameterValue( value, Neo4jTypes.NTInteger );
}

static DefaultParameterValue ntFloat( double value )
public static DefaultParameterValue ntFloat( double value )
{
return new DefaultParameterValue( value, Neo4jTypes.NTFloat );
}

static DefaultParameterValue ntBoolean( boolean value )
public static DefaultParameterValue ntBoolean( boolean value )
{
return new DefaultParameterValue( value, Neo4jTypes.NTBoolean );
}

static DefaultParameterValue ntMap( Map<String,Object> value )
public static DefaultParameterValue ntMap( Map<String,Object> value )
{
return new DefaultParameterValue( value, Neo4jTypes.NTMap );
}

static DefaultParameterValue ntList( List<?> value, Neo4jTypes.AnyType inner )
public static DefaultParameterValue ntList( List<?> value, Neo4jTypes.AnyType inner )
{
return new DefaultParameterValue( value, Neo4jTypes.NTList( inner ) );
}
Expand Down
Expand Up @@ -17,13 +17,11 @@
* 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.kernel.api.proc;
package org.neo4j.internal.kernel.api.procs;

import java.util.Objects;
import java.util.Optional;

import org.neo4j.kernel.impl.proc.DefaultParameterValue;

import static java.util.Objects.requireNonNull;

/** Represents a type and a name for a field in a record, used to define input and output record signatures. */
Expand Down
Expand Up @@ -17,7 +17,7 @@
* 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.kernel.api.proc;
package org.neo4j.internal.kernel.api.procs;

/**
* See also type_system.txt in the cypher code base, this is a mapping of that type system definition
Expand Down
Expand Up @@ -17,7 +17,7 @@
* 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.kernel.api.proc;
package org.neo4j.internal.kernel.api.procs;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -26,9 +26,7 @@
import java.util.Optional;

import org.neo4j.helpers.collection.Iterables;
import org.neo4j.kernel.api.proc.Neo4jTypes.AnyType;
import org.neo4j.procedure.Mode;

import static java.util.Collections.unmodifiableList;

/**
Expand All @@ -43,19 +41,19 @@ public class ProcedureSignature
private final List<FieldSignature> inputSignature;
private final List<FieldSignature> outputSignature;
private final Mode mode;
private final Optional<String> deprecated;
private final String deprecated;
private final String[] allowed;
private final Optional<String> description;
private final Optional<String> warning;
private final String description;
private final String warning;

public ProcedureSignature( QualifiedName name,
List<FieldSignature> inputSignature,
List<FieldSignature> outputSignature,
Mode mode,
Optional<String> deprecated,
String deprecated,
String[] allowed,
Optional<String> description,
Optional<String> warning )
String description,
String warning )
{
this.name = name;
this.inputSignature = unmodifiableList( inputSignature );
Expand All @@ -79,7 +77,7 @@ public Mode mode()

public Optional<String> deprecated()
{
return deprecated;
return Optional.ofNullable( deprecated );
}

public String[] allowed()
Expand All @@ -104,12 +102,12 @@ public boolean isVoid()

public Optional<String> description()
{
return description;
return Optional.ofNullable( description );
}

public Optional<String> warning()
{
return warning;
return Optional.ofNullable( warning );
}

@Override
Expand Down Expand Up @@ -156,10 +154,10 @@ public static class Builder
private final List<FieldSignature> inputSignature = new LinkedList<>();
private List<FieldSignature> outputSignature = new LinkedList<>();
private Mode mode = Mode.READ;
private Optional<String> deprecated = Optional.empty();
private String deprecated;
private String[] allowed = new String[0];
private Optional<String> description = Optional.empty();
private Optional<String> warning = Optional.empty();
private String description;
private String warning;

public Builder( String[] namespace, String name )
{
Expand All @@ -174,25 +172,25 @@ public Builder mode( Mode mode )

public Builder description( String description )
{
this.description = Optional.of( description );
this.description = description;
return this;
}

public Builder deprecatedBy( String deprecated )
{
this.deprecated = Optional.of( deprecated );
this.deprecated = deprecated;
return this;
}

/** Define an input field */
public Builder in( String name, AnyType type )
public Builder in( String name, Neo4jTypes.AnyType type )
{
inputSignature.add( FieldSignature.inputField( name, type ) );
return this;
}

/** Define an output field */
public Builder out( String name, AnyType type )
public Builder out( String name, Neo4jTypes.AnyType type )
{
outputSignature.add( FieldSignature.outputField( name, type ) );
return this;
Expand All @@ -212,7 +210,7 @@ public Builder allowed( String[] allowed )

public Builder warning( String warning )
{
this.warning = Optional.of( warning );
this.warning = warning;
return this;
}

Expand Down
Expand Up @@ -17,7 +17,7 @@
* 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.kernel.api.proc;
package org.neo4j.internal.kernel.api.procs;

import java.util.Arrays;
import java.util.List;
Expand Down
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2002-2018 "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.internal.kernel.api.procs;

import org.neo4j.internal.kernel.api.exceptions.ProcedureException;

public interface UserAggregator
{
void update( Object[] input ) throws ProcedureException;

Object result() throws ProcedureException;
}
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2002-2018 "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.internal.kernel.api.procs;


public class UserFunctionHandle
{
private final UserFunctionSignature signature;
private final int id;

public UserFunctionHandle( UserFunctionSignature signature, int id )
{
this.signature = signature;
this.id = id;
}

public UserFunctionSignature signature()
{
return signature;
}

public int id()
{
return id;
}
}

0 comments on commit f9ca9f1

Please sign in to comment.