Search in sources :

Example 6 with TypeSignature

use of io.crate.types.TypeSignature in project crate by crate.

the class UserDefinedFunctionsIntegrationTest method test_pg_get_function_result.

@Test
public void test_pg_get_function_result() throws Exception {
    TypeSignature returnTypeSig = TypeSignature.parseTypeSignature("array(array(integer))");
    String returnType = returnTypeSig.toString();
    Signature signature = Signature.builder().kind(FunctionType.SCALAR).name(new FunctionName(Schemas.DOC_SCHEMA_NAME, "make_2d_array")).argumentTypes(DataTypes.INTEGER.getTypeSignature()).returnType(returnTypeSig).build();
    int functionOid = OidHash.functionOid(signature);
    execute("select pg_get_function_result(?)", new Object[] { functionOid });
    assertThat(response.rows()[0][0], nullValue());
    execute("create function doc.make_2d_array(integer) returns array(array(integer)) language dummy_lang as ?", new Object[] { returnType });
    execute("select pg_get_function_result(" + functionOid + ")");
    assertThat(response.rows()[0][0], is(returnType));
    execute("drop function doc.make_2d_array(integer)");
    execute("select pg_get_function_result(" + functionOid + ")");
    assertThat(response.rows()[0][0], nullValue());
}
Also used : FunctionName(io.crate.metadata.FunctionName) TypeSignature(io.crate.types.TypeSignature) Signature(io.crate.metadata.functions.Signature) TypeSignature(io.crate.types.TypeSignature) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

TypeSignature (io.crate.types.TypeSignature)6 ParameterTypeSignature (io.crate.types.ParameterTypeSignature)3 Nullable (javax.annotation.Nullable)2 FunctionName (io.crate.metadata.FunctionName)1 BoundVariables (io.crate.metadata.functions.BoundVariables)1 Signature (io.crate.metadata.functions.Signature)1 ArrayList (java.util.ArrayList)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1