Search in sources :

Example 6 with ParamType

use of io.confluent.ksql.function.types.ParamType in project ksql by confluentinc.

the class UdfUtilTest method shouldGetFunction.

@Test
public void shouldGetFunction() throws NoSuchMethodException {
    final Type type = getClass().getDeclaredMethod("functionType", Function.class).getGenericParameterTypes()[0];
    final ParamType schema = UdfUtil.getSchemaFromType(type);
    assertThat(schema, instanceOf(LambdaType.class));
    assertThat(((LambdaType) schema).inputTypes(), equalTo(ImmutableList.of(ParamTypes.LONG)));
    assertThat(((LambdaType) schema).returnType(), equalTo(ParamTypes.INTEGER));
}
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 7 with ParamType

use of io.confluent.ksql.function.types.ParamType in project ksql by confluentinc.

the class UdfUtilTest method shouldGetPartialGenericTriFunction.

@Test
public void shouldGetPartialGenericTriFunction() throws NoSuchMethodException {
    // Given:
    final Type genericType = getClass().getMethod("partialGenericTriFunctionType").getGenericReturnType();
    // When:
    final ParamType returnType = UdfUtil.getSchemaFromType(genericType);
    // Then:
    assertThat(returnType, is(LambdaType.of(ImmutableList.of(GenericType.of("T"), ParamTypes.BOOLEAN, GenericType.of("U")), ParamTypes.INTEGER)));
}
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 8 with ParamType

use of io.confluent.ksql.function.types.ParamType in project ksql by confluentinc.

the class UdfUtilTest method shouldGetGenericTriFunction.

@Test
public void shouldGetGenericTriFunction() throws NoSuchMethodException {
    // Given:
    final Type genericType = getClass().getMethod("genericTriFunctionType").getGenericReturnType();
    // When:
    final ParamType returnType = UdfUtil.getSchemaFromType(genericType);
    // Then:
    assertThat(returnType, is(LambdaType.of(ImmutableList.of(GenericType.of("T"), GenericType.of("U"), GenericType.of("V")), GenericType.of("W"))));
}
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 9 with ParamType

use of io.confluent.ksql.function.types.ParamType in project ksql by confluentinc.

the class UdfUtilTest method shouldGetMapSchemaFromMapClass.

@Test
public void shouldGetMapSchemaFromMapClass() throws NoSuchMethodException {
    final Type type = getClass().getDeclaredMethod("mapType", Map.class).getGenericParameterTypes()[0];
    final ParamType schema = UdfUtil.getSchemaFromType(type);
    assertThat(schema, instanceOf(MapType.class));
    assertThat(((MapType) schema).value(), equalTo(ParamTypes.INTEGER));
}
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) MapType(io.confluent.ksql.function.types.MapType) Test(org.junit.Test)

Example 10 with ParamType

use of io.confluent.ksql.function.types.ParamType in project ksql by confluentinc.

the class UdfUtilTest method shouldGetGenericSchemaFromPartialParameterizedType.

@Test
public void shouldGetGenericSchemaFromPartialParameterizedType() throws NoSuchMethodException {
    // Given:
    final Type genericType = getClass().getMethod("partialGenericMapType").getGenericReturnType();
    // When:
    final ParamType returnType = UdfUtil.getSchemaFromType(genericType);
    // Then:
    assertThat(returnType, is(MapType.of(ParamTypes.LONG, GenericType.of("V"))));
}
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)

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