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));
}
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));
}
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);
}
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);
}
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);
}
Aggregations