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);
}
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));
}
}
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));
}
}
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_="));
}
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_<>"));
}
Aggregations