Search in sources :

Example 11 with ParamType

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

the class UdfUtilTest method shouldGetGenericFunction.

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

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

the class UdfUtilTest method shouldGetGenericSchemaFromType.

@Test
public void shouldGetGenericSchemaFromType() throws NoSuchMethodException {
    // Given:
    final Type genericType = getClass().getMethod("genericType").getGenericReturnType();
    // When:
    final ParamType returnType = UdfUtil.getSchemaFromType(genericType);
    // Then:
    MatcherAssert.assertThat(returnType, CoreMatchers.is(GenericType.of("T")));
}
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 13 with ParamType

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

the class UdfUtilTest method shouldGetPartialGenericFunction.

@Test
public void shouldGetPartialGenericFunction() throws NoSuchMethodException {
    // Given:
    final Type genericType = getClass().getMethod("partialGenericFunctionType").getGenericReturnType();
    // When:
    final ParamType returnType = UdfUtil.getSchemaFromType(genericType);
    // Then:
    assertThat(returnType, is(LambdaType.of(ImmutableList.of(ParamTypes.LONG), 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 14 with ParamType

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

the class UdfUtilTest method shouldGetTriFunction.

@Test
public void shouldGetTriFunction() throws NoSuchMethodException {
    final Type type = getClass().getDeclaredMethod("triFunctionType", TriFunction.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, ParamTypes.BOOLEAN)));
    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 15 with ParamType

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

the class UdafTypes method getInputSchema.

List<ParameterInfo> getInputSchema(final String inSchema) {
    validateStructAnnotation(inputType, inSchema, "paramSchema");
    final ParamType inputSchema = getSchemaFromType(inputType, inSchema);
    return ImmutableList.<ParameterInfo>builder().add(new ParameterInfo("val", inputSchema, "", false)).addAll(literalParams).build();
}
Also used : 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