Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-23-2021 09:11 AM
I'm trying to create a user defined procedure and it compiles okay but Neo4j fails to re-start after introducing the jar file. I'm trying to convert a string of 0's and 1's representing a base 2 number to a base 10 number which is returned as a long integer. I don't understand how to get the long output required by Neo4j. The error message in the log file is:
Caused by: org.neo4j.internal.kernel.api.exceptions.ProcedureException: Argument
radix
at position 1 inbaseConvert
with typeInteger
cannot be converted to a Neo4j type: Don't know how to mapjava.lang.Integer
to the Neo4j Type System.
The code is:
package genealogy;
import org.neo4j.procedure.Description;
import org.neo4j.procedure.Name;
import org.neo4j.procedure.UserFunction;
/**
* This is an example of a simple user-defined function for Neo4j to perform a baseConvert
*/
public class base2to10 {
@UserFunction
@Description("example.baseConvert('1101', 2) - Convert the provided base 2 string to a base 10 integer.")
public Integer baseConvert(
@Name("s")
String s,
@Name(value = "radix")
Integer radix
)
{
if (s == null || radix == null) {
return null;
}
return Integer.parseInt(s, radix);
}
}
08-24-2021 09:22 AM
Need to use Long in place of Integer.
I ran into the same thing yesterday evening and was eventually able to resolve by changing the type. The documentation does include a type mapping entry, but it wasn't immediately obvious in the udf section.
08-24-2021 12:30 PM
Mike,
Thanks! So others can see the full final solutions ...
package genealogy;
import org.neo4j.procedure.Description;
import org.neo4j.procedure.Name;
import org.neo4j.procedure.UserFunction;
/**
* This is an example of a simple user-defined function for Neo4j to perform a baseConvert
*/
public class base2to10 {
@UserFunction
@Description("example.baseConvert('1101', 2) - Convert the provided base 2 string to a base 10 integer.")
public Long baseConvert(
@Name("s")
String s
)
{
return Long.parseLong(s, 2);
}
}
I'm only working with base 2 to produce ahnentafel numbers ....
Then
return genealogy.baseConvert('111101')
produces
61
All the sessions of the conference are now available online