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