Search in sources :

Example 11 with FunctionInfo

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

Example 12 with FunctionInfo

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

the class CoordinateFunction method register.

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

Example 13 with FunctionInfo

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

the class GeoHashFunction method register.

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

Example 14 with FunctionInfo

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

the class SelectStatementAnalyzerTest method testArrayCompareAny.

@Test
public void testArrayCompareAny() throws Exception {
    SelectAnalyzedStatement analysis = analyze("select * from users where 0 = ANY (counters)");
    assertThat(analysis.relation().querySpec().where().hasQuery(), is(true));
    FunctionInfo anyInfo = ((Function) analysis.relation().querySpec().where().query()).info();
    assertThat(anyInfo.ident().name(), is("any_="));
    analysis = analyze("select * from users where 0 = ANY (counters)");
    assertThat(analysis.relation().querySpec().where().hasQuery(), is(true));
    anyInfo = ((Function) analysis.relation().querySpec().where().query()).info();
    assertThat(anyInfo.ident().name(), is("any_="));
}
Also used : DistanceFunction(io.crate.operation.scalar.geo.DistanceFunction) SubscriptFunction(io.crate.operation.scalar.SubscriptFunction) MatchesFunction(io.crate.operation.scalar.regex.MatchesFunction) AddFunction(io.crate.operation.scalar.arithmetic.AddFunction) FunctionInfo(io.crate.metadata.FunctionInfo) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 15 with FunctionInfo

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

the class SelectStatementAnalyzerTest method testArrayCompareAnyNeq.

@Test
public void testArrayCompareAnyNeq() throws Exception {
    SelectAnalyzedStatement analysis = analyze("select * from users where ? != ANY (counters)", new Object[] { 4.3F });
    assertThat(analysis.relation().querySpec().where().hasQuery(), is(true));
    FunctionInfo anyInfo = ((Function) analysis.relation().querySpec().where().query()).info();
    assertThat(anyInfo.ident().name(), is("any_<>"));
}
Also used : DistanceFunction(io.crate.operation.scalar.geo.DistanceFunction) SubscriptFunction(io.crate.operation.scalar.SubscriptFunction) MatchesFunction(io.crate.operation.scalar.regex.MatchesFunction) AddFunction(io.crate.operation.scalar.arithmetic.AddFunction) FunctionInfo(io.crate.metadata.FunctionInfo) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

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