Search in sources :

Example 31 with ParamType

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"))));
}
Also used : ParamType(io.confluent.ksql.function.types.ParamType) MapType(io.confluent.ksql.function.types.MapType) LambdaType(io.confluent.ksql.function.types.LambdaType) StructType(io.confluent.ksql.function.types.StructType) Type(java.lang.reflect.Type) ArrayType(io.confluent.ksql.function.types.ArrayType) GenericType(io.confluent.ksql.function.types.GenericType) ParamType(io.confluent.ksql.function.types.ParamType) Test(org.junit.Test)

Example 32 with ParamType

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));
}
Also used : LambdaType(io.confluent.ksql.function.types.LambdaType) ParamType(io.confluent.ksql.function.types.ParamType) MapType(io.confluent.ksql.function.types.MapType) LambdaType(io.confluent.ksql.function.types.LambdaType) StructType(io.confluent.ksql.function.types.StructType) Type(java.lang.reflect.Type) ArrayType(io.confluent.ksql.function.types.ArrayType) GenericType(io.confluent.ksql.function.types.GenericType) ParamType(io.confluent.ksql.function.types.ParamType) Test(org.junit.Test)

Example 33 with ParamType

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);
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) ParamType(io.confluent.ksql.function.types.ParamType) MapType(io.confluent.ksql.function.types.MapType) LambdaType(io.confluent.ksql.function.types.LambdaType) ParameterizedType(java.lang.reflect.ParameterizedType) StructType(io.confluent.ksql.function.types.StructType) Type(java.lang.reflect.Type) ArrayType(io.confluent.ksql.function.types.ArrayType) GenericType(io.confluent.ksql.function.types.GenericType) TypeVariable(java.lang.reflect.TypeVariable) ArrayList(java.util.ArrayList) ParamType(io.confluent.ksql.function.types.ParamType)

Example 34 with ParamType

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);
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) ParamType(io.confluent.ksql.function.types.ParamType) MapType(io.confluent.ksql.function.types.MapType) LambdaType(io.confluent.ksql.function.types.LambdaType) ParameterizedType(java.lang.reflect.ParameterizedType) StructType(io.confluent.ksql.function.types.StructType) Type(java.lang.reflect.Type) ArrayType(io.confluent.ksql.function.types.ArrayType) GenericType(io.confluent.ksql.function.types.GenericType) TypeVariable(java.lang.reflect.TypeVariable) ParamType(io.confluent.ksql.function.types.ParamType)

Example 35 with ParamType

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);
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) ParamType(io.confluent.ksql.function.types.ParamType) MapType(io.confluent.ksql.function.types.MapType) LambdaType(io.confluent.ksql.function.types.LambdaType) ParameterizedType(java.lang.reflect.ParameterizedType) StructType(io.confluent.ksql.function.types.StructType) Type(java.lang.reflect.Type) ArrayType(io.confluent.ksql.function.types.ArrayType) GenericType(io.confluent.ksql.function.types.GenericType) TypeVariable(java.lang.reflect.TypeVariable) ParamType(io.confluent.ksql.function.types.ParamType)

Aggregations

ParamType (io.confluent.ksql.function.types.ParamType)35 GenericType (io.confluent.ksql.function.types.GenericType)26 Test (org.junit.Test)22 LambdaType (io.confluent.ksql.function.types.LambdaType)20 StructType (io.confluent.ksql.function.types.StructType)20 ArrayType (io.confluent.ksql.function.types.ArrayType)19 Type (java.lang.reflect.Type)19 MapType (io.confluent.ksql.function.types.MapType)18 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)11 HashMap (java.util.HashMap)5 KsqlException (io.confluent.ksql.util.KsqlException)4 ParameterizedType (java.lang.reflect.ParameterizedType)4 ArrayList (java.util.ArrayList)4 GenericArrayType (java.lang.reflect.GenericArrayType)3 TypeVariable (java.lang.reflect.TypeVariable)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Expression (io.confluent.ksql.execution.expression.tree.Expression)2 KsqlScalarFunction (io.confluent.ksql.function.KsqlScalarFunction)2 ParamTypes (io.confluent.ksql.function.types.ParamTypes)2 Kudf (io.confluent.ksql.function.udf.Kudf)2