use of io.confluent.ksql.function.types.ParamType in project ksql by confluentinc.
the class UdfUtilTest method shouldGetGenericBiFunction.
@Test
public void shouldGetGenericBiFunction() throws NoSuchMethodException {
// Given:
final Type genericType = getClass().getMethod("partialGenericBiFunctionType").getGenericReturnType();
// When:
final ParamType returnType = UdfUtil.getSchemaFromType(genericType);
// Then:
assertThat(returnType, is(LambdaType.of(ImmutableList.of(GenericType.of("T"), ParamTypes.BOOLEAN), GenericType.of("U"))));
}
use of io.confluent.ksql.function.types.ParamType in project ksql by confluentinc.
the class UdfUtilTest method shouldGetBiFunction.
@Test
public void shouldGetBiFunction() throws NoSuchMethodException {
final Type type = getClass().getDeclaredMethod("biFunctionType", BiFunction.class).getGenericParameterTypes()[0];
final ParamType schema = UdfUtil.getSchemaFromType(type);
assertThat(schema, instanceOf(LambdaType.class));
assertThat(((LambdaType) schema).inputTypes(), equalTo(ImmutableList.of(ParamTypes.LONG, ParamTypes.INTEGER)));
assertThat(((LambdaType) schema).returnType(), equalTo(ParamTypes.BOOLEAN));
}
use of io.confluent.ksql.function.types.ParamType in project ksql by confluentinc.
the class UdfUtil method handleLambdaType.
private static ParamType handleLambdaType(final ParameterizedType type) {
final List<ParamType> inputParamTypes = new ArrayList<>();
for (int i = 0; i < type.getActualTypeArguments().length - 1; i++) {
final Type inputType = type.getActualTypeArguments()[i];
final ParamType inputParamType = inputType instanceof TypeVariable ? GenericType.of(((TypeVariable<?>) inputType).getName()) : getSchemaFromType(inputType);
inputParamTypes.add(inputParamType);
}
final Type returnType = type.getActualTypeArguments()[type.getActualTypeArguments().length - 1];
final ParamType returnParamType = returnType instanceof TypeVariable ? GenericType.of(((TypeVariable<?>) returnType).getName()) : getSchemaFromType(returnType);
return LambdaType.of(inputParamTypes, returnParamType);
}
use of io.confluent.ksql.function.types.ParamType in project ksql by confluentinc.
the class UdfUtil method handleListType.
private static ParamType handleListType(final ParameterizedType type) {
final Type elementType = type.getActualTypeArguments()[0];
final ParamType elementParamType = elementType instanceof TypeVariable ? GenericType.of(((TypeVariable<?>) elementType).getName()) : getSchemaFromType(elementType);
return ArrayType.of(elementParamType);
}
use of io.confluent.ksql.function.types.ParamType in project ksql by confluentinc.
the class UdfUtil method handleMapType.
private static ParamType handleMapType(final ParameterizedType type) {
final Type keyType = type.getActualTypeArguments()[0];
final ParamType keyParamType = keyType instanceof TypeVariable ? GenericType.of(((TypeVariable<?>) keyType).getName()) : getSchemaFromType(keyType);
final Type valueType = type.getActualTypeArguments()[1];
final ParamType valueParamType = valueType instanceof TypeVariable ? GenericType.of(((TypeVariable<?>) valueType).getName()) : getSchemaFromType(valueType);
return MapType.of(keyParamType, valueParamType);
}
Aggregations