use of io.crate.metadata.functions.Signature in project crate by crate.
the class PgGetFunctionResultFunctionTest method test_system_function_result_type_text_representation.
@Test
public void test_system_function_result_type_text_representation() {
for (List<FunctionProvider> providers : sqlExpressions.nodeCtx.functions().functionResolvers().values()) {
for (FunctionProvider sysFunc : providers) {
Signature signature = sysFunc.getSignature();
Integer funcOid = OidHash.functionOid(signature);
assertEvaluate("pg_get_function_result(" + funcOid + ")", signature.getReturnType().toString());
}
}
}
use of io.crate.metadata.functions.Signature in project crate by crate.
the class ExpressionAnalyzer method allocateBuiltinOrUdfFunction.
/**
* Creates a function symbol and tries to normalize the new function's
* {@link FunctionImplementation} iff only Literals are supplied as arguments.
* This folds any constant expressions like '1 + 1' => '2'.
* @param schema The schema for udf functions
* @param functionName The function name of the new function.
* @param arguments The arguments to provide to the {@link Function}.
* @param filter The filter clause to filter {@link Function}'s input values.
* @param context Context holding the state for the current translation.
* @param windowDefinition The definition of the window the allocated function will be executed against.
* @param coordinatorTxnCtx {@link CoordinatorTxnCtx} for this transaction.
* @param nodeCtx The {@link NodeContext} to normalize constant expressions.
* @return The supplied {@link Function} or a {@link Literal} in case of constant folding.
*/
private static Symbol allocateBuiltinOrUdfFunction(@Nullable String schema, String functionName, List<Symbol> arguments, @Nullable Symbol filter, @Nullable Boolean ignoreNulls, ExpressionAnalysisContext context, @Nullable WindowDefinition windowDefinition, CoordinatorTxnCtx coordinatorTxnCtx, NodeContext nodeCtx) {
FunctionImplementation funcImpl = nodeCtx.functions().get(schema, functionName, arguments, coordinatorTxnCtx.sessionContext().searchPath());
Signature signature = funcImpl.signature();
Signature boundSignature = funcImpl.boundSignature();
List<Symbol> castArguments = cast(arguments, boundSignature.getArgumentDataTypes());
Function newFunction;
if (windowDefinition == null) {
if (signature.getKind() == FunctionType.AGGREGATE) {
context.indicateAggregates();
} else if (filter != null) {
throw new UnsupportedOperationException("Only aggregate functions allow a FILTER clause");
}
if (ignoreNulls != null) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "%s cannot accept RESPECT or IGNORE NULLS flag.", functionName));
}
newFunction = new Function(signature, castArguments, boundSignature.getReturnType().createType(), filter);
} else {
if (signature.getKind() != FunctionType.WINDOW) {
if (signature.getKind() != FunctionType.AGGREGATE) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "OVER clause was specified, but %s is neither a window nor an aggregate function.", functionName));
} else {
if (ignoreNulls != null) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "%s cannot accept RESPECT or IGNORE NULLS flag.", functionName));
}
}
}
newFunction = new WindowFunction(signature, castArguments, boundSignature.getReturnType().createType(), filter, windowDefinition, ignoreNulls);
}
return newFunction;
}
use of io.crate.metadata.functions.Signature in project crate by crate.
the class UserDefinedFunctionsIntegrationTest method test_pg_function_is_visible_when_oid_is_retrieved_from_column.
@Test
public void test_pg_function_is_visible_when_oid_is_retrieved_from_column() throws Exception {
Signature signature = Signature.builder().kind(FunctionType.SCALAR).name(new FunctionName(null, CurrentTimeFunction.NAME)).argumentTypes().returnType(DataTypes.TIMETZ.getTypeSignature()).build();
int functionOid = OidHash.functionOid(signature);
execute("create table oid_test(oid integer)");
execute("insert into oid_test values(" + functionOid + ")");
execute("refresh table oid_test");
execute("select pg_function_is_visible(t.oid) from oid_test t");
assertThat(response.rows()[0][0], is(true));
execute("drop table oid_test");
}
use of io.crate.metadata.functions.Signature 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());
}
use of io.crate.metadata.functions.Signature in project crate by crate.
the class UserDefinedFunctionsIntegrationTest method test_pg_function_is_visible.
@Test
public void test_pg_function_is_visible() throws Exception {
Signature signature = Signature.builder().kind(FunctionType.SCALAR).name(new FunctionName(Schemas.DOC_SCHEMA_NAME, "my_func")).argumentTypes(TypeSignature.parseTypeSignature("array(array(integer))"), TypeSignature.parseTypeSignature("integer"), TypeSignature.parseTypeSignature("text")).returnType(TypeSignature.parseTypeSignature("text")).build();
int functionOid = OidHash.functionOid(signature);
execute("select pg_function_is_visible(" + functionOid + ")");
assertThat(response.rows()[0][0], is(false));
execute("create function doc.my_func(array(array(integer)), integer, text) returns text language dummy_lang as '42'");
execute("select pg_function_is_visible(" + functionOid + ")");
assertThat(response.rows()[0][0], is(true));
execute("drop function doc.my_func(array(array(integer)), integer, text)");
execute("select pg_function_is_visible(" + functionOid + ")");
assertThat(response.rows()[0][0], is(false));
}
Aggregations