use of io.crate.metadata.functions.Signature in project crate by crate.
the class AbstractFunctionModule method register.
public void register(Signature signature, BiFunction<Signature, Signature, FunctionImplementation> factory) {
List<FunctionProvider> functions = functionImplementations.computeIfAbsent(signature.getName(), k -> new ArrayList<>());
var duplicate = functions.stream().filter(fr -> fr.getSignature().equals(signature)).findFirst();
if (duplicate.isPresent()) {
throw new IllegalStateException("A function already exists for signature = " + signature);
}
functions.add(new FunctionProvider(signature, factory));
}
use of io.crate.metadata.functions.Signature in project crate by crate.
the class PgGetFunctionResultFunction method evaluate.
@Override
public String evaluate(TransactionContext txnCtx, NodeContext nodeCtx, Input<Integer>... args) {
assert args.length == 1 : NAME + " expects exactly 1 argument, got " + args.length;
Integer oid = args[0].value();
if (oid == null) {
return null;
}
Signature sig = nodeCtx.functions().findFunctionSignatureByOid(oid);
return sig != null ? sig.getReturnType().toString() : null;
}
use of io.crate.metadata.functions.Signature in project crate by crate.
the class SumAggregationTest method testFloatSummationWithoutLosingPrecision.
@Test
public void testFloatSummationWithoutLosingPrecision() throws Exception {
Object[][] rows = new Object[][] { { 0.8f }, { 0.4f }, { 0.2f } };
Signature signature = Signature.aggregate(SumAggregation.NAME, DataTypes.FLOAT.getTypeSignature(), DataTypes.FLOAT.getTypeSignature());
Object result = executeAggregation(signature, signature.getArgumentDataTypes(), signature.getReturnType().createType(), rows, false, List.of());
assertThat(result, is(1.4f));
}
use of io.crate.metadata.functions.Signature in project crate by crate.
the class SymbolPrinterTest method testFormatAggregation.
@Test
public void testFormatAggregation() throws Exception {
Signature signature = Signature.aggregate("agg", DataTypes.INTEGER.getTypeSignature(), DataTypes.LONG.getTypeSignature());
Aggregation a = new Aggregation(signature, DataTypes.LONG, Collections.singletonList(Literal.of(-127)));
assertPrint(a, "agg(-127)");
}
use of io.crate.metadata.functions.Signature in project crate by crate.
the class PgFunctionIsVisibleFunctionTest method test_system_function_visibility.
@Test
public void test_system_function_visibility() {
assertEvaluate("pg_function_is_visible(0)", false);
assertEvaluate("pg_function_is_visible(-14)", false);
for (List<FunctionProvider> providers : sqlExpressions.nodeCtx.functions().functionResolvers().values()) {
for (FunctionProvider sysFunc : providers) {
Signature signature = sysFunc.getSignature();
Integer funcOid = OidHash.functionOid(signature);
assertEvaluate("pg_function_is_visible(" + funcOid + ")", true);
}
}
}
Aggregations