Search in sources :

Example 6 with SqlArgument

use of io.confluent.ksql.schema.ksql.SqlArgument in project ksql by confluentinc.

the class GenericsUtilTest method shouldIdentifyGeneric.

@Test
public void shouldIdentifyGeneric() {
    // Given:
    final GenericType a = GenericType.of("A");
    final SqlArgument instance = SqlArgument.of(SqlTypes.STRING);
    // When:
    final Map<GenericType, SqlType> mapping = GenericsUtil.reserveGenerics(a, instance);
    // Then:
    assertThat(mapping, hasEntry(a, SqlTypes.STRING));
}
Also used : GenericType(io.confluent.ksql.function.types.GenericType) SqlArgument(io.confluent.ksql.schema.ksql.SqlArgument) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Test(org.junit.Test)

Example 7 with SqlArgument

use of io.confluent.ksql.schema.ksql.SqlArgument in project ksql by confluentinc.

the class GenericsUtilTest method shouldIdentifyArrayGeneric.

@Test
public void shouldIdentifyArrayGeneric() {
    // Given:
    final ArrayType a = ArrayType.of(GenericType.of("A"));
    final SqlArgument instance = SqlArgument.of(SqlTypes.array(SqlTypes.STRING));
    // When:
    final Map<GenericType, SqlType> mapping = GenericsUtil.reserveGenerics(a, instance);
    // Then:
    assertThat(mapping, hasEntry(a.element(), SqlTypes.STRING));
}
Also used : ArrayType(io.confluent.ksql.function.types.ArrayType) SqlArgument(io.confluent.ksql.schema.ksql.SqlArgument) GenericType(io.confluent.ksql.function.types.GenericType) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Test(org.junit.Test)

Example 8 with SqlArgument

use of io.confluent.ksql.schema.ksql.SqlArgument in project ksql by confluentinc.

the class GenericsUtilTest method shouldIdentifyInstanceOfLambda.

@Test
public void shouldIdentifyInstanceOfLambda() {
    // Given:
    final LambdaType lambda = LambdaType.of(ImmutableList.of(GenericType.of("A")), GenericType.of("B"));
    final SqlArgument instance = SqlArgument.of(SqlLambdaResolved.of(ImmutableList.of(SqlTypes.INTEGER), SqlTypes.BIGINT));
    // When:
    final boolean isInstance = GenericsUtil.reserveGenerics(lambda, instance, new HashMap<>()).getLeft();
    // Then:
    assertThat("expected instance of", isInstance);
}
Also used : LambdaType(io.confluent.ksql.function.types.LambdaType) SqlArgument(io.confluent.ksql.schema.ksql.SqlArgument) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 9 with SqlArgument

use of io.confluent.ksql.schema.ksql.SqlArgument in project ksql by confluentinc.

the class GenericsUtilTest method shouldNotIdentifyInstanceOfTypeMismatchLambda.

@Test
public void shouldNotIdentifyInstanceOfTypeMismatchLambda() {
    // Given:
    final MapType map = MapType.of(GenericType.of("A"), GenericType.of("B"));
    final SqlArgument lambdaInstance = SqlArgument.of(SqlLambdaResolved.of(ImmutableList.of(SqlTypes.INTEGER), SqlTypes.BIGINT));
    final LambdaType lambda = LambdaType.of(ImmutableList.of(GenericType.of("A")), GenericType.of("B"));
    final SqlArgument mapInstance = SqlArgument.of(SqlTypes.map(SqlTypes.STRING, SqlTypes.BOOLEAN));
    // When:
    final boolean isInstance1 = GenericsUtil.reserveGenerics(map, lambdaInstance, new HashMap<>()).getLeft();
    final boolean isInstance2 = GenericsUtil.reserveGenerics(lambda, mapInstance, new HashMap<>()).getLeft();
    // Then:
    assertThat("expected not instance of", !isInstance1);
    assertThat("expected not instance of", !isInstance2);
}
Also used : LambdaType(io.confluent.ksql.function.types.LambdaType) SqlArgument(io.confluent.ksql.schema.ksql.SqlArgument) HashMap(java.util.HashMap) MapType(io.confluent.ksql.function.types.MapType) Test(org.junit.Test)

Example 10 with SqlArgument

use of io.confluent.ksql.schema.ksql.SqlArgument in project ksql by confluentinc.

the class FunctionLoaderUtils method handleUdfSchemaProviderAnnotation.

private static Function<List<SqlArgument>, SqlType> handleUdfSchemaProviderAnnotation(final String schemaProviderName, final Class theClass, final String functionName) {
    // throws exception if it cannot find the method
    final Method m = findSchemaProvider(theClass, schemaProviderName);
    final Object instance = FunctionLoaderUtils.instantiateFunctionInstance(theClass, functionName);
    return parameterSchemas -> invokeSchemaProviderMethod(instance, m, parameterSchemas, functionName);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) UdfParameter(io.confluent.ksql.function.udf.UdfParameter) ParamType(io.confluent.ksql.function.types.ParamType) HashMap(java.util.HashMap) Function(java.util.function.Function) UdfUtil(io.confluent.ksql.execution.function.UdfUtil) Parameter(java.lang.reflect.Parameter) Map(java.util.Map) SqlTypeParser(io.confluent.ksql.schema.ksql.SqlTypeParser) SchemaConverters(io.confluent.ksql.schema.ksql.SchemaConverters) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Method(java.lang.reflect.Method) Udf(io.confluent.ksql.function.udf.Udf) SqlArgument(io.confluent.ksql.schema.ksql.SqlArgument) ParamTypes(io.confluent.ksql.function.types.ParamTypes) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) LambdaType(io.confluent.ksql.function.types.LambdaType) List(java.util.List) Type(java.lang.reflect.Type) UdfSchemaProvider(io.confluent.ksql.function.udf.UdfSchemaProvider) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) GenericType(io.confluent.ksql.function.types.GenericType) Method(java.lang.reflect.Method)

Aggregations

SqlArgument (io.confluent.ksql.schema.ksql.SqlArgument)21 Test (org.junit.Test)14 GenericType (io.confluent.ksql.function.types.GenericType)12 LambdaType (io.confluent.ksql.function.types.LambdaType)10 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)10 HashMap (java.util.HashMap)7 MapType (io.confluent.ksql.function.types.MapType)4 KsqlException (io.confluent.ksql.util.KsqlException)4 Expression (io.confluent.ksql.execution.expression.tree.Expression)3 ParamType (io.confluent.ksql.function.types.ParamType)3 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 LambdaFunctionCall (io.confluent.ksql.execution.expression.tree.LambdaFunctionCall)2 UdfUtil (io.confluent.ksql.execution.function.UdfUtil)2 ParamTypes (io.confluent.ksql.function.types.ParamTypes)2 Udf (io.confluent.ksql.function.udf.Udf)2 UdfParameter (io.confluent.ksql.function.udf.UdfParameter)2 UdfSchemaProvider (io.confluent.ksql.function.udf.UdfSchemaProvider)2 SchemaConverters (io.confluent.ksql.schema.ksql.SchemaConverters)2