use of io.confluent.ksql.function.types.LambdaType in project ksql by confluentinc.
the class GenericsUtilTest method shouldFailToIdentifyLambdasWithDifferentArgumentList.
@Test
public void shouldFailToIdentifyLambdasWithDifferentArgumentList() {
// Given:
final GenericType typeA = GenericType.of("A");
final GenericType typeB = GenericType.of("B");
final GenericType typeC = GenericType.of("C");
final LambdaType a = LambdaType.of(ImmutableList.of(typeA, typeC), typeB);
final SqlArgument instance = SqlArgument.of(SqlLambda.of(4));
// When:
final Exception e = assertThrows(KsqlException.class, () -> GenericsUtil.reserveGenerics(a, instance));
// Then:
assertThat(e.getMessage(), containsString("Cannot infer generics for LAMBDA (A, C) => B from LAMBDA " + "because they do not have the same schema structure."));
}
use of io.confluent.ksql.function.types.LambdaType in project ksql by confluentinc.
the class GenericsUtilTest method shouldFailToIdentifyMismatchedGenericsInLambda.
@Test
public void shouldFailToIdentifyMismatchedGenericsInLambda() {
// Given:
final GenericType typeA = GenericType.of("A");
final LambdaType a = LambdaType.of(ImmutableList.of(typeA), typeA);
final SqlArgument instance = SqlArgument.of(SqlLambdaResolved.of(ImmutableList.of(SqlTypes.DOUBLE), SqlTypes.BOOLEAN));
// When:
final Exception e = assertThrows(KsqlException.class, () -> GenericsUtil.reserveGenerics(a, instance));
// Then:
assertThat(e.getMessage(), containsString("Found invalid instance of generic schema when mapping LAMBDA (A) => A to LAMBDA (DOUBLE) => BOOLEAN. " + "Cannot map A to both DOUBLE and BOOLEAN"));
}
use of io.confluent.ksql.function.types.LambdaType in project ksql by confluentinc.
the class GenericsUtilTest method shouldNotMapGenericsForNonSqlLambdaResolved.
@Test
public void shouldNotMapGenericsForNonSqlLambdaResolved() {
// Given:
final GenericType typeA = GenericType.of("A");
final GenericType typeB = GenericType.of("B");
final GenericType typeC = GenericType.of("C");
final LambdaType a = LambdaType.of(ImmutableList.of(typeA, typeC), typeB);
final SqlArgument instance = SqlArgument.of(SqlLambda.of(2));
// When:
final Map<GenericType, SqlType> mapping = GenericsUtil.reserveGenerics(a, instance);
// Then:
// the map should be empty since the instance type was a SqlLambda without any types resolved
assertThat(mapping.size(), is(0));
}
use of io.confluent.ksql.function.types.LambdaType 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.function.types.LambdaType 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);
}
Aggregations