Argument Matching in Splice Machine

When you declare a function or procedure using CREATE FUNCTION/PROCEDURE, Splice Machine does not verify whether a matching Java method exists. Instead, Splice Machine looks for a matching method only when you invoke the function or procedure in a later SQL statement.

At that time, Splice Machine searches for a public, static method having the class and method name declared in the EXTERNAL NAME clause of the earlier CREATE FUNCTION/PROCEDURE statement. Furthermore, the Java types of the method’s arguments and return value must match the SQL types declared in the CREATE FUNCTION/PROCEDURE statement.

The following may happen:

Result Description
Success If exactly one Java method matches, then Splice Machine invokes it.
Ambiguity If exactly one Java method matches, then Splice Machine invokes it.
Failure Splice Machine also raises an error if no method matches.

In mapping SQL data types to Java data types, Splice Machine considers the following kinds of matches:

Result Description  
Primitive Match Splice Machine looks for a primitive Java type corresponding to the SQL type. For instance, SQL INTEGER matches Java int
Wrapper Match Splice Machine looks for a wrapper class in the java.lang or java.sql packages corresponding to the SQL type. For instance, SQL INTEGER matches java.lang.Integer. For a user-defined type (UDT), Splice Machine looks for the UDT's external name class.
Array Match For OUT and INOUT procedure arguments, Splice Machine looks for an array of the corresponding primitive or wrapper type. For example, an OUT procedure argument of type SQL INTEGER matches int[] and Integer[].
ResultSet Match If a procedure is declared to return n RESULT SETS, Splice Machine looks for a method whose last n arguments are of type java.sql.ResultSet[].

Splice Machine resolves function and procedure invocations as follows:

Call type Resolution
Function Splice Machine looks for a method whose argument and return types are primitive matches or wrapper matches for the function's SQL arguments and return value.
Procedure

Splice Machine looks for a method which returns void and whose argument types match as follows:

  • IN - Method arguments are primitive matches or wrapper matches for the procedure's IN arguments.
  • OUT and INOUT - Method arguments are array matches for the procedure's OUT and INOUT arguments.

In addition, if the procedure returns n RESULT SETS, then the last n arguments of the Java method must be of type java.sql.ResultSet[]

Example of argument matching

The following function:

CREATE FUNCTION TO_DEGREES
     ( RADIANS DOUBLE )
RETURNS DOUBLE
PARAMETER STYLE JAVA
NO SQL
LANGUAGE JAVA
EXTERNAL NAME 'example.MathUtils.toDegrees'
;

would match all of the following methods:

public static double toDegrees( double arg ) {...}
public static Double toDegrees( double arg ) {...}
public static double toDegrees( Double arg ) {...}
public static Double toDegrees( Double arg ) {...}

Note that Splice Machine raises an exception if it finds more than one matching method.

Mapping SQL data types to Java data types

The following table shows how Splice Machine maps specific SQL data types to Java data types.

SQL and Java type correspondence
SQL Type Primitive Match Wrapper Match
BOOLEAN boolean java.lang.Boolean
SMALLINT short java.lang.Integer
INTEGER int java.lang.Integer
BIGINT long java.lang.Long
DECIMAL None java.math.BigDecimal
NUMERIC None java.math.BigDecimal
REAL float java.lang.Float
DOUBLE double java.lang.Double
FLOAT double java.lang.Double
CHAR None java.lang.String
VARCHAR None java.lang.String
LONG VARCHAR None java.lang.String
CLOB None java.sql.Clob
BLOB None java.sql.Blob
DATE None java.sql.Date
TIME None java.sql.Time
TIMESTAMP None java.sql.Timestamp
User-defined type None Underlying Java class

See Also