Search in sources :

Example 1 with Signature

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));
}
Also used : List(java.util.List) FunctionImplementation(io.crate.metadata.FunctionImplementation) AbstractModule(org.elasticsearch.common.inject.AbstractModule) FunctionName(io.crate.metadata.FunctionName) Map(java.util.Map) BiFunction(java.util.function.BiFunction) FunctionProvider(io.crate.metadata.FunctionProvider) HashMap(java.util.HashMap) Signature(io.crate.metadata.functions.Signature) MapBinder(org.elasticsearch.common.inject.multibindings.MapBinder) TypeLiteral(org.elasticsearch.common.inject.TypeLiteral) ArrayList(java.util.ArrayList) FunctionProvider(io.crate.metadata.FunctionProvider)

Example 2 with Signature

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;
}
Also used : Signature(io.crate.metadata.functions.Signature)

Example 3 with Signature

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));
}
Also used : Signature(io.crate.metadata.functions.Signature) Test(org.junit.Test)

Example 4 with Signature

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)");
}
Also used : Aggregation(io.crate.expression.symbol.Aggregation) Signature(io.crate.metadata.functions.Signature) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 5 with Signature

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);
        }
    }
}
Also used : FunctionProvider(io.crate.metadata.FunctionProvider) Signature(io.crate.metadata.functions.Signature) Test(org.junit.Test)

Aggregations

Signature (io.crate.metadata.functions.Signature)12 Test (org.junit.Test)8 FunctionName (io.crate.metadata.FunctionName)4 FunctionImplementation (io.crate.metadata.FunctionImplementation)3 FunctionProvider (io.crate.metadata.FunctionProvider)3 TypeSignature (io.crate.types.TypeSignature)3 Input (io.crate.data.Input)2 Symbol (io.crate.expression.symbol.Symbol)2 Scalar (io.crate.metadata.Scalar)2 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)2 List (java.util.List)2 Map (java.util.Map)2 UnsupportedFeatureException (io.crate.exceptions.UnsupportedFeatureException)1 ArraySliceFunction (io.crate.expression.scalar.ArraySliceFunction)1 CurrentDateFunction (io.crate.expression.scalar.CurrentDateFunction)1 SubscriptFunction (io.crate.expression.scalar.SubscriptFunction)1 ArrayFunction (io.crate.expression.scalar.arithmetic.ArrayFunction)1 MapFunction (io.crate.expression.scalar.arithmetic.MapFunction)1 IfFunction (io.crate.expression.scalar.conditional.IfFunction)1 CurrentTimeFunction (io.crate.expression.scalar.timestamp.CurrentTimeFunction)1