use of io.confluent.ksql.schema.ksql.SqlArgument 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.schema.ksql.SqlArgument 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.schema.ksql.SqlArgument in project ksql by confluentinc.
the class GenericsUtilTest method shouldNotIdentifyInstanceOfTypeMismatch.
@Test
public void shouldNotIdentifyInstanceOfTypeMismatch() {
// Given:
final MapType map = MapType.of(GenericType.of("A"), GenericType.of("B"));
final SqlArgument instance = SqlArgument.of(SqlTypes.array(SqlTypes.STRING));
// When:
final boolean isInstance = GenericsUtil.reserveGenerics(map, instance, new HashMap<>()).getLeft();
// Then:
assertThat("expected not instance of", !isInstance);
}
use of io.confluent.ksql.schema.ksql.SqlArgument in project ksql by confluentinc.
the class GenericsUtilTest method shouldIdentifyMapGeneric.
@Test
public void shouldIdentifyMapGeneric() {
// Given:
final MapType a = MapType.of(GenericType.of("A"), GenericType.of("B"));
final SqlArgument instance = SqlArgument.of(SqlTypes.map(SqlTypes.DOUBLE, SqlTypes.BIGINT));
// When:
final Map<GenericType, SqlType> mapping = GenericsUtil.reserveGenerics(a, instance);
// Then:
assertThat(mapping, hasEntry(a.key(), SqlTypes.DOUBLE));
assertThat(mapping, hasEntry(a.value(), SqlTypes.BIGINT));
}
use of io.confluent.ksql.schema.ksql.SqlArgument 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));
}
Aggregations