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