Search in sources :

Example 6 with FunctionInfo

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

the class FunctionTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    Function fn = new Function(new FunctionInfo(new FunctionIdent(randomAsciiOfLength(10), ImmutableList.of(DataTypes.BOOLEAN)), TestingHelpers.randomPrimitiveType(), FunctionInfo.Type.SCALAR, randomFeatures()), Collections.singletonList(TestingHelpers.createReference(randomAsciiOfLength(2), DataTypes.BOOLEAN)));
    BytesStreamOutput output = new BytesStreamOutput();
    Symbols.toStream(fn, output);
    StreamInput input = StreamInput.wrap(output.bytes());
    Function fn2 = (Function) Symbols.fromStream(input);
    assertThat(fn, is(equalTo(fn2)));
    assertThat(fn.hashCode(), is(fn2.hashCode()));
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) StreamInput(org.elasticsearch.common.io.stream.StreamInput) FunctionInfo(io.crate.metadata.FunctionInfo) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with FunctionInfo

use of io.crate.metadata.FunctionInfo 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 8 with FunctionInfo

use of io.crate.metadata.FunctionInfo 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 9 with FunctionInfo

use of io.crate.metadata.FunctionInfo 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 10 with FunctionInfo

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

the class CastFunctionResolver method generateCastFunction.

public static Symbol generateCastFunction(Symbol sourceSymbol, DataType targetType, boolean tryCast) {
    DataType sourceType = sourceSymbol.valueType();
    FunctionInfo functionInfo = functionInfo(sourceType, targetType, tryCast);
    //noinspection ArraysAsListWithZeroOrOneArgument  # arguments of Function must be mutable
    return new io.crate.analyze.symbol.Function(functionInfo, Arrays.asList(sourceSymbol));
}
Also used : Function(com.google.common.base.Function) DataType(io.crate.types.DataType) FunctionInfo(io.crate.metadata.FunctionInfo)

Aggregations

FunctionInfo (io.crate.metadata.FunctionInfo)18 FunctionIdent (io.crate.metadata.FunctionIdent)15 CrateUnitTest (io.crate.test.integration.CrateUnitTest)7 DataType (io.crate.types.DataType)7 Test (org.junit.Test)7 Aggregation (io.crate.analyze.symbol.Aggregation)4 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)3 StreamInput (org.elasticsearch.common.io.stream.StreamInput)3 InputColumn (io.crate.analyze.symbol.InputColumn)2 Symbol (io.crate.analyze.symbol.Symbol)2 Reference (io.crate.metadata.Reference)2 AggregationFunction (io.crate.operation.aggregation.AggregationFunction)2 Aggregator (io.crate.operation.aggregation.Aggregator)2 CountAggregation (io.crate.operation.aggregation.impl.CountAggregation)2 CollectExpression (io.crate.operation.collect.CollectExpression)2 InputCollectExpression (io.crate.operation.collect.InputCollectExpression)2 SubscriptFunction (io.crate.operation.scalar.SubscriptFunction)2 AddFunction (io.crate.operation.scalar.arithmetic.AddFunction)2 DistanceFunction (io.crate.operation.scalar.geo.DistanceFunction)2 MatchesFunction (io.crate.operation.scalar.regex.MatchesFunction)2