Search in sources :

Example 16 with FunctionIdent

use of io.crate.metadata.FunctionIdent in project crate by crate.

the class SubscriptFunctionTest method testNotRegisteredForSets.

@Test
public void testNotRegisteredForSets() throws Exception {
    expectedException.expect(UnsupportedOperationException.class);
    expectedException.expectMessage("unknown function: subscript(integer_set, integer)");
    FunctionIdent functionIdent = new FunctionIdent(SubscriptFunction.NAME, Arrays.<DataType>asList(new SetType(DataTypes.INTEGER), DataTypes.INTEGER));
    functions.getSafe(functionIdent);
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) SetType(io.crate.types.SetType) Test(org.junit.Test)

Example 17 with FunctionIdent

use of io.crate.metadata.FunctionIdent in project crate by crate.

the class LengthFunction method register.

private static void register(ScalarFunctionModule module, String name, Function<BytesRef, Integer> func) {
    for (DataType inputType : SUPPORTED_INPUT_TYPES) {
        FunctionIdent ident = new FunctionIdent(name, Collections.singletonList(inputType));
        module.register(new UnaryScalar<>(new FunctionInfo(ident, DataTypes.INTEGER), func));
    }
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) DataType(io.crate.types.DataType) FunctionInfo(io.crate.metadata.FunctionInfo)

Example 18 with FunctionIdent

use of io.crate.metadata.FunctionIdent in project crate by crate.

the class DateFormatFunction method register.

public static void register(ScalarFunctionModule module) {
    List<DataType> supportedTimestampTypes = ImmutableList.<DataType>of(DataTypes.TIMESTAMP, DataTypes.LONG, DataTypes.STRING);
    for (DataType dataType : supportedTimestampTypes) {
        // without format
        module.register(new DateFormatFunction(new FunctionInfo(new FunctionIdent(NAME, ImmutableList.of(dataType)), DataTypes.STRING)));
        // with format
        module.register(new DateFormatFunction(new FunctionInfo(new FunctionIdent(NAME, ImmutableList.of(DataTypes.STRING, dataType)), DataTypes.STRING)));
        // time zone aware variant
        module.register(new DateFormatFunction(new FunctionInfo(new FunctionIdent(NAME, ImmutableList.of(DataTypes.STRING, DataTypes.STRING, dataType)), DataTypes.STRING)));
    }
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) DataType(io.crate.types.DataType) FunctionInfo(io.crate.metadata.FunctionInfo)

Example 19 with FunctionIdent

use of io.crate.metadata.FunctionIdent in project crate by crate.

the class TrigonometricFunctions method register.

private static void register(ScalarFunctionModule module, String name, DoubleUnaryOperator func) {
    for (DataType inputType : DataTypes.NUMERIC_PRIMITIVE_TYPES) {
        FunctionIdent ident = new FunctionIdent(name, Collections.singletonList(inputType));
        module.register(new DoubleScalar(new FunctionInfo(ident, DataTypes.DOUBLE), func));
    }
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) DataType(io.crate.types.DataType) FunctionInfo(io.crate.metadata.FunctionInfo) DoubleScalar(io.crate.operation.scalar.DoubleScalar)

Example 20 with FunctionIdent

use of io.crate.metadata.FunctionIdent in project crate by crate.

the class CastFunctionResolver method functionInfo.

/**
     * resolve the needed conversion function info based on the wanted return data type
     */
@VisibleForTesting
static FunctionInfo functionInfo(DataType dataType, DataType returnType, boolean tryCast) {
    String functionName = FUNCTION_MAP.get(returnType);
    if (functionName == null) {
        throw new IllegalArgumentException(String.format(Locale.ENGLISH, "No cast function found for return type %s", returnType.getName()));
    }
    functionName = tryCast ? TRY_CAST_PREFIX + functionName : functionName;
    return new FunctionInfo(new FunctionIdent(functionName, ImmutableList.of(dataType)), returnType);
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) FunctionInfo(io.crate.metadata.FunctionInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

FunctionIdent (io.crate.metadata.FunctionIdent)32 Test (org.junit.Test)19 FunctionInfo (io.crate.metadata.FunctionInfo)15 AggregationTest (io.crate.operation.aggregation.AggregationTest)12 DataType (io.crate.types.DataType)8 CrateUnitTest (io.crate.test.integration.CrateUnitTest)6 Aggregation (io.crate.analyze.symbol.Aggregation)4 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)4 AggregationFunction (io.crate.operation.aggregation.AggregationFunction)3 InputCollectExpression (io.crate.operation.collect.InputCollectExpression)3 StreamInput (org.elasticsearch.common.io.stream.StreamInput)3 Function (io.crate.analyze.symbol.Function)2 InputColumn (io.crate.analyze.symbol.InputColumn)2 Symbol (io.crate.analyze.symbol.Symbol)2 Reference (io.crate.metadata.Reference)2 Aggregator (io.crate.operation.aggregation.Aggregator)2 CountAggregation (io.crate.operation.aggregation.impl.CountAggregation)2 CollectExpression (io.crate.operation.collect.CollectExpression)2 SetType (io.crate.types.SetType)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1